File: bounds_of_cast.cpp

package info (click to toggle)
halide 21.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,752 kB
  • sloc: cpp: 289,334; ansic: 22,751; python: 7,486; makefile: 4,299; sh: 2,508; java: 1,549; javascript: 282; pascal: 207; xml: 127; asm: 9
file content (37 lines) | stat: -rw-r--r-- 970 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "Halide.h"
#include <stdio.h>

using namespace Halide;

void check(Func f, ImageParam in, int min, int extent) {
    Buffer<int> output(12345);
    output.set_min(-1234);

    in.reset();
    f.infer_input_bounds(output);
    Buffer<int> im = in.get();

    if (im.extent(0) != extent || im.min(0) != min) {
        printf("Inferred size was [%d, %d] instead of [%d, %d]\n",
               im.min(0), im.extent(0), min, extent);
        exit(1);
    }
}

int main(int argc, char **argv) {
    ImageParam input(Int(32), 1);
    Var x;
    Func f1 = lambda(x, input(cast<uint8_t>(x)));
    Func f2 = lambda(x, input(cast<int8_t>(x)));
    Func f3 = lambda(x, input(cast<uint16_t>(x)));
    Func f4 = lambda(x, input(cast<int16_t>(x)));

    // input should only be required from 0 to 256
    check(f1, input, 0, 256);
    check(f2, input, -128, 256);
    check(f3, input, 0, 65536);
    check(f4, input, -32768, 65536);

    printf("Success!\n");
    return 0;
}