#include "Halide.h"
#include <stdio.h>
int main(int argc, char **argv) {
Type valid_halide_types[] = {
{
assert(
UInt(8).bits() == 8);
assert(type_of<float>() ==
Float(32));
assert(cast<uint8_t>(x).type() ==
UInt(8));
f1(x) = cast<uint8_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);
for (
Type t : valid_halide_types) {
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);
}
{
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);
}
signed __INT32_TYPE__ int32_t
A Halide variable, to be used when defining functions.
unsigned __INT16_TYPE__ uint16_t
Type Float(int bits, int lanes=1)
Construct a floating-point type.
HALIDE_ALWAYS_INLINE bool is_float() const
Is this type a floating point type (float or double).
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.
HALIDE_ALWAYS_INLINE auto is_int(A &&a, int bits=0, int lanes=0) noexcept -> IsInt< decltype(pattern_arg(a))>
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.
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Type Handle(int lanes=1, const halide_handle_cplusplus_type *handle_type=nullptr)
Construct a handle type.
HALIDE_ALWAYS_INLINE bool is_handle() const
Is this type an opaque handle type (void *)
HALIDE_ALWAYS_INLINE Type type() const
Get the type of this expression node.
HALIDE_ALWAYS_INLINE int bits() const
Return the bit size of a single element of this type.
Type UInt(int bits, int lanes=1)
Constructing an unsigned integer type.
const std::vector< Type > & types() const
A fragment of Halide syntax.
Type Int(int bits, int lanes=1)
Constructing a signed integer type.