This source file includes following definitions.
- main
#include "Halide.h"
#include <stdio.h>
using namespace Halide;
int main(int argc, char *argv[]) {
Buffer<uint8_t> input(1024, 1024, 3);
for (int c = 0; c < input.channels(); c++) {
for (int y = 0; y < input.height(); y++) {
for (int x = 0; x < input.width(); x++) {
input(x, y, c) = x + y + c;
}
}
}
Var x("x"), y("y"), c("c");
Func clamped_input = Halide::BoundaryConditions::repeat_edge(input);
Func f("f"), g("g"), h("h");
g(x, y, c) = x + y + c;
g(x, y, 0) = x;
h(x, y) = clamped_input(x + g(x, y, 0), y, 2);
f(x, y, c) = select(h(x, y) < x + y, x + y, y + c);
f.compute_root();
Func output("output");
output(x, y, c) = cast<float>(f(x, y, c));
Buffer<float> im = output.realize(1024, 1024, 3);
for (int y = 0; y < input.height(); y++) {
for (int x = 0; x < input.width(); x++) {
for (int c = 0; c < input.channels(); c++) {
float correct = (input(2*x, y, 2) < x + y) ? x + y : y + c;
if (im(x, y, c) != correct) {
printf("im(%d, %d, %d) = %f instead of %f\n",
x, y, c, im(x, y, c), correct);
return -1;
}
}
}
}
printf("Success!\n");
return 0;
}