Compute Library
 21.02
arm_compute::test Namespace Reference

Namespaces

 benchmark
 
 colorconvert_helper
 
 convolution_3d
 
 detail
 
 framework
 
 traits
 
 validation
 

Data Structures

class  Accessor
 Accessor implementation for Tensor objects. More...
 
class  ArrayAccessor
 ArrayAccessor implementation for Array objects. More...
 
class  AssetsLibrary
 Factory class to create and fill tensors. More...
 
class  CLAccessor
 Accessor implementation for CLTensor objects. More...
 
class  CLArrayAccessor
 Accessor implementation for CLArray objects. More...
 
class  CLHOGAccessor
 Accessor implementation for CLHOG objects. More...
 
class  CLLutAccessor
 Accessor implementation for CLLut objects. More...
 
class  CLSynthetizeFunction
 This template synthetizes an ICLSimpleFunction which runs the given kernel K. More...
 
class  CLSynthetizeFunctionInitOutputWithZeroAndWithZeroConstantBorder
 As above but this also initializes to zero the input tensor. More...
 
class  CLSynthetizeFunctionWithZeroConstantBorder
 As above but this also setups a Zero border on the input tensor of the specified bordersize. More...
 
struct  common_promoted_signed_type
 Find the signed promoted common type. More...
 
struct  common_promoted_unsigned_type
 Find the unsigned promoted common type. More...
 
class  ContextSchedulerUser
 
struct  ContextType
 
struct  ContextType< Tensor >
 
class  GCAccessor
 Accessor implementation for GCTensor objects. More...
 
class  HOGAccessor
 Accessor implementation for HOG objects. More...
 
class  IAccessor
 Common interface to provide information and access to tensor like structures. More...
 
class  IArrayAccessor
 Common interface to provide information and access to array like structures. More...
 
class  IHOGAccessor
 Common interface to access HOG structure. More...
 
class  ILutAccessor
 Common interface to provide information and access to Lut like structures. More...
 
class  LutAccessor
 Accessor implementation for Lut objects. More...
 
class  NESynthetizeFunction
 This template synthetizes an INESimpleFunction which runs the given kernel K. More...
 
class  NESynthetizeFunctionWithZeroConstantBorder
 As above but this also setups a Zero border on the input tensor of the specified bordersize. More...
 
class  NESynthetizeFunctionWithZeroConstantKernelBorder
 As above but this also setups a Zero border on the input tensor of the kernel's bordersize. More...
 
class  PaddingCalculator
 Calculate required padding. More...
 
class  ParametersLibrary
 Class that contains all the global parameters used by the tests. More...
 
class  RawLutAccessor
 Accessor implementation for std::map-lut objects. More...
 
class  RawTensor
 Subclass of SimpleTensor using uint8_t as value type. More...
 
class  SimpleTensor
 Simple tensor object that stores elements in a consecutive chunk of memory. More...
 
class  SimpleTensorAccessor
 Accessor implementation for SimpleTensor objects. More...
 
class  TensorCache
 Stores RawTensor categorised by the image they are created from including name, format and channel. More...
 

Functions

template<typename O , typename F , typename... As>
void apply (O *obj, F &&func, const std::tuple< As... > &args)
 
template<typename T , typename std::enable_if< std::is_same< typename T::value_type, std::string >::value, int >::type = 0>
std::string join (T first, T last, const std::string &separator)
 Helper function to concatenate multiple strings. More...
 
template<typename T , typename UnaryOp >
std::string join (T &&first, T &&last, const std::string &separator, UnaryOp &&op)
 Helper function to concatenate multiple values. More...
 
template<typename T , typename std::enable_if< std::is_arithmetic< typename T::value_type >::value, int >::type = 0>
std::string join (T &&first, T &&last, const std::string &separator)
 Helper function to concatenate multiple values. More...
 
std::string tolower (std::string string)
 Convert string to lower case. More...
 
template<typename T , typename std::enable_if< std::is_arithmetic< T >::value, int >::type = 0>
std::string arithmetic_to_string (T val, int decimal_places=0)
 Create a string with the arithmetic value in full precision. More...
 
void sleep_in_seconds (float seconds)
 Makes the calling thread to sleep for a specified number of seconds. More...
 
GCTensor create_tensor (const TensorShape &shape, DataType data_type, int num_channels=1)
 Helper to create an empty tensor. More...
 
GCTensor create_tensor (const std::string &name, DataType data_type)
 Helper to create an empty tensor. More...
 
void print_tensor (ITensor &tensor, const std::string &name, IOFormatInfo info=IOFormatInfo(IOFormatInfo::PrintRegion::Full))
 Helper to print tensor. More...
 
template<typename D , typename T , typename... Ts>
void fill_tensors (D &&dist, std::initializer_list< int > seeds, T &&tensor, Ts &&... other_tensors)
 
template<typename T1 , typename T2 >
SimpleTensor< T1 > copy_tensor (const SimpleTensor< T2 > &tensor)
 
template<typename T1 , typename T2 , typename std::enable_if< std::is_same< T1, T2 >::value, int >::type = 0>
SimpleTensor< T1 > copy_tensor (const SimpleTensor< half > &tensor)
 
template<typename U >
void swap (SimpleTensor< U > &tensor1, SimpleTensor< U > &tensor2)
 
template<typename T , typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
round_half_up (T value)
 Round floating-point value with half value rounding to positive infinity. More...
 
template<typename T , typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
round_half_even (T value, T epsilon=std::numeric_limits< T >::epsilon())
 Round floating-point value with half value rounding to nearest even. More...
 
Format get_format_for_channel (Channel channel)
 Look up the format corresponding to a channel. More...
 
Format get_channel_format (Channel channel)
 Return the format of a channel. More...
 
template<typename F , typename T >
foldl (F &&, const T &value)
 Base case of foldl. More...
 
template<typename F , typename T , typename U >
auto foldl (F &&func, T &&value1, U &&value2) -> decltype(func(value1, value2))
 Base case of foldl. More...
 
template<typename F , typename I , typename T , typename... Vs>
foldl (F &&func, I &&initial, T &&value, Vs &&... values)
 Fold left. More...
 
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. More...
 
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 - 1" and border mode. More...
 
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" and border mode. More...
 
template<typename T >
void store_value_with_data_type (void *ptr, T value, DataType data_type)
 Write the value after casting the pointer according to data_type. More...
 
template<typename U , typename T >
saturate_cast (T val)
 Saturate a value of type T against the numeric limits of type U. More...
 
Coordinates index2coord (const TensorShape &shape, int index)
 Convert a linear index into n-dimensional coordinates. More...
 
int coord2index (const TensorShape &shape, const Coordinates &coord)
 Linearise the given coordinate. More...
 
bool is_in_valid_region (const ValidRegion &valid_region, Coordinates coord)
 Check if a coordinate is within a valid region. More...
 
template<typename T >
create_tensor (const TensorShape &shape, DataType data_type, int num_channels=1, QuantizationInfo quantization_info=QuantizationInfo(), DataLayout data_layout=DataLayout::NCHW, IRuntimeContext *ctx=nullptr)
 Create and initialize a tensor of the given type. More...
 
template<typename T >
create_tensor (const TensorShape &shape, Format format, IRuntimeContext *ctx=nullptr)
 Create and initialize a tensor of the given type. More...
 
template<typename T >
create_multi_image (const TensorShape &shape, Format format)
 Create and initialize a multi-image of the given type. More...
 
template<typename T >
create_HOG (const HOGInfo &hog_info)
 Create and initialize a HOG (Histogram of Oriented Gradients) of the given type. More...
 
template<typename T >
create_pyramid (const PyramidInfo &pyramid_info)
 Create and initialize a Pyramid of the given type. More...
 
void init_conv (int16_t *conv, unsigned int width, unsigned int height, std::random_device::result_type seed)
 Initialize a convolution matrix. More...
 
void init_separable_conv (int16_t *conv, unsigned int width, unsigned int height, std::random_device::result_type seed)
 Initialize a separable convolution matrix. More...
 
template<typename T , typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
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. More...
 
std::vector< KeyPointgenerate_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. More...
 
template<typename T , typename ArrayAccessor_T >
void fill_array (ArrayAccessor_T &&array, const std::vector< T > &v)
 
std::string get_typestring (DataType data_type)
 Obtain numpy type string from DataType. More...
 
template<typename TensorType >
void sync_if_necessary ()
 Sync if necessary. More...
 
template<typename TensorType >
void sync_tensor_if_necessary (TensorType &tensor)
 Sync tensor if necessary. More...
 

Variables

std::unique_ptr< ParametersLibraryparameters
 
std::unique_ptr< AssetsLibrarylibrary
 
std::unique_ptr< AssetsLibraryfixed_library
 

Function Documentation

◆ apply()

void arm_compute::test::apply ( O *  obj,
F &&  func,
const std::tuple< As... > &  args 
)

Definition at line 79 of file Utils.h.

References arm_compute::test::framework::apply_impl(), and func.

80 {
81  detail::apply_impl(obj, std::forward<F>(func), args, detail::sequence_t<sizeof...(As)>());
82 }
void apply_impl(O *obj, F &&func, const std::tuple< As... > &args, detail::sequence< S... >)
Definition: Utils.h:72
FloorUKernelPtr func

◆ arithmetic_to_string()

std::string arm_compute::test::arithmetic_to_string ( val,
int  decimal_places = 0 
)
inline

Create a string with the arithmetic value in full precision.

Parameters
valArithmetic value
decimal_placesHow many decimal places to show
Returns
String with the arithmetic value.

Definition at line 164 of file Utils.h.

References arm_compute::test::framework::sleep_in_seconds(), and arm_compute::test::validation::ss().

Referenced by PrettyPrinter::print_measurements().

165 {
166  std::stringstream ss;
167  ss << std::fixed;
168  ss.precision((decimal_places) ? decimal_places : std::numeric_limits<T>::digits10 + 1);
169  ss << val;
170  return ss.str();
171 }
std::stringstream ss(mlgo_str)

◆ coord2index()

int arm_compute::test::coord2index ( const TensorShape shape,
const Coordinates coord 
)
inline

Linearise the given coordinate.

Transforms the given coordinate into a linear offset in terms of elements.

Parameters
[in]shapeShape of the n-dimensional tensor.
[in]coordThe to be converted coordinate.
Returns
Linear offset to the element.

Definition at line 489 of file Utils.h.

References ARM_COMPUTE_ERROR_ON_MSG, Dimensions< T >::num_dimensions(), and TensorShape::total_size().

Referenced by arm_compute::test::validation::apply_2d_spatial_filter(), arm_compute::test::validation::reference::col2im(), DATA_TEST_CASE(), arm_compute::test::validation::reference::fast_corners(), arm_compute::test::validation::reference::instance_normalization(), arm_compute::test::validation::reference::logical_binary_op(), RawTensor::operator()(), SimpleTensor< uint8_t >::operator()(), arm_compute::test::validation::reference::pad_layer(), arm_compute::test::validation::reference::pooling_layer_internal(), arm_compute::test::validation::reference::reverse(), arm_compute::test::validation::reference::scale_core(), arm_compute::test::validation::tensor_elem_at(), arm_compute::test::validation::reference::tile(), arm_compute::test::validation::reference::transpose(), arm_compute::test::validation::reference::warp_affine(), arm_compute::test::validation::reference::warp_perspective(), and arm_compute::test::validation::reference::weights_reshape().

490 {
491  ARM_COMPUTE_ERROR_ON_MSG(shape.total_size() == 0, "Cannot get index from empty shape");
492  ARM_COMPUTE_ERROR_ON_MSG(coord.num_dimensions() == 0, "Cannot get index of empty coordinate");
493 
494  int index = 0;
495  int dim_size = 1;
496 
497  for(unsigned int i = 0; i < coord.num_dimensions(); ++i)
498  {
499  index += coord[i] * dim_size;
500  dim_size *= shape[i];
501  }
502 
503  return index;
504 }
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456

◆ copy_tensor() [1/2]

SimpleTensor<T1> arm_compute::test::copy_tensor ( const SimpleTensor< T2 > &  tensor)

Definition at line 223 of file SimpleTensor.h.

References SimpleTensor< T >::data(), SimpleTensor< T >::data_layout(), SimpleTensor< T >::data_type(), SimpleTensor< T >::num_channels(), SimpleTensor< T >::quantization_info(), and SimpleTensor< T >::shape().

224 {
225  SimpleTensor<T1> st(tensor.shape(), tensor.data_type(),
226  tensor.num_channels(),
227  tensor.quantization_info(),
228  tensor.data_layout());
229  for(size_t n = 0; n < size_t(st.num_elements()); n++)
230  {
231  st.data()[n] = static_cast<T1>(tensor.data()[n]);
232  }
233  return st;
234 }

◆ copy_tensor() [2/2]

SimpleTensor< T1 > copy_tensor ( const SimpleTensor< half > &  tensor)

Definition at line 237 of file SimpleTensor.h.

References SimpleTensor< T >::data(), SimpleTensor< T >::data_layout(), SimpleTensor< T >::data_type(), SimpleTensor< T >::num_channels(), SimpleTensor< T >::quantization_info(), and SimpleTensor< T >::shape().

238 {
239  SimpleTensor<T1> st(tensor.shape(), tensor.data_type(),
240  tensor.num_channels(),
241  tensor.quantization_info(),
242  tensor.data_layout());
243  memcpy((void *)st.data(), (const void *)tensor.data(), size_t(st.num_elements() * sizeof(T1)));
244  return st;
245 }

◆ create_HOG()

T arm_compute::test::create_HOG ( const HOGInfo hog_info)
inline

Create and initialize a HOG (Histogram of Oriented Gradients) of the given type.

Parameters
[in]hog_infoHOGInfo object
Returns
Initialized HOG of given type.

Definition at line 586 of file Utils.h.

587 {
588  T hog;
589  hog.init(hog_info);
590 
591  return hog;
592 }

◆ create_multi_image()

T arm_compute::test::create_multi_image ( const TensorShape shape,
Format  format 
)
inline

Create and initialize a multi-image of the given type.

Parameters
[in]shapeTensor shape.
[in]formatFormat type.
Returns
Initialized tensor of given type.

Definition at line 571 of file Utils.h.

References Dimensions< T >::x(), and Dimensions< T >::y().

572 {
573  T multi_image;
574  multi_image.init(shape.x(), shape.y(), format);
575 
576  return multi_image;
577 }

◆ create_pyramid()

T arm_compute::test::create_pyramid ( const PyramidInfo pyramid_info)
inline

Create and initialize a Pyramid of the given type.

Parameters
[in]pyramid_infoThe PyramidInfo object.
Returns
Initialized Pyramid of given type.

Definition at line 601 of file Utils.h.

602 {
603  T pyramid;
604  pyramid.init_auto_padding(pyramid_info);
605 
606  return pyramid;
607 }

◆ create_tensor() [1/4]

GCTensor arm_compute::test::create_tensor ( const TensorShape shape,
DataType  data_type,
int  num_channels = 1 
)
inline

Helper to create an empty tensor.

Parameters
[in]shapeDesired shape.
[in]data_typeDesired data type.
[in]num_channels(Optional) It indicates the number of channels for each tensor element
Returns
Empty GCTensor with the specified shape and data type.

Definition at line 46 of file Helper.h.

References GCTensor::allocator(), and ITensorAllocator::init().

47 {
48  GCTensor tensor;
49  tensor.allocator()->init(TensorInfo(shape, num_channels, data_type));
50 
51  return tensor;
52 }
const DataType data_type
Definition: Im2Col.cpp:150

◆ create_tensor() [2/4]

GCTensor arm_compute::test::create_tensor ( const std::string &  name,
DataType  data_type 
)
inline

Helper to create an empty tensor.

Parameters
[in]nameFile name from which to get the dimensions.
[in]data_typeDesired data type.
Returns
Empty GCTensor with the specified shape and data type.

Definition at line 61 of file Helper.h.

References GCTensor::allocator(), arm_compute::test::validation::data_type, ITensorAllocator::init(), library, and SimpleTensor< T >::shape().

62 {
63  constexpr unsigned int num_channels = 1;
64 
65  const RawTensor &raw = library->get(name);
66 
67  GCTensor tensor;
68  tensor.allocator()->init(TensorInfo(raw.shape(), num_channels, data_type));
69 
70  return tensor;
71 }
const DataType data_type
Definition: Im2Col.cpp:150
std::unique_ptr< AssetsLibrary > library
Definition: main.cpp:78
const char * name

◆ create_tensor() [3/4]

T arm_compute::test::create_tensor ( const TensorShape shape,
DataType  data_type,
int  num_channels = 1,
QuantizationInfo  quantization_info = QuantizationInfo(),
DataLayout  data_layout = DataLayout::NCHW,
IRuntimeContext ctx = nullptr 
)
inline

Create and initialize a tensor of the given type.

Parameters
[in]shapeTensor shape.
[in]data_typeData type.
[in]num_channels(Optional) Number of channels.
[in]quantization_info(Optional) Quantization info for asymmetric quantized types.
[in]data_layout(Optional) Data layout. Default is NCHW.
[in]ctx(Optional) Pointer to the runtime context.
Returns
Initialized tensor of given type.

Definition at line 532 of file Utils.h.

References arm_compute::test::validation::data_layout, arm_compute::test::validation::info, TensorInfo::set_data_layout(), and TensorInfo::set_quantization_info().

534 {
535  T tensor(ctx);
536  TensorInfo info(shape, num_channels, data_type);
537  info.set_quantization_info(quantization_info);
538  info.set_data_layout(data_layout);
539  tensor.allocator()->init(info);
540 
541  return tensor;
542 }
const DataLayout data_layout
Definition: Im2Col.cpp:151
const DataType data_type
Definition: Im2Col.cpp:150
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)

◆ create_tensor() [4/4]

T arm_compute::test::create_tensor ( const TensorShape shape,
Format  format,
IRuntimeContext ctx = nullptr 
)
inline

Create and initialize a tensor of the given type.

Parameters
[in]shapeTensor shape.
[in]formatFormat type.
[in]ctx(Optional) Pointer to the runtime context.
Returns
Initialized tensor of given type.

Definition at line 553 of file Utils.h.

References arm_compute::test::validation::info.

554 {
555  TensorInfo info(shape, format);
556 
557  T tensor(ctx);
558  tensor.allocator()->init(info);
559 
560  return tensor;
561 }
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)

◆ fill_array()

void arm_compute::test::fill_array ( ArrayAccessor_T &&  array,
const std::vector< T > &  v 
)
inline

Definition at line 730 of file Utils.h.

731 {
732  array.resize(v.size());
733  std::memcpy(array.buffer(), v.data(), v.size() * sizeof(T));
734 }

◆ fill_tensors()

void arm_compute::test::fill_tensors ( D &&  dist,
std::initializer_list< int >  seeds,
T &&  tensor,
Ts &&...  other_tensors 
)

Definition at line 43 of file Helper.h.

References ARM_COMPUTE_ERROR_ON, and library.

44 {
45  const std::array < T, 1 + sizeof...(Ts) > tensors{ { std::forward<T>(tensor), std::forward<Ts>(other_tensors)... } };
46  std::vector<int> vs(seeds);
47  ARM_COMPUTE_ERROR_ON(vs.size() != tensors.size());
48  int k = 0;
49  for(auto tp : tensors)
50  {
51  library->fill(Accessor(*tp), std::forward<D>(dist), vs[k++]);
52  }
53 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
std::unique_ptr< AssetsLibrary > library
Definition: main.cpp:78

◆ foldl() [1/3]

T arm_compute::test::foldl ( F &&  ,
const T &  value 
)
inline

Base case of foldl.

Returns
value.

Definition at line 188 of file Utils.h.

Referenced by foldl().

189 {
190  return value;
191 }

◆ foldl() [2/3]

auto arm_compute::test::foldl ( F &&  func,
T &&  value1,
U &&  value2 
) -> decltype(func(value1, value2))
inline

Base case of foldl.

Returns
func(value1, value2).

Definition at line 198 of file Utils.h.

References func.

199 {
200  return func(value1, value2);
201 }
FloorUKernelPtr func

◆ foldl() [3/3]

I arm_compute::test::foldl ( F &&  func,
I &&  initial,
T &&  value,
Vs &&...  values 
)
inline

Fold left.

Parameters
[in]funcBinary function to be called.
[in]initialInitial value.
[in]valueArgument passed to the function.
[in]valuesRemaining arguments.

Definition at line 211 of file Utils.h.

References foldl(), and func.

212 {
213  return foldl(std::forward<F>(func), func(std::forward<I>(initial), std::forward<T>(value)), std::forward<Vs>(values)...);
214 }
I foldl(F &&func, I &&initial, T &&value, Vs &&... values)
Fold left.
Definition: Utils.h:211
FloorUKernelPtr func

◆ generate_random_keypoints()

std::vector<KeyPoint> arm_compute::test::generate_random_keypoints ( const TensorShape shape,
size_t  num_keypoints,
std::random_device::result_type  seed,
size_t  num_levels = 1 
)
inline

Create a vector of random keypoints for pyramid representation.

Parameters
[in]shapeThe shape of the input tensor.
[in]num_keypointsThe number of keypoints to be created.
[in]seedThe random seed to be used.
[in]num_levelsThe number of pyramid levels.
Returns
A vector that contains the requested number of random keypoints

Definition at line 700 of file Utils.h.

References ARM_COMPUTE_ERROR_ON, KeyPoint::tracking_status, Dimensions< T >::x(), KeyPoint::x, Dimensions< T >::y(), and KeyPoint::y.

701 {
702  std::vector<KeyPoint> keypoints;
703  std::mt19937 gen(seed);
704 
705  // Calculate distribution bounds
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());
709 
710  ARM_COMPUTE_ERROR_ON(min > max_width || min > max_height);
711 
712  // Create distributions
713  std::uniform_int_distribution<> dist_w(min, max_width);
714  std::uniform_int_distribution<> dist_h(min, max_height);
715 
716  for(unsigned int i = 0; i < num_keypoints; i++)
717  {
718  KeyPoint keypoint;
719  keypoint.x = dist_w(gen);
720  keypoint.y = dist_h(gen);
721  keypoint.tracking_status = 1;
722 
723  keypoints.push_back(keypoint);
724  }
725 
726  return keypoints;
727 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466

◆ generate_random_real()

std::vector<T> arm_compute::test::generate_random_real ( unsigned int  num_values,
min,
max,
std::random_device::result_type  seed 
)
inline

Create a vector with a uniform distribution of floating point values across the specified range.

Parameters
[in]num_valuesThe number of values to be created.
[in]minThe minimum value in distribution (inclusive).
[in]maxThe maximum value in distribution (inclusive).
[in]seedThe random seed to be used.
Returns
A vector that contains the requested number of random floating point values

Definition at line 677 of file Utils.h.

678 {
679  std::vector<T> v(num_values);
680  std::mt19937 gen(seed);
681  std::uniform_real_distribution<T> dist(min, max);
682 
683  for(unsigned int i = 0; i < num_values; ++i)
684  {
685  v.at(i) = dist(gen);
686  }
687 
688  return v;
689 }

◆ get_channel_format()

Format arm_compute::test::get_channel_format ( Channel  channel)
inline

Return the format of a channel.

Parameters
[in]channelChannel type.
Returns
Format of the given channel.

Definition at line 170 of file Utils.h.

References arm_compute::B, arm_compute::G, arm_compute::R, and arm_compute::U8.

Referenced by AssetsLibrary::fill().

171 {
172  switch(channel)
173  {
174  case Channel::R:
175  case Channel::G:
176  case Channel::B:
177  return Format::U8;
178  default:
179  throw std::runtime_error("Unsupported channel");
180  }
181 }

◆ get_format_for_channel()

Format arm_compute::test::get_format_for_channel ( Channel  channel)
inline

Look up the format corresponding to a channel.

Parameters
[in]channelChannel type.
Returns
Format that contains the given channel.

Definition at line 151 of file Utils.h.

References arm_compute::B, arm_compute::G, arm_compute::R, and arm_compute::RGB888.

Referenced by AssetsLibrary::fill(), and AssetsLibrary::get().

152 {
153  switch(channel)
154  {
155  case Channel::R:
156  case Channel::G:
157  case Channel::B:
158  return Format::RGB888;
159  default:
160  throw std::runtime_error("Unsupported channel");
161  }
162 }

◆ get_typestring()

std::string arm_compute::test::get_typestring ( DataType  data_type)
inline

Obtain numpy type string from DataType.

Parameters
[in]data_typeData type.
Returns
numpy type string.

Definition at line 742 of file Utils.h.

References ARM_COMPUTE_ERROR, arm_compute::F32, arm_compute::F64, arm_compute::S16, arm_compute::S32, arm_compute::S64, arm_compute::S8, arm_compute::SIZET, arm_compute::support::cpp11::to_string(), arm_compute::U16, arm_compute::U32, arm_compute::U64, and arm_compute::U8.

743 {
744  // Check endianness
745  const unsigned int i = 1;
746  const char *c = reinterpret_cast<const char *>(&i);
747  std::string endianness;
748  if(*c == 1)
749  {
750  endianness = std::string("<");
751  }
752  else
753  {
754  endianness = std::string(">");
755  }
756  const std::string no_endianness("|");
757 
758  switch(data_type)
759  {
760  case DataType::U8:
761  return no_endianness + "u" + support::cpp11::to_string(sizeof(uint8_t));
762  case DataType::S8:
763  return no_endianness + "i" + support::cpp11::to_string(sizeof(int8_t));
764  case DataType::U16:
765  return endianness + "u" + support::cpp11::to_string(sizeof(uint16_t));
766  case DataType::S16:
767  return endianness + "i" + support::cpp11::to_string(sizeof(int16_t));
768  case DataType::U32:
769  return endianness + "u" + support::cpp11::to_string(sizeof(uint32_t));
770  case DataType::S32:
771  return endianness + "i" + support::cpp11::to_string(sizeof(int32_t));
772  case DataType::U64:
773  return endianness + "u" + support::cpp11::to_string(sizeof(uint64_t));
774  case DataType::S64:
775  return endianness + "i" + support::cpp11::to_string(sizeof(int64_t));
776  case DataType::F32:
777  return endianness + "f" + support::cpp11::to_string(sizeof(float));
778  case DataType::F64:
779  return endianness + "f" + support::cpp11::to_string(sizeof(double));
780  case DataType::SIZET:
781  return endianness + "u" + support::cpp11::to_string(sizeof(size_t));
782  default:
783  ARM_COMPUTE_ERROR("NOT SUPPORTED!");
784  }
785 }
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
const DataType data_type
Definition: Im2Col.cpp:150
std::string to_string(const ICLTensor &arg)

◆ index2coord()

Coordinates arm_compute::test::index2coord ( const TensorShape shape,
int  index 
)
inline

Convert a linear index into n-dimensional coordinates.

Parameters
[in]shapeShape of the n-dimensional tensor.
[in]indexLinear index specifying the i-th element.
Returns
n-dimensional coordinates.

Definition at line 460 of file Utils.h.

References ARM_COMPUTE_ERROR_ON_MSG, Dimensions< T >::num_dimensions(), TensorShape::set(), and TensorShape::total_size().

Referenced by arm_compute::test::validation::reference::box3x3(), arm_compute::test::validation::reference::channel_combine(), arm_compute::test::validation::reference::convolution(), DATA_TEST_CASE(), arm_compute::test::validation::reference::dilate(), arm_compute::test::validation::reference::erode(), arm_compute::test::validation::reference::fast_corners(), AssetsLibrary::fill(), AssetsLibrary::fill_boxes(), arm_compute::test::validation::reference::gaussian3x3(), arm_compute::test::validation::reference::gaussian5x5(), arm_compute::test::validation::reference::median3x3(), arm_compute::test::validation::reference::non_linear_filter(), arm_compute::test::validation::reference::non_maxima_suppression(), arm_compute::test::validation::reference::pad_layer(), arm_compute::test::validation::reference::permute(), arm_compute::test::validation::reference::remap(), arm_compute::test::validation::reference::reverse(), arm_compute::test::validation::reference::scale_core(), arm_compute::test::validation::reference::tile(), arm_compute::test::validation::reference::transpose(), arm_compute::test::validation::transpose(), arm_compute::test::validation::validate(), arm_compute::test::validation::validate_wrap(), arm_compute::test::validation::reference::warp_affine(), arm_compute::test::validation::reference::warp_perspective(), and arm_compute::test::validation::reference::yolo_layer().

461 {
462  int num_elements = shape.total_size();
463 
464  ARM_COMPUTE_ERROR_ON_MSG(index < 0 || index >= num_elements, "Index has to be in [0, num_elements]");
465  ARM_COMPUTE_ERROR_ON_MSG(num_elements == 0, "Cannot create coordinate from empty shape");
466 
467  Coordinates coord{ 0 };
468 
469  for(int d = shape.num_dimensions() - 1; d >= 0; --d)
470  {
471  num_elements /= shape[d];
472  coord.set(d, index / num_elements);
473  index %= num_elements;
474  }
475 
476  return coord;
477 }
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456

◆ init_conv()

void arm_compute::test::init_conv ( int16_t *  conv,
unsigned int  width,
unsigned int  height,
std::random_device::result_type  seed 
)
inline

Initialize a convolution matrix.

Parameters
[in,out]convThe input convolution matrix.
[in]widthThe width of the convolution matrix.
[in]heightThe height of the convolution matrix.
[in]seedThe random seed to be used.

Definition at line 616 of file Utils.h.

617 {
618  std::mt19937 gen(seed);
619  std::uniform_int_distribution<int16_t> distribution_int16(-32768, 32767);
620 
621  for(unsigned int i = 0; i < width * height; ++i)
622  {
623  conv[i] = distribution_int16(gen);
624  }
625 }

◆ init_separable_conv()

void arm_compute::test::init_separable_conv ( int16_t *  conv,
unsigned int  width,
unsigned int  height,
std::random_device::result_type  seed 
)
inline

Initialize a separable convolution matrix.

Parameters
[in,out]convThe input convolution matrix.
[in]widthThe width of the convolution matrix.
[in]heightThe height of the convolution matrix.
[in]seedThe random seed to be used.

Definition at line 634 of file Utils.h.

635 {
636  std::mt19937 gen(seed);
637  // Set it between -128 and 127 to ensure the matrix does not overflow
638  std::uniform_int_distribution<int16_t> distribution_int16(-128, 127);
639 
640  int16_t *conv_row = new int16_t[width];
641  int16_t *conv_col = new int16_t[height];
642 
643  conv_row[0] = conv_col[0] = 1;
644  for(unsigned int i = 1; i < width; ++i)
645  {
646  conv_row[i] = distribution_int16(gen);
647  }
648 
649  for(unsigned int i = 1; i < height; ++i)
650  {
651  conv_col[i] = distribution_int16(gen);
652  }
653 
654  // Multiply two matrices
655  for(unsigned int i = 0; i < width; ++i)
656  {
657  for(unsigned int j = 0; j < height; ++j)
658  {
659  conv[i * width + j] = conv_col[i] * conv_row[j];
660  }
661  }
662 
663  delete[] conv_row;
664  delete[] conv_col;
665 }

◆ is_in_valid_region()

bool arm_compute::test::is_in_valid_region ( const ValidRegion valid_region,
Coordinates  coord 
)
inline

Check if a coordinate is within a valid region.

Definition at line 507 of file Utils.h.

References ValidRegion::end(), Dimensions< int >::num_max_dimensions, and ValidRegion::start().

Referenced by arm_compute::test::validation::reference::fast_corners(), arm_compute::test::validation::reference::non_linear_filter(), arm_compute::test::validation::reference::non_maxima_suppression(), arm_compute::test::validation::validate(), and arm_compute::test::validation::validate_wrap().

508 {
509  for(size_t d = 0; d < Coordinates::num_max_dimensions; ++d)
510  {
511  if(coord[d] < valid_region.start(d) || coord[d] >= valid_region.end(d))
512  {
513  return false;
514  }
515  }
516 
517  return true;
518 }
const ValidRegion valid_region
Definition: Scale.cpp:221
int start(unsigned int d) const
Return the start of the valid region for the given dimension d.
Definition: Types.h:234
int end(unsigned int d) const
Return the end of the valid region for the given dimension d.
Definition: Types.h:240

◆ join() [1/3]

std::string arm_compute::test::join ( first,
last,
const std::string &  separator 
)

Helper function to concatenate multiple strings.

Parameters
[in]firstIterator pointing to the first element to be concatenated.
[in]lastIterator pointing behind the last element to be concatenated.
[in]separatorString used to join the elements.
Returns
String containing all elements joined by separator.

Definition at line 93 of file Utils.h.

References accumulate().

Referenced by GEMMParam::__str__(), NativeGEMMConfig::__str__(), ReshapedOnlyRHSGEMMConfig::__str__(), ReshapedGEMMConfig::__str__(), Measurement::__str__(), enable_tracing::do_insert_tracing(), enable_tracing::get_class_and_args(), Framework::init(), join(), JSONPrinter::print_measurements(), format_doxygen::process_comment(), and GEMMBenchmarkResultRecorder::summary().

94 {
95  return std::accumulate(std::next(first), last, *first, [&separator](const std::string & base, const std::string & suffix)
96  {
97  return base + separator + suffix;
98  });
99 }
__kernel void accumulate(__global uchar *input_ptr, uint input_stride_x, uint input_step_x, uint input_stride_y, uint input_step_y, uint input_offset_first_element_in_bytes, __global uchar *accu_ptr, uint accu_stride_x, uint accu_step_x, uint accu_stride_y, uint accu_step_y, uint accu_offset_first_element_in_bytes)
This function accumulates an input image into output image.
Definition: accumulate.cl:41

◆ join() [2/3]

std::string arm_compute::test::join ( T &&  first,
T &&  last,
const std::string &  separator,
UnaryOp &&  op 
)

Helper function to concatenate multiple values.

All values are converted to std::string using the provided operation before being joined.

The signature of op has to be equivalent to std::string op(const T::value_type &val).

Parameters
[in]firstIterator pointing to the first element to be concatenated.
[in]lastIterator pointing behind the last element to be concatenated.
[in]separatorString used to join the elements.
[in]opConversion function.
Returns
String containing all elements joined by separator.

Definition at line 117 of file Utils.h.

References accumulate().

118 {
119  return std::accumulate(std::next(first), last, op(*first), [&separator, &op](const std::string & base, const typename T::value_type & suffix)
120  {
121  return base + separator + op(suffix);
122  });
123 }
__kernel void accumulate(__global uchar *input_ptr, uint input_stride_x, uint input_step_x, uint input_stride_y, uint input_step_y, uint input_offset_first_element_in_bytes, __global uchar *accu_ptr, uint accu_stride_x, uint accu_step_x, uint accu_stride_y, uint accu_step_y, uint accu_offset_first_element_in_bytes)
This function accumulates an input image into output image.
Definition: accumulate.cl:41

◆ join() [3/3]

std::string arm_compute::test::join ( T &&  first,
T &&  last,
const std::string &  separator 
)

Helper function to concatenate multiple values.

All values are converted to std::string using std::to_string before being joined.

Parameters
[in]firstIterator pointing to the first element to be concatenated.
[in]lastIterator pointing behind the last element to be concatenated.
[in]separatorString used to join the elements.
Returns
String containing all elements joined by separator.

Definition at line 136 of file Utils.h.

References join(), and arm_compute::support::cpp11::to_string().

137 {
138  return join(std::forward<T>(first), std::forward<T>(last), separator, support::cpp11::to_string);
139 }
std::string join(T &&first, T &&last, const std::string &separator)
Helper function to concatenate multiple values.
Definition: Utils.h:136
std::string to_string(const ICLTensor &arg)

◆ print_tensor()

void arm_compute::test::print_tensor ( ITensor tensor,
const std::string &  name,
IOFormatInfo  info = IOFormatInfo(IOFormatInfo::PrintRegion::Full) 
)
inline

Helper to print tensor.

Parameters
[in]tensorTensor to print.
[in]nameTensor name.
[in]infoFormat information.
Returns
Empty GCTensor with the specified shape and data type.

Definition at line 81 of file Helper.h.

References arm_compute::test::validation::info, IGCTensor::map(), ITensor::print(), tf_frozen_model_extractor::t, and IGCTensor::unmap().

82 {
83  std::ostringstream s;
84  IGCTensor &t = dynamic_cast<IGCTensor &>(tensor);
85  t.map();
86  t.print(s, info);
87 
88  std::cout << name << ":" << std::endl;
89  std::cout << s.str().c_str();
90  t.unmap();
91 }
const char * name
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)

◆ round_half_even()

T arm_compute::test::round_half_even ( value,
epsilon = std::numeric_limits<T>::epsilon() 
)
inline

Round floating-point value with half value rounding to nearest even.

Parameters
[in]valuefloating-point value to be rounded.
[in]epsilonprecision.
Returns
Floating-point value of rounded value.

Definition at line 88 of file Utils.h.

89 {
90  T positive_value = std::abs(value);
91  T ipart = 0;
92  std::modf(positive_value, &ipart);
93  // If 'value' is exactly halfway between two integers
94  if(std::abs(positive_value - (ipart + 0.5f)) < epsilon)
95  {
96  // If 'ipart' is even then return 'ipart'
97  if(std::fmod(ipart, 2.f) < epsilon)
98  {
99  return support::cpp11::copysign(ipart, value);
100  }
101  // Else return the nearest even integer
102  return support::cpp11::copysign(std::ceil(ipart + 0.5f), value);
103  }
104  // Otherwise use the usual round to closest
105  return support::cpp11::copysign(support::cpp11::round(positive_value), value);
106 }
T copysign(T x, T y)
Composes a floating point value with the magnitude of x and the sign of y.
int round(float x, RoundingPolicy rounding_policy)
Return a rounded value of x.
Definition: Rounding.cpp:35

◆ round_half_up()

T arm_compute::test::round_half_up ( value)
inline

Round floating-point value with half value rounding to positive infinity.

Parameters
[in]valuefloating-point value to be rounded.
Returns
Floating-point value of rounded value.

Definition at line 75 of file Utils.h.

76 {
77  return std::floor(value + 0.5f);
78 }

◆ saturate_cast()

T arm_compute::test::saturate_cast ( val)

Saturate a value of type T against the numeric limits of type U.

Parameters
[in]valValue to be saturated.
Returns
saturated value.

Definition at line 414 of file Utils.h.

References arm_compute::support::cpp11::lowest().

Referenced by arm_compute::test::validation::reference::absolute_difference(), arm_compute::test::validation::reference::accumulate(), arm_compute::test::validation::reference::accumulate_squared(), arm_compute::test::validation::reference::convolution(), arm_compute::test::validation::reference::magnitude(), and arm_compute::test::validation::reference::non_linear_filter().

415 {
416  if(val > static_cast<T>(std::numeric_limits<U>::max()))
417  {
418  val = static_cast<T>(std::numeric_limits<U>::max());
419  }
420  if(val < static_cast<T>(std::numeric_limits<U>::lowest()))
421  {
422  val = static_cast<T>(std::numeric_limits<U>::lowest());
423  }
424  return val;
425 }

◆ shape_to_valid_region()

ValidRegion arm_compute::test::shape_to_valid_region ( const TensorShape a_shape,
bool  border_undefined = false,
BorderSize  border_size = BorderSize(0) 
)
inline

Create a valid region based on tensor shape, border mode and border size.

Parameters
[in]a_shapeShape used as size of the valid region.
[in]border_undefined(Optional) Boolean indicating if the border mode is undefined.
[in]border_size(Optional) Border size used to specify the region to exclude.
Returns
A valid region starting at (0, 0, ...) with size of shape if border_undefined is false; otherwise return A valid region starting at (border_size.left, border_size.top, ...) with reduced size of shape.

Definition at line 225 of file Utils.h.

References ValidRegion::anchor, ARM_COMPUTE_ERROR_ON, Dimensions< T >::num_dimensions(), Dimensions< T >::set(), TensorShape::set(), arm_compute::test::validation::shape, ValidRegion::shape, arm_compute::test::validation::valid_region, Dimensions< T >::x(), and Dimensions< T >::y().

Referenced by arm_compute::test::validation::combine(), arm_compute::test::validation::reference::fast_corners(), arm_compute::test::validation::FIXTURE_DATA_TEST_CASE(), arm_compute::test::validation::reference::non_linear_filter(), arm_compute::test::validation::reference::non_maxima_suppression(), arm_compute::test::validation::reference::optical_flow(), arm_compute::test::validation::validate(), and arm_compute::test::validation::validate_wrap().

226 {
227  ValidRegion valid_region{ Coordinates(), a_shape };
228 
229  Coordinates &anchor = valid_region.anchor;
230  TensorShape &shape = valid_region.shape;
231 
232  if(border_undefined)
233  {
234  ARM_COMPUTE_ERROR_ON(shape.num_dimensions() < 2);
235 
236  anchor.set(0, border_size.left);
237  anchor.set(1, border_size.top);
238 
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));
241 
242  shape.set(0, valid_shape_x);
243  shape.set(1, valid_shape_y);
244  }
245 
246  return valid_region;
247 }
TensorShape shape
Shape of the valid region.
Definition: Types.h:261
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
const ValidRegion valid_region
Definition: Scale.cpp:221
Coordinates anchor
Anchor for the start of the valid region.
Definition: Types.h:260

◆ shape_to_valid_region_gaussian_pyramid_half()

ValidRegion arm_compute::test::shape_to_valid_region_gaussian_pyramid_half ( const TensorShape a_shape,
const ValidRegion a_valid_region,
bool  border_undefined = false 
)
inline

Create a valid region for Gaussian Pyramid Half based on tensor shape and valid region at level "i - 1" and border mode.

Note
The border size is 2 in case of Gaussian Pyramid Half
Parameters
[in]a_shapeShape used at level "i - 1" of Gaussian Pyramid Half
[in]a_valid_regionValid region used at level "i - 1" of Gaussian Pyramid Half
[in]border_undefined(Optional) Boolean indicating if the border mode is undefined.

return The valid region for the level "i" of Gaussian Pyramid Half

Definition at line 259 of file Utils.h.

References ValidRegion::anchor, ARM_COMPUTE_ERROR_ON, Dimensions< T >::num_dimensions(), Dimensions< T >::set(), TensorShape::set(), arm_compute::test::validation::shape, ValidRegion::shape, arm_compute::test::validation::valid_region, Dimensions< T >::x(), and Dimensions< T >::y().

Referenced by shape_to_valid_region_laplacian_pyramid().

260 {
261  constexpr int border_size = 2;
262 
263  ValidRegion valid_region{ Coordinates(), a_shape };
264 
265  Coordinates &anchor = valid_region.anchor;
266  TensorShape &shape = valid_region.shape;
267 
268  // Compute tensor shape for level "i" of Gaussian Pyramid Half
269  // dst_width = (src_width + 1) * 0.5f
270  // dst_height = (src_height + 1) * 0.5f
271  shape.set(0, (a_shape[0] + 1) * 0.5f);
272  shape.set(1, (a_shape[1] + 1) * 0.5f);
273 
274  if(border_undefined)
275  {
276  ARM_COMPUTE_ERROR_ON(shape.num_dimensions() < 2);
277 
278  // Compute the left and top invalid borders
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;
281 
282  // For the new anchor point we can have 2 cases:
283  // 1) If the width/height of the tensor shape is odd, we have to take the ceil value of (a_valid_region.anchor.x() + border_size) / 2.0f or (a_valid_region.anchor.y() + border_size / 2.0f
284  // 2) If the width/height of the tensor shape is even, we have to take the floor value of (a_valid_region.anchor.x() + border_size) / 2.0f or (a_valid_region.anchor.y() + border_size) / 2.0f
285  // In this manner we should be able to propagate correctly the valid region along all levels of the pyramid
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);
288 
289  // Set the anchor point
290  anchor.set(0, static_cast<int>(invalid_border_left));
291  anchor.set(1, static_cast<int>(invalid_border_top));
292 
293  // Compute shape
294  // Calculate the right and bottom invalid borders at the previous level of the pyramid
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]));
297 
298  // Calculate the right and bottom invalid borders at the current level of the pyramid
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);
301 
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));
304 
305  shape.set(0, valid_shape_x);
306  shape.set(1, valid_shape_y);
307  }
308 
309  return valid_region;
310 }
TensorShape shape
Shape of the valid region.
Definition: Types.h:261
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
const ValidRegion valid_region
Definition: Scale.cpp:221
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.
Definition: TensorShape.h:79
Coordinates anchor
Anchor for the start of the valid region.
Definition: Types.h:260

◆ shape_to_valid_region_laplacian_pyramid()

ValidRegion arm_compute::test::shape_to_valid_region_laplacian_pyramid ( const TensorShape a_shape,
const ValidRegion a_valid_region,
bool  border_undefined = false 
)
inline

Create a valid region for Laplacian Pyramid based on tensor shape and valid region at level "i - 1" and border mode.

Note
The border size is 2 in case of Laplacian Pyramid
Parameters
[in]a_shapeShape used at level "i - 1" of Laplacian Pyramid
[in]a_valid_regionValid region used at level "i - 1" of Laplacian Pyramid
[in]border_undefined(Optional) Boolean indicating if the border mode is undefined.

return The valid region for the level "i" of Laplacian Pyramid

Definition at line 322 of file Utils.h.

References ValidRegion::anchor, BorderSize::bottom, BorderSize::left, BorderSize::right, Dimensions< T >::set(), TensorShape::set(), ValidRegion::shape, shape_to_valid_region_gaussian_pyramid_half(), BorderSize::top, and arm_compute::test::validation::valid_region.

323 {
324  ValidRegion valid_region = shape_to_valid_region_gaussian_pyramid_half(a_shape, a_valid_region, border_undefined);
325 
326  if(border_undefined)
327  {
328  const BorderSize gaussian5x5_border(2);
329 
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);
334 
335  valid_region.anchor.set(0, valid_region.anchor[0] + border_left);
336  valid_region.anchor.set(1, valid_region.anchor[1] + border_top);
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));
339  }
340 
341  return valid_region;
342 }
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 - ...
Definition: Utils.h:259
const ValidRegion valid_region
Definition: Scale.cpp:221

◆ sleep_in_seconds()

void arm_compute::test::sleep_in_seconds ( float  seconds)

Makes the calling thread to sleep for a specified number of seconds.

Parameters
[in]secondsAmount of seconds to sleep. Will return immediately if less or equal to zero.

Definition at line 38 of file Utils.cpp.

Referenced by arithmetic_to_string(), and Framework::run().

39 {
40  // Early return on non-positive input
41  if(seconds <= 0.f)
42  {
43  return;
44  }
45 
46 #ifndef NO_MULTI_THREADING
47  const int64_t us = static_cast<int64_t>(seconds * 1e6);
48  std::this_thread::sleep_for(std::chrono::microseconds(us));
49 #endif /* NO_MULTI_THREADING */
50 }

◆ store_value_with_data_type()

void arm_compute::test::store_value_with_data_type ( void *  ptr,
value,
DataType  data_type 
)

Write the value after casting the pointer according to data_type.

Warning
The type of the value must match the specified data type.
Parameters
[out]ptrPointer to memory where the value will be written.
[in]valueValue that will be written.
[in]data_typeData type that will be written.

Definition at line 353 of file Utils.h.

References ARM_COMPUTE_ERROR, arm_compute::BFLOAT16, arm_compute::F16, arm_compute::F32, arm_compute::F64, arm_compute::QASYMM16, arm_compute::QASYMM8, arm_compute::QASYMM8_SIGNED, arm_compute::QSYMM16, arm_compute::QSYMM8, arm_compute::QSYMM8_PER_CHANNEL, arm_compute::S16, arm_compute::S32, arm_compute::S64, arm_compute::S8, arm_compute::SIZET, arm_compute::U16, arm_compute::U32, arm_compute::U64, and arm_compute::U8.

Referenced by AssetsLibrary::fill_boxes().

354 {
355  switch(data_type)
356  {
357  case DataType::U8:
358  case DataType::QASYMM8:
359  *reinterpret_cast<uint8_t *>(ptr) = value;
360  break;
361  case DataType::S8:
362  case DataType::QASYMM8_SIGNED:
363  case DataType::QSYMM8:
364  case DataType::QSYMM8_PER_CHANNEL:
365  *reinterpret_cast<int8_t *>(ptr) = value;
366  break;
367  case DataType::U16:
368  case DataType::QASYMM16:
369  *reinterpret_cast<uint16_t *>(ptr) = value;
370  break;
371  case DataType::S16:
372  case DataType::QSYMM16:
373  *reinterpret_cast<int16_t *>(ptr) = value;
374  break;
375  case DataType::U32:
376  *reinterpret_cast<uint32_t *>(ptr) = value;
377  break;
378  case DataType::S32:
379  *reinterpret_cast<int32_t *>(ptr) = value;
380  break;
381  case DataType::U64:
382  *reinterpret_cast<uint64_t *>(ptr) = value;
383  break;
384  case DataType::S64:
385  *reinterpret_cast<int64_t *>(ptr) = value;
386  break;
387  case DataType::BFLOAT16:
388  *reinterpret_cast<bfloat16 *>(ptr) = bfloat16(value);
389  break;
390  case DataType::F16:
391  *reinterpret_cast<half *>(ptr) = value;
392  break;
393  case DataType::F32:
394  *reinterpret_cast<float *>(ptr) = value;
395  break;
396  case DataType::F64:
397  *reinterpret_cast<double *>(ptr) = value;
398  break;
399  case DataType::SIZET:
400  *reinterpret_cast<size_t *>(ptr) = value;
401  break;
402  default:
403  ARM_COMPUTE_ERROR("NOT SUPPORTED!");
404  }
405 }
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
half_float::half half
16-bit floating point type
Definition: Types.h:46
arm_compute::bfloat16 bfloat16
Definition: bfloat.hpp:30
const DataType data_type
Definition: Im2Col.cpp:150

◆ swap()

void arm_compute::test::swap ( SimpleTensor< U > &  tensor1,
SimpleTensor< U > &  tensor2 
)
Parameters
[in,out]tensor1Tensor to be swapped.
[in,out]tensor2Tensor to be swapped.

Definition at line 442 of file SimpleTensor.h.

Referenced by SimpleTensor< uint8_t >::operator=().

443 {
444  // Use unqualified call to swap to enable ADL. But make std::swap available
445  // as backup.
446  using std::swap;
447  swap(tensor1._shape, tensor2._shape);
448  swap(tensor1._format, tensor2._format);
449  swap(tensor1._data_type, tensor2._data_type);
450  swap(tensor1._num_channels, tensor2._num_channels);
451  swap(tensor1._quantization_info, tensor2._quantization_info);
452  swap(tensor1._buffer, tensor2._buffer);
453 }
void swap(SimpleTensor< U > &tensor1, SimpleTensor< U > &tensor2)
Definition: SimpleTensor.h:442

◆ sync_if_necessary()

void arm_compute::test::sync_if_necessary ( )
inline

Sync if necessary.

Definition at line 790 of file Utils.h.

References CLScheduler::get(), arm_compute::opencl_is_available(), CLScheduler::sync(), and type.

791 {
792 #ifdef ARM_COMPUTE_CL
793  if(opencl_is_available() && std::is_same<typename std::decay<TensorType>::type, arm_compute::CLTensor>::value)
794  {
795  CLScheduler::get().sync();
796  }
797 #endif /* ARM_COMPUTE_CL */
798 }
decltype(strategy::transforms) typedef type
bool opencl_is_available()
Check if OpenCL is available.
Definition: OpenCL.cpp:152
Basic implementation of the OpenCL tensor interface.
Definition: CLTensor.h:41

◆ sync_tensor_if_necessary()

void arm_compute::test::sync_tensor_if_necessary ( TensorType tensor)
inline

Sync tensor if necessary.

Note
: If the destination tensor not being used on OpenGL ES, GPU will optimize out the operation.
Parameters
[in]tensorTensor to be sync.

Definition at line 807 of file Utils.h.

References ARM_COMPUTE_UNUSED, IGCTensor::map(), arm_compute::opengles31_is_available(), tf_frozen_model_extractor::t, type, and IGCTensor::unmap().

808 {
809 #ifdef ARM_COMPUTE_GC
810  if(opengles31_is_available() && std::is_same<typename std::decay<TensorType>::type, arm_compute::GCTensor>::value)
811  {
812  // Force sync the tensor by calling map and unmap.
813  IGCTensor &t = dynamic_cast<IGCTensor &>(tensor);
814  t.map();
815  t.unmap();
816  }
817 #else /* ARM_COMPUTE_GC */
818  ARM_COMPUTE_UNUSED(tensor);
819 #endif /* ARM_COMPUTE_GC */
820 }
bool opengles31_is_available()
Check if the OpenGL ES 3.1 API is available at runtime.
Definition: OpenGLES.cpp:160
decltype(strategy::transforms) typedef type
Interface for OpenGL ES tensor.
Definition: GCTensor.h:38
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152

◆ tolower()

std::string arm_compute::test::tolower ( std::string  string)
inline

Convert string to lower case.

Parameters
[in]stringTo be converted string.
Returns
Lower case string.

Definition at line 147 of file Utils.h.

References arm_compute::mlgo::parser::end().

Referenced by arm_compute::test::framework::dataset_mode_from_name(), arm_compute::test::framework::instrument_type_from_name(), arm_compute::test::framework::log_format_from_name(), and arm_compute::test::framework::log_level_from_name().

148 {
149  std::transform(string.begin(), string.end(), string.begin(), [](unsigned char c)
150  {
151  return std::tolower(c);
152  });
153  return string;
154 }
std::string tolower(std::string string)
Convert string to lower case.
Definition: Utils.h:147
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290

Variable Documentation

◆ fixed_library

std::unique_ptr< AssetsLibrary > fixed_library

Definition at line 81 of file main.cpp.

Referenced by main(), and arm_compute::utils::run_example().

◆ library

◆ parameters

std::unique_ptr< ParametersLibrary > parameters

Definition at line 46 of file Framework.cpp.

Referenced by main().