This source file includes following definitions.
- main
#include <stdio.h>
#include "Halide.h"
using namespace Halide;
int main(int argc, char **argv) {
Var x("x");
Func f("f");
ImageParam in(Int(32), 1, "in");
Expr factor("factor");
factor = select(x < in.left(), -10,
select(x > in.right(), 10, 1));
f(x) = factor * x;
Buffer<int> input(5);
Buffer<int> out(10);
input.fill(0);
out.fill(0);
const int INOFF = 4;
const int OUTOFF = 1;
input.set_min(INOFF);
out.set_min(OUTOFF);
in.set(input);
f.realize(out);
int expected[] = { -10, -20, -30, 4, 5, 6, 7, 8, 90, 100 };
for (int i = 0; i < out.width(); i++) {
if (out(i + OUTOFF) != expected[i]) {
printf("Unexpected output: %d != %d\n", out(i + OUTOFF), expected[i]);
return -1;
}
}
printf("Success!\n");
return 0;
}