24 #ifndef ARM_COMPUTE_TEST_UTILS_H 25 #define ARM_COMPUTE_TEST_UTILS_H 48 #include <type_traits> 67 template <typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>
::type>
70 return std::floor(value + 0.5f);
80 template <typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>
::type>
83 T positive_value = std::abs(value);
85 std::modf(positive_value, &ipart);
87 if(std::abs(positive_value - (ipart + 0.5f)) <
epsilon)
90 if(std::fmod(ipart, 2.f) <
epsilon)
125 template <
typename T>
128 template <
typename T>
131 template <
typename T>
153 throw std::runtime_error(
"Unsupported channel");
172 throw std::runtime_error(
"Unsupported channel");
180 template <
typename F,
typename T>
181 inline T
foldl(F &&,
const T &value)
190 template <
typename F,
typename T,
typename U>
191 inline auto foldl(F &&func, T &&value1, U &&value2) -> decltype(func(value1, value2))
193 return func(value1, value2);
203 template <
typename F,
typename I,
typename T,
typename... Vs>
204 inline I
foldl(F &&func, I &&initial, T &&value, Vs &&... values)
206 return foldl(std::forward<F>(func), func(std::forward<I>(initial), std::forward<T>(value)), std::forward<Vs>(values)...);
229 anchor.
set(0, border_size.left);
230 anchor.
set(1, border_size.top);
232 const int valid_shape_x = std::max(0, static_cast<int>(shape.
x()) - static_cast<int>(border_size.left) -
static_cast<int>(border_size.right));
233 const int valid_shape_y = std::max(0, static_cast<int>(shape.
y()) - static_cast<int>(border_size.top) -
static_cast<int>(border_size.bottom));
235 shape.
set(0, valid_shape_x);
236 shape.
set(1, valid_shape_y);
250 template <
typename T>
257 *
reinterpret_cast<uint8_t *
>(ptr) = value;
263 *
reinterpret_cast<int8_t *
>(ptr) = value;
267 *
reinterpret_cast<uint16_t *
>(ptr) = value;
271 *
reinterpret_cast<int16_t *
>(ptr) = value;
274 *
reinterpret_cast<uint32_t *
>(ptr) = value;
277 *
reinterpret_cast<int32_t *
>(ptr) = value;
280 *
reinterpret_cast<uint64_t *
>(ptr) = value;
283 *
reinterpret_cast<int64_t *
>(ptr) = value;
289 *
reinterpret_cast<half *
>(ptr) = value;
292 *
reinterpret_cast<float *
>(ptr) = value;
295 *
reinterpret_cast<double *
>(ptr) = value;
298 *
reinterpret_cast<size_t *
>(ptr) = value;
311 template <
typename U,
typename T>
314 if(val > static_cast<T>(std::numeric_limits<U>::max()))
316 val =
static_cast<T
>(std::numeric_limits<U>::max());
327 template <
typename... T>
340 template <
typename... T>
369 num_elements /= shape[d];
370 coord.
set(d, index / num_elements);
371 index %= num_elements;
397 index += coord[i] * dim_size;
398 dim_size *= shape[i];
409 if(coord[d] < valid_region.
start(d) || coord[d] >= valid_region.
end(d))
425 template <
typename T>
429 tensor.allocator()->init(info);
444 template <
typename T>
453 return create_tensor<T>(
info, ctx);
464 template <
typename T>
469 return create_tensor<T>(
info, ctx);
481 template <typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>
::type>
482 inline std::vector<T>
generate_random_real(
unsigned int num_values, T min, T max, std::random_device::result_type seed)
484 std::vector<T> v(num_values);
485 std::mt19937 gen(seed);
486 std::uniform_real_distribution<T> dist(min, max);
488 for(
unsigned int i = 0; i < num_values; ++i)
496 template <
typename T,
typename ArrayAccessor_T>
497 inline void fill_array(ArrayAccessor_T &&array,
const std::vector<T> &v)
499 array.resize(v.size());
500 std::memcpy(array.buffer(), v.data(), v.size() *
sizeof(T));
512 const unsigned int i = 1;
513 const char *c =
reinterpret_cast<const char *
>(&i);
514 std::string endianness;
517 endianness = std::string(
"<");
521 endianness = std::string(
">");
523 const std::string no_endianness(
"|");
556 template <
typename TensorType>
559 #ifdef ARM_COMPUTE_CL 573 template <
typename TensorType>
588 std::fill(states.begin(), states.end(), value);
615 template <
typename TensorType>
626 template <
typename TensorType>
void set(size_t dimension, T value, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
typename std::conditional< std::is_integral< T >::value, std::make_signed< T >, std::common_type< T > >::type make_signed_conditional_t
ITensorInfo::TensorDimsState construct_dims_state(int32_t value)
Construct and return object for dimensions' state filled with the given value.
quantized, symmetric fixed-point 16-bit number
TensorShape shape
Shape of the valid region.
T foldl(F &&, const T &value)
Base case of foldl.
Container for 2D border size.
static CLScheduler & get()
Access the scheduler singleton.
Brain floating point representation class.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Format get_format_for_channel(Channel channel)
Look up the format corresponding to a channel.
T copysign(T x, T y)
Composes a floating point value with the magnitude of x and the sign of y.
1 channel, 1 U8 per channel
typename promote< T >::type promote_t
Get promoted type.
std::string to_string(T &&value)
Convert integer and float values to string.
half_float::half half
16-bit floating point type
1 channel, 1 F32 per channel
void sync_if_necessary()
Sync if necessary.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
const DataLayout data_layout
quantized, asymmetric fixed-point 16-bit number
1 channel, 1 U16 per channel
const ValidRegion valid_region
decltype(strategy::transforms) typedef type
Copyright (c) 2017-2021 Arm Limited.
int coord2index(const TensorShape &shape, const Coordinates &coord)
Linearise the given coordinate.
1 channel, 1 F16 per channel
ITensorInfo & set_quantization_info(const QuantizationInfo &quantization_info) override
Set the quantization settings (scale and offset) of the tensor.
arm_compute::bfloat16 bfloat16
1 channel, 1 S32 per channel
T round_half_even(T value, T epsilon=std::numeric_limits< T >::epsilon())
Round floating-point value with half value rounding to nearest even.
16-bit brain floating-point number
T x() const
Alias to access the size of the first dimension.
3 channels, 1 U8 per channel
Interface to enqueue OpenCL kernels and get/set the OpenCL CommandQueue and ICLTuner.
Quantization information.
Format get_channel_format(Channel channel)
Return the format of a channel.
ITensorInfo & set_data_layout(const DataLayout &data_layout) override
Set the data layout of the tensor.
void store_value_with_data_type(void *ptr, T value, DataType data_type)
Write the value after casting the pointer according to data_type.
bool is_in_valid_region(const ValidRegion &valid_region, Coordinates coord)
Check if a coordinate is within a valid region.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
void sync_tensor_if_necessary(TensorType &tensor)
Sync tensor if necessary.
library fill(src, distribution, 0)
void set_tensor_dynamic(TensorType &t)
Set the dimension states of the given tensor to dynamic.
1 channel, 1 U32 per channel
Channel
Available channels.
Format
Image colour formats.
quantized, asymmetric fixed-point 8-bit number unsigned
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
int start(unsigned int d) const
Return the start of the valid region for the given dimension d.
size_t total_size() const
Collapses all dimensions to a single linear total size.
void fill_array(ArrayAccessor_T &&array, const std::vector< T > &v)
T create_tensor(const TensorInfo &info, IRuntimeContext *ctx=nullptr)
Create and initialize a tensor of the given type.
Coordinates index2coord(const TensorShape &shape, int index)
Convert a linear index into n-dimensional coordinates.
static constexpr int32_t get_static_state_value()
Get the value representing static dimension state.
1 channel, 1 S16 per channel
std::string get_typestring(DataType data_type)
Obtain numpy type string from DataType.
quantized, symmetric fixed-point 8-bit number
Num samples, channels, height, width.
void sync()
Blocks until all commands in the associated command queue have finished.
quantized, symmetric per channel fixed-point 8-bit number
Basic pool of threads to execute CPP/Neon code on several cores in parallel.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
int end(unsigned int d) const
Return the end of the valid region for the given dimension d.
ITensorInfo::TensorDimsState construct_dynamic_dims_state()
Construct and return object for dimensions' state filled with the value for dynamic state...
T round(T value)
Round floating-point value with half value rounding away from zero.
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
T saturate_cast(T val)
Saturate a value of type T against the numeric limits of type U.
Wrapper to configure the Khronos OpenCL C++ header.
Store the tensor's metadata.
void set_tensor_static(TensorType &t)
Set the dimension states of the given tensor to state.
T y() const
Alias to access the size of the second dimension.
quantized, asymmetric fixed-point 8-bit number signed
64-bit floating-point number
T round_half_up(T value)
Round floating-point value with half value rounding to positive infinity.
Container for valid region of a window.
typename std::conditional< std::is_integral< T >::value, std::make_unsigned< T >, std::common_type< T > >::type make_unsigned_conditional_t
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
DataType
Available data types.
static constexpr int32_t get_dynamic_state_value()
Get the value representing dynamic dimension state.
DataLayout
[DataLayout enum definition]
std::vector< T > generate_random_real(unsigned int num_values, T min, T max, std::random_device::result_type seed)
Create a vector with a uniform distribution of floating point values across the specified range...
TensorShape & set(size_t dimension, size_t value, bool apply_dim_correction=true, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
Coordinates anchor
Anchor for the start of the valid region.
ValidRegion shape_to_valid_region(const TensorShape &a_shape, bool border_undefined=false, BorderSize border_size=BorderSize(0))
Create a valid region based on tensor shape, border mode and border size.
ITensorInfo::TensorDimsState construct_static_dims_state()
Construct and return object for dimensions' state filled with the value for non-dynamic state...
bool opencl_is_available()
Check if OpenCL is available.
Basic implementation of the OpenCL tensor interface.