#include "Halide.h"
#include <algorithm>
#include <stdio.h>
int main(int argc, char **argv) {
single_valued(x, y) = x + y;
color_image(x, y, c) = select(c == 0, 245,
c == 1, 42,
132);
brighter(x, y, c) = color_image(x, y, c) + 10;
func_array[0](x, y) = x + y;
func_array[1](x, y) = sin(x);
func_array[2](x, y) = cos(y);
multi_valued(x, y) =
Tuple(x + y, sin(x * y));
{
assert(im0(30, 40) == 30 + 40);
assert(im1(30, 40) == sinf(30 * 40));
}
{
int multi_valued_0[80 * 60];
float multi_valued_1[80 * 60];
for (int y = 0; y < 80; y++) {
for (int x = 0; x < 60; x++) {
multi_valued_0[x + 60 * y] = x + y;
multi_valued_1[x + 60 * y] = sinf(x * y);
}
}
}
multi_valued_2(x, y) = {x + y, sin(x * y)};
Expr integer_part = multi_valued_2(x, y)[0];
Expr floating_part = multi_valued_2(x, y)[1];
consumer(x, y) = {integer_part + 10, floating_part + 10.0f};
{
input_func(x) = sin(x);
arg_max() = {0, input(0)};
Expr old_index = arg_max()[0];
Expr old_max = arg_max()[1];
Expr new_index = select(old_max < input(r), r, old_index);
Expr new_max = max(input(r), old_max);
arg_max() = {new_index, new_max};
int arg_max_0 = 0;
float arg_max_1 = input(0);
for (int r = 1; r < 100; r++) {
int old_index = arg_max_0;
float old_max = arg_max_1;
int new_index = old_max < input(r) ? r : old_index;
float new_max = std::max(input(r), old_max);
arg_max_0 = new_index;
arg_max_1 = new_max;
}
{
assert(arg_max_0 == r0(0));
assert(arg_max_1 == r1(0));
}
}
{
struct Complex {
: real(t[0]), imag(t[1]) {
}
: real(r), imag(i) {
}
}
return {real, imag};
}
Complex operator+(const Complex &other) const {
return {real + other.real, imag + other.imag};
}
Complex operator*(const Complex &other) const {
return {real * other.real - imag * other.imag,
real * other.imag + imag * other.real};
}
Expr magnitude_squared()
const {
return real * real + imag * imag;
}
};
Complex initial(x / 15.0f - 2.5f, y / 6.0f - 2.0f);
mandelbrot(x, y, t) = Complex(0.0f, 0.0f);
Complex current = mandelbrot(x, y, r - 1);
mandelbrot(x, y, r) = current * current + initial;
Expr escape_condition = Complex(mandelbrot(x, y, r)).magnitude_squared() < 16.0f;
Tuple first_escape = argmin(escape_condition);
escape(x, y) = first_escape[0];
const char *code = " .:-~*={}&%#@";
for (int y = 0; y < result.height(); y++) {
for (int x = 0; x < result.width(); x++) {
printf("%c", code[result(x, y)]);
}
printf("\n");
}
}
printf("Success!\n");
return 0;
}
A Halide::Buffer is a named shared reference to a Halide::Runtime::Buffer.
Realization realize(std::vector< int32_t > sizes={}, const Target &target=Target())
Evaluate this function over some rectangular domain and return the resulting buffer or buffers.
A fragment of front-end syntax of the form f(x, y, z), where x, y, z are Vars or Exprs.
A multi-dimensional domain over which to iterate.
A Realization is a vector of references to existing Buffer objects.
size_t size() const
The number of images in the Realization.
Create a small array of Exprs for defining and calling functions with multiple outputs.
A Halide variable, to be used when defining functions.
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
A fragment of Halide syntax.