File: tuple_update_ops.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 (125 lines) | stat: -rw-r--r-- 3,855 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "Halide.h"
#include <stdio.h>

using namespace Halide;
using namespace Halide::Internal;

int main(int argc, char **argv) {
    {
        Var x("x"), y("y");
        Func f("f");

        f(x, y) += Tuple(x + y);

        Realization result = f.realize({1024, 1024});
        Buffer<int> a = result[0];
        for (int y = 0; y < a.height(); y++) {
            for (int x = 0; x < a.width(); x++) {
                int correct_a = x + y;
                if (a(x, y) != correct_a) {
                    printf("result(%d, %d) = (%d) instead of (%d)\n",
                           x, y, a(x, y), correct_a);
                    return 1;
                }
            }
        }
    }

    {
        Var x("x"), y("y");
        Func f("f");

        f(x, y) += Tuple(4, 8);
        f(x, y) *= Tuple(x + y, x + 13);
        f(x, y) /= Tuple(2, 2);
        f(x, y) -= Tuple(x, y);

        Realization result = f.realize({1024, 1024});
        Buffer<int> a = result[0], b = result[1];
        for (int y = 0; y < a.height(); y++) {
            for (int x = 0; x < a.width(); x++) {
                int correct_a = x + 2 * y;
                int correct_b = 4 * (x + 13) - y;
                if (a(x, y) != correct_a || b(x, y) != correct_b) {
                    printf("result(%d, %d) = (%d, %d) instead of (%d, %d)\n",
                           x, y, a(x, y), b(x, y), correct_a, correct_b);
                    return 1;
                }
            }
        }
    }

    {
        Var x("x"), i("i"), j("j");
        Func f("f"), g("g");

        g(i, j) = i + j;

        f(x, _) = Tuple(cast<int16_t>(x), cast<int32_t>(g(_)));
        f(x, _) += Tuple(cast<int16_t>(2 * x), cast<int32_t>(x));

        Realization result = f.realize({100, 100, 100});
        Buffer<int16_t> a = result[0];
        Buffer<int32_t> b = result[1];
        for (int j = 0; j < a.channels(); j++) {
            for (int i = 0; i < a.height(); i++) {
                for (int x = 0; x < a.width(); x++) {
                    int correct_a = 3 * x;
                    int correct_b = x + i + j;
                    if (a(x, i, j) != correct_a || b(x, i, j) != correct_b) {
                        printf("result(%d, %d, %d) = (%d, %d) instead of (%d, %d)\n",
                               x, i, j, a(x, i, j), b(x, i, j), correct_a, correct_b);
                        return 1;
                    }
                }
            }
        }
    }

    {
        Var x("x"), y("y");
        Func f("f");

        f(x, y) = Tuple(x + 13, x + y);
        f(x, y) *= f(x, y);

        Realization result = f.realize({1024, 1024});
        Buffer<int> a = result[0], b = result[1];
        for (int y = 0; y < a.height(); y++) {
            for (int x = 0; x < a.width(); x++) {
                int correct_a = (x + 13) * (x + 13);
                int correct_b = (x + y) * (x + y);
                if (a(x, y) != correct_a || b(x, y) != correct_b) {
                    printf("result(%d, %d) = (%d, %d) instead of (%d, %d)\n",
                           x, y, a(x, y), b(x, y), correct_a, correct_b);
                    return 1;
                }
            }
        }
    }

    {
        Var x("x"), y("y");
        Func f("f");

        f(x, y) = Tuple(x + y);
        f(x, y) += Tuple(x);
        f(x, y) *= f(x, y);

        Realization result = f.realize({1024, 1024});
        Buffer<int> a = result[0];
        for (int y = 0; y < a.height(); y++) {
            for (int x = 0; x < a.width(); x++) {
                int correct_a = (2 * x + y) * (2 * x + y);
                if (a(x, y) != correct_a) {
                    printf("result(%d, %d) = (%d) instead of (%d)\n",
                           x, y, a(x, y), correct_a);
                    return 1;
                }
            }
        }
    }

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