#include "Halide.h"
#include <stdio.h>
int main(int argc, char **argv) {
{
Func gradient(
"gradient");
gradient(x, y) = x + y;
printf("Evaluating gradient\n");
Func parallel_gradient(
"parallel_gradient");
parallel_gradient(x, y) = x + y;
printf("\nEvaluating parallel_gradient\n");
}
{
printf("\nEvaluating sin(x) + cos(y), and just printing cos(y)\n");
}
{
f(x, y) =
sin(x) +
print(
cos(y),
"<- this is cos(", y,
") when x =", x);
printf("\nEvaluating sin(x) + cos(y), and printing cos(y) with more context\n");
}
{
e =
print_when(x == 37 && y == 42, e,
"<- this is cos(y) at x, y == (37, 42)");
printf("\nEvaluating sin(x) + cos(y), and printing cos(y) at a single pixel\n");
e =
print_when(e < 0, e,
"cos(y) < 0 at y ==", y);
printf("\nEvaluating sin(x) + cos(y), and printing whenever cos(y) < 0\n");
}
{
Var fizz(
"fizz"), buzz(
"buzz");
for (int i = 2; i < 100; i++) {
if (i % 3 == 0 && i % 5 == 0) e += fizz*buzz;
else if (i % 3 == 0) e += fizz;
else if (i % 5 == 0) e += buzz;
else e += i;
}
std::cout << "Printing a complex Expr: " << e << "\n";
}
printf("Success!\n");
return 0;
}