#include "Halide.h"
#include <stdio.h>
Expr average(Expr a, Expr b);
int main(int argc, char **argv) {
Type valid_halide_types[] = {
{
assert(
UInt(8).bits() == 8);
t = t.with_bits(t.bits() * 2);
assert(type_of<float>() ==
Float(32));
Var x;
assert(Expr(x).type() ==
Int(32));
assert(cast<uint8_t>(x).type() ==
UInt(8));
Func f1;
f1(x) = cast<uint8_t>(x);
assert(f1.output_types()[0] ==
UInt(8));
Func f2;
assert(f2.output_types()[0] ==
Int(32) &&
f2.output_types()[1] ==
Float(32));
}
{
Var x;
Expr
u8 = cast<uint8_t>(x);
Expr
u16 = cast<uint16_t>(x);
Expr
u32 = cast<uint32_t>(x);
Expr
u64 = cast<uint64_t>(x);
Expr s8 = cast<int8_t>(x);
Expr s16 = cast<int16_t>(x);
Expr s32 = cast<int32_t>(x);
Expr s64 = cast<int64_t>(x);
Expr
f32 = cast<float>(x);
Expr
f64 = cast<double>(x);
for (Type t : valid_halide_types) {
if (t.is_handle()) continue;
assert((e + e).type() == e.type());
}
assert((
f32 + s64).type() ==
Float(32));
assert((
f64 + s32).type() ==
Float(64));
assert((
u32 + 3).type() ==
UInt(32));
assert((3 + s16).type() ==
Int(16));
assert((s16 + s64).type() ==
Int(64));
assert((
u8 + s32).type() ==
Int(32));
assert((
u32 + s8).type() ==
Int(32));
assert((
u32 + s32).type() ==
Int(32));
int32_t result32 = evaluate<int>(cast<int32_t>(cast<uint8_t>(255)));
assert(result32 == 255);
uint16_t result16 = evaluate<uint16_t>(cast<uint16_t>(cast<int8_t>(-1)));
assert(result16 == 65535);
}
{
assert(type_of<void *>() ==
Handle());
assert(type_of<const char *const **>() ==
Handle());
assert(
Handle().bits() == 64);
}
{
Var x;
assert(average(cast<float>(x), 3.0f).type() ==
Float(32));
assert(average(x, 3).type() ==
Int(32));
assert(average(cast<uint8_t>(x), cast<uint8_t>(3)).type() ==
UInt(8));
}
printf("Success!\n");
return 0;
}
Expr average(Expr a, Expr b) {
assert(a.type() == b.type());
if (a.type().is_float()) {
return (a + b) / 2;
}
Type wider = narrow.with_bits(narrow.bits() * 2);
return cast(narrow, (a + b) / 2);
}
HALIDE_ALWAYS_INLINE auto is_int(A &&a, int bits=0) noexcept -> IsInt< decltype(pattern_arg(a))>
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Type UInt(int bits, int lanes=1)
Constructing an unsigned integer type.
Type Float(int bits, int lanes=1)
Construct a floating-point type.
Expr cast(Expr a)
Cast an expression to the halide type corresponding to the C++ type T.
Expr sin(Expr x)
Return the sine of a floating-point expression.
Type Int(int bits, int lanes=1)
Constructing a signed integer type.
Type Handle(int lanes=1, const halide_handle_cplusplus_type *handle_type=nullptr)
Construct a handle type.
signed __INT32_TYPE__ int32_t
unsigned __INT16_TYPE__ uint16_t