This source file includes following definitions.
- test
- main
#include <stdio.h>
#include "Halide.h"
using namespace Halide;
template<typename T>
bool test() {
Var x;
Func f;
f(x) = cast<T>(x) % 2;
Buffer<T> im = f.realize(16);
for (int i = 0; i < 16; i++) {
if (im(i) != (T)(i%2)) {
printf("Mod error for %d %% 2 == %f\n", i, (double)(im(i)));
return false;
}
}
Func nf;
nf(x) = cast<T>(-x) % 4;
Buffer<T> nim = nf.realize(16);
for (int i = 1; i < 16; i++) {
if (nim(i) != (T)((4 - (i % 4)) % 4)) {
printf("Mod error for %d %% 4 == %f\n", -i, (double)(nim(i)));
return false;
}
}
return true;
}
int main(int argc, char **argv) {
if (test<float>() &&
test<double>() &&
test<int32_t>() &&
test<uint32_t>() &&
test<int16_t>() &&
test<uint16_t>() &&
test<int8_t>() &&
test<uint8_t>()) {
printf("Success!\n");
return 0;
}
printf("Failure!\n");
return -1;
}