File: embed_image_aottest.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-- 1,071 bytes parent folder | download | duplicates (4)
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 <math.h>
#include <stdio.h>

#include "HalideBuffer.h"
#include "embed_image.h"

using namespace Halide::Runtime;

int main(int argc, char **argv) {
    Buffer<float, 3> input(10, 10, 3);
    for (int y = 0; y < 10; y++) {
        for (int x = 0; x < 10; x++) {
            input(x, y, 0) = sinf((float)(x * y + 1));
            input(x, y, 1) = cosf((float)(x * y + 1));
            input(x, y, 2) = sqrtf((float)(x * x + y * y));
        }
    }
    Buffer<float, 3> output(10, 10, 3);

    embed_image(input, output);

    // We expected the color channels to be flipped and multiplied by 0.5
    for (int y = 0; y < 10; y++) {
        for (int x = 0; x < 10; x++) {
            for (int c = 0; c < 3; c++) {
                float correct = input(x, y, 2 - c) * 0.5f;
                if (fabs(output(x, y, c) - correct) > 0.0001f) {
                    printf("output(%d, %d, %d) was %f instead of %f\n", x, y, c, output(x, y, c),
                           correct);
                }
            }
        }
    }

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