#include "Halide.h"
#include <stdio.h>
int main(int argc, char **argv) {
Type valid_halide_types[] = {
UInt(8), UInt(16), UInt(32), UInt(64),
Int(8), Int(16), Int(32), Int(64),
Float(32), Float(64), Handle()};
{
assert(UInt(8).bits() == 8);
assert(Int(8).is_int());
assert(t == UInt(16));
assert(type_of<float>() == Float(32));
assert(
Expr(x).type() == Int(32));
assert(sin(x).type() == Float(32));
assert(cast(UInt(8), x).type() == UInt(8));
assert(cast<uint8_t>(x).type() == UInt(8));
f1(x) = cast<uint8_t>(x);
assert(f1.
types()[0] == UInt(8));
f2(x) = {x, sin(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);
for (
Type t : valid_halide_types) {
assert((e + e).type() == e.
type());
}
assert((u8 + f32).type() ==
Float(32));
assert((f32 + s64).type() ==
Float(32));
assert((u16 + f64).type() ==
Float(64));
assert((f64 + s32).type() ==
Float(64));
assert((f64 + f32).type() ==
Float(64));
assert((u32 + 3).type() ==
UInt(32));
assert((3 + s16).type() ==
Int(16));
assert((u32 + u8).type() ==
UInt(32));
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);
}
{
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;
}
return (a + b) / 2;
}
return cast(narrow, (a + b) / 2);
}
const std::vector< Type > & types() const
A Halide variable, to be used when defining functions.
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.
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.
Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a)
Cast operators for ConstantIntervals.
signed __INT32_TYPE__ int32_t
unsigned __INT16_TYPE__ uint16_t
A fragment of Halide syntax.
HALIDE_ALWAYS_INLINE Type type() const
Get the type of this expression node.
Types in the halide type system.
Type with_bits(int new_bits) const
Return Type with same type code and lanes, but new_bits for the number of bits.
HALIDE_ALWAYS_INLINE int bits() const
Return the bit size of a single element of this type.
HALIDE_ALWAYS_INLINE bool is_handle() const
Is this type an opaque handle type (void *)
HALIDE_ALWAYS_INLINE bool is_float() const
Is this type a floating point type (float or double).