root/test/generator/embed_image_aottest.cpp

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

#include <math.h>
#include <stdio.h>

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

using namespace Halide::Runtime;

int main(int argc, char **argv) {
    Buffer<float> 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> 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;
}

/* [<][>][^][v][top][bottom][index][help] */