24 #ifndef ARM_COMPUTE_TEST_UTILS_H 25 #define ARM_COMPUTE_TEST_UTILS_H 55 #include <type_traits> 74 template <typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>
::type>
77 return std::floor(value + 0.5f);
87 template <typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>
::type>
90 T positive_value = std::abs(value);
92 std::modf(positive_value, &ipart);
94 if(std::abs(positive_value - (ipart + 0.5f)) <
epsilon)
97 if(std::fmod(ipart, 2.f) <
epsilon)
132 template <
typename T>
135 template <
typename T>
138 template <
typename T>
160 throw std::runtime_error(
"Unsupported channel");
179 throw std::runtime_error(
"Unsupported channel");
187 template <
typename F,
typename T>
188 inline T
foldl(F &&,
const T &value)
197 template <
typename F,
typename T,
typename U>
198 inline auto foldl(F &&
func, T &&value1, U &&value2) -> decltype(
func(value1, value2))
200 return func(value1, value2);
210 template <
typename F,
typename I,
typename T,
typename... Vs>
211 inline I
foldl(F &&
func, I &&initial, T &&value, Vs &&... values)
213 return foldl(std::forward<F>(
func),
func(std::forward<I>(initial), std::forward<T>(value)), std::forward<Vs>(values)...);
236 anchor.
set(0, border_size.left);
237 anchor.
set(1, border_size.top);
239 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));
240 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));
242 shape.
set(0, valid_shape_x);
243 shape.
set(1, valid_shape_y);
261 constexpr
int border_size = 2;
271 shape.
set(0, (a_shape[0] + 1) * 0.5f);
272 shape.
set(1, (a_shape[1] + 1) * 0.5f);
279 float invalid_border_left =
static_cast<float>(a_valid_region.
anchor.
x() + border_size) / 2.0f;
280 float invalid_border_top =
static_cast<float>(a_valid_region.
anchor.
y() + border_size) / 2.0f;
286 invalid_border_left = (a_shape[0] % 2) ? std::ceil(invalid_border_left) : std::floor(invalid_border_left);
287 invalid_border_top = (a_shape[1] % 2) ? std::ceil(invalid_border_top) : std::floor(invalid_border_top);
290 anchor.
set(0, static_cast<int>(invalid_border_left));
291 anchor.
set(1, static_cast<int>(invalid_border_top));
295 const float prev_invalid_border_right =
static_cast<float>(a_shape[0] - (a_valid_region.
anchor.
x() + a_valid_region.
shape[0]));
296 const float prev_invalid_border_bottom =
static_cast<float>(a_shape[1] - (a_valid_region.
anchor.
y() + a_valid_region.
shape[1]));
299 const float invalid_border_right = std::ceil((prev_invalid_border_right + static_cast<float>(border_size)) / 2.0f);
300 const float invalid_border_bottom = std::ceil((prev_invalid_border_bottom + static_cast<float>(border_size)) / 2.0f);
302 const int valid_shape_x = std::max(0, static_cast<int>(shape.
x()) - static_cast<int>(invalid_border_left) -
static_cast<int>(invalid_border_right));
303 const int valid_shape_y = std::max(0, static_cast<int>(shape.
y()) - static_cast<int>(invalid_border_top) -
static_cast<int>(invalid_border_bottom));
305 shape.
set(0, valid_shape_x);
306 shape.
set(1, valid_shape_y);
330 auto border_left =
static_cast<int>(gaussian5x5_border.
left);
331 auto border_right =
static_cast<int>(gaussian5x5_border.
right);
332 auto border_top =
static_cast<int>(gaussian5x5_border.
top);
333 auto border_bottom =
static_cast<int>(gaussian5x5_border.
bottom);
337 valid_region.
shape.
set(0, std::max(0, static_cast<int>(valid_region.
shape[0]) - border_right - border_left));
338 valid_region.
shape.
set(1, std::max(0, static_cast<int>(valid_region.
shape[1]) - border_top - border_bottom));
352 template <
typename T>
359 *
reinterpret_cast<uint8_t *
>(ptr) = value;
365 *
reinterpret_cast<int8_t *
>(ptr) = value;
369 *
reinterpret_cast<uint16_t *
>(ptr) = value;
373 *
reinterpret_cast<int16_t *
>(ptr) = value;
376 *
reinterpret_cast<uint32_t *
>(ptr) = value;
379 *
reinterpret_cast<int32_t *
>(ptr) = value;
382 *
reinterpret_cast<uint64_t *
>(ptr) = value;
385 *
reinterpret_cast<int64_t *
>(ptr) = value;
391 *
reinterpret_cast<half *
>(ptr) = value;
394 *
reinterpret_cast<float *
>(ptr) = value;
397 *
reinterpret_cast<double *
>(ptr) = value;
400 *
reinterpret_cast<size_t *
>(ptr) = value;
413 template <
typename U,
typename T>
416 if(val > static_cast<T>(std::numeric_limits<U>::max()))
418 val =
static_cast<T
>(std::numeric_limits<U>::max());
429 template <
typename... T>
442 template <
typename... T>
471 num_elements /= shape[d];
472 coord.
set(d, index / num_elements);
473 index %= num_elements;
499 index += coord[i] * dim_size;
500 dim_size *= shape[i];
511 if(coord[d] < valid_region.
start(d) || coord[d] >= valid_region.
end(d))
531 template <
typename T>
539 tensor.allocator()->init(info);
552 template <
typename T>
558 tensor.allocator()->init(info);
570 template <
typename T>
574 multi_image.init(shape.
x(), shape.
y(), format);
585 template <
typename T>
600 template <
typename T>
604 pyramid.init_auto_padding(pyramid_info);
616 inline void init_conv(int16_t *conv,
unsigned int width,
unsigned int height, std::random_device::result_type seed)
618 std::mt19937 gen(seed);
619 std::uniform_int_distribution<int16_t> distribution_int16(-32768, 32767);
621 for(
unsigned int i = 0; i < width * height; ++i)
623 conv[i] = distribution_int16(gen);
634 inline void init_separable_conv(int16_t *conv,
unsigned int width,
unsigned int height, std::random_device::result_type seed)
636 std::mt19937 gen(seed);
638 std::uniform_int_distribution<int16_t> distribution_int16(-128, 127);
640 int16_t *conv_row =
new int16_t[width];
641 int16_t *conv_col =
new int16_t[height];
643 conv_row[0] = conv_col[0] = 1;
644 for(
unsigned int i = 1; i < width; ++i)
646 conv_row[i] = distribution_int16(gen);
649 for(
unsigned int i = 1; i < height; ++i)
651 conv_col[i] = distribution_int16(gen);
655 for(
unsigned int i = 0; i < width; ++i)
657 for(
unsigned int j = 0; j < height; ++j)
659 conv[i * width + j] = conv_col[i] * conv_row[j];
676 template <typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>
::type>
677 inline std::vector<T>
generate_random_real(
unsigned int num_values, T min, T max, std::random_device::result_type seed)
679 std::vector<T> v(num_values);
680 std::mt19937 gen(seed);
681 std::uniform_real_distribution<T> dist(min, max);
683 for(
unsigned int i = 0; i < num_values; ++i)
702 std::vector<KeyPoint> keypoints;
703 std::mt19937 gen(seed);
706 const auto min =
static_cast<int>(std::pow(2, num_levels));
707 const auto max_width =
static_cast<int>(shape.
x());
708 const auto max_height =
static_cast<int>(shape.
y());
713 std::uniform_int_distribution<> dist_w(min, max_width);
714 std::uniform_int_distribution<> dist_h(min, max_height);
716 for(
unsigned int i = 0; i < num_keypoints; i++)
719 keypoint.
x = dist_w(gen);
720 keypoint.
y = dist_h(gen);
723 keypoints.push_back(keypoint);
729 template <
typename T,
typename ArrayAccessor_T>
730 inline void fill_array(ArrayAccessor_T &&array,
const std::vector<T> &v)
732 array.resize(v.size());
733 std::memcpy(array.buffer(), v.data(), v.size() *
sizeof(T));
745 const unsigned int i = 1;
746 const char *c =
reinterpret_cast<const char *
>(&i);
747 std::string endianness;
750 endianness = std::string(
"<");
754 endianness = std::string(
">");
756 const std::string no_endianness(
"|");
789 template <
typename TensorType>
792 #ifdef ARM_COMPUTE_CL 806 template <
typename TensorType>
809 #ifdef ARM_COMPUTE_GC void set(size_t dimension, T value, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
unsigned int top
top of the border
typename std::conditional< std::is_integral< T >::value, std::make_signed< T >, std::common_type< T > >::type make_signed_conditional_t
void init_conv(int16_t *conv, unsigned int width, unsigned int height, std::random_device::result_type seed)
Initialize a convolution matrix.
quantized, symmetric fixed-point 16-bit number
TensorShape shape
Shape of the valid region.
T foldl(F &&, const T &value)
Base case of foldl.
void map(bool blocking=true)
Map on an allocated buffer.
ValidRegion shape_to_valid_region_gaussian_pyramid_half(const TensorShape &a_shape, const ValidRegion &a_valid_region, bool border_undefined=false)
Create a valid region for Gaussian Pyramid Half based on tensor shape and valid region at level "i - ...
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.
int32_t tracking_status
Status initialized to 1 by the corner detector, set to 0 when the point is lost.
std::string to_string(T &&value)
Convert integer and float values to string.
Store the HOG's metadata.
half_float::half half
16-bit floating point type
1 channel, 1 F32 per channel
GCTensor create_tensor(const TensorShape &shape, DataType data_type, int num_channels=1)
Helper to create an empty tensor.
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
void unmap()
Unmap an allocated and mapped buffer.
Interface for GLES Compute tensor.
quantized, asymmetric fixed-point 16-bit number
1 channel, 1 U16 per channel
unsigned int bottom
bottom of the border
const ValidRegion valid_region
bool opengles31_is_available()
Check if the OpenGL ES 3.1 API is available at runtime.
decltype(strategy::transforms) typedef type
Interface for OpenGL ES tensor.
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.
ValidRegion shape_to_valid_region_laplacian_pyramid(const TensorShape &a_shape, const ValidRegion &a_valid_region, bool border_undefined=false)
Create a valid region for Laplacian Pyramid based on tensor shape and valid region at level "i - 1" a...
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.
1 channel, 1 U32 per channel
Channel
Available channels.
Format
Image colour formats.
quantized, asymmetric fixed-point 8-bit number unsigned
T create_pyramid(const PyramidInfo &pyramid_info)
Create and initialize a Pyramid of the given type.
#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.
std::vector< KeyPoint > generate_random_keypoints(const TensorShape &shape, size_t num_keypoints, std::random_device::result_type seed, size_t num_levels=1)
Create a vector of random keypoints for pyramid representation.
void fill_array(ArrayAccessor_T &&array, const std::vector< T > &v)
Coordinates index2coord(const TensorShape &shape, int index)
Convert a linear index into n-dimensional coordinates.
unsigned int left
left of the border
unsigned int right
right of the border
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
Store the Pyramid's metadata.
Basic pool of threads to execute CPP/Neon code on several cores in parallel.
Wrapper to configure the Khronos EGL and OpenGL ES C header.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
T create_HOG(const HOGInfo &hog_info)
Create and initialize a HOG (Histogram of Oriented Gradients) of the given type.
int end(unsigned int d) const
Return the end of the valid region for the given dimension d.
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.
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.
void init_separable_conv(int16_t *conv, unsigned int width, unsigned int height, std::random_device::result_type seed)
Initialize a separable convolution matrix.
DataType
Available data types.
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.
bool opencl_is_available()
Check if OpenCL is available.
T create_multi_image(const TensorShape &shape, Format format)
Create and initialize a multi-image of the given type.
Basic implementation of the OpenCL tensor interface.