Compute Library
 20.05
arm_compute::utility Namespace Reference

Namespaces

 detail
 

Functions

template<std::size_t N, typename Iterator >
std::array< typename std::iterator_traits< Iterator >::value_type, N > make_array (Iterator first, Iterator last)
 
template<typename DataType , typename RangeType = DataType>
DataType clamp (const DataType &n, const DataType &lower=std::numeric_limits< RangeType >::lowest(), const DataType &upper=std::numeric_limits< RangeType >::max())
 Performs clamping among a lower and upper value. More...
 
template<typename F >
void for_each (F &&)
 Base case of for_each. More...
 
template<typename F , typename T , typename... Ts>
void for_each (F &&func, T &&arg, Ts &&... args)
 Call the function for each of the arguments. More...
 
template<typename F , typename T >
T && foldl (F &&, T &&value)
 Base case of foldl. More...
 
template<typename F , typename T , typename U , typename... Us>
auto foldl (F &&func, T &&initial, U &&value, Us &&... values) -> decltype(func(std::forward< T >(initial), std::forward< U >(value)))
 Fold left. More...
 
template<typename T >
std::vector< size_t > sort_indices (const std::vector< T > &v)
 Perform an index sort of a given vector. More...
 
bool endswith (const std::string &str, const std::string &suffix)
 Checks if a string contains a given suffix. More...
 
bool check_aligned (void *ptr, const size_t alignment)
 Checks if a pointer complies with a given alignment. More...
 
std::string tolower (std::string string)
 Convert string to lower case. More...
 

Function Documentation

◆ check_aligned()

bool arm_compute::utility::check_aligned ( void *  ptr,
const size_t  alignment 
)
inline

Checks if a pointer complies with a given alignment.

Parameters
[in]ptrPointer to check
[in]alignmentAlignment value
Returns
True if the pointer is aligned else false

Definition at line 192 of file Utility.h.

193 {
194  return (reinterpret_cast<std::uintptr_t>(ptr) % alignment) == 0;
195 }

Referenced by TensorAllocator::import_memory(), and arm_compute::test::validation::TEST_CASE().

◆ clamp()

DataType arm_compute::utility::clamp ( const DataType n,
const DataType lower = std::numeric_limits<RangeType>::lowest(),
const DataType upper = std::numeric_limits<RangeType>::max() 
)
inline

Performs clamping among a lower and upper value.

Parameters
[in]nValue to clamp.
[in]lowerLower threshold.
[in]upperUpper threshold.
Returns
Clamped value.

Definition at line 99 of file Utility.h.

102 {
103  return std::max(lower, std::min(n, upper));
104 }

Referenced by arm_compute::helpers::tensor_transform::calculate_end_on_index(), arm_compute::helpers::tensor_transform::calculate_start_on_index(), clamp_to_border_with_size(), clamp_to_border_with_size_quantized(), arm_compute::compute_region_coordinate(), arm_compute::test::validation::reference::roi_align_layer(), and roi_pooling_layer().

◆ endswith()

bool arm_compute::utility::endswith ( const std::string &  str,
const std::string &  suffix 
)
inline

Checks if a string contains a given suffix.

Parameters
[in]strInput string
[in]suffixSuffix to check for
Returns
True if the string ends with the given suffix else false

Definition at line 176 of file Utility.h.

177 {
178  if(str.size() < suffix.size())
179  {
180  return false;
181  }
182  return std::equal(suffix.rbegin(), suffix.rend(), str.rbegin());
183 }

Referenced by arm_compute::graph_utils::get_input_accessor().

◆ foldl() [1/2]

T&& arm_compute::utility::foldl ( F &&  ,
T &&  value 
)
inline

Base case of foldl.

Returns
value.

Definition at line 130 of file Utility.h.

131 {
132  return std::forward<T>(value);
133 }

Referenced by arm_compute::intersect_valid_regions().

◆ foldl() [2/2]

auto arm_compute::utility::foldl ( F &&  func,
T &&  initial,
U &&  value,
Us &&...  values 
) -> decltype(func(std::forward<T>(initial), std::forward<U>(value)))
inline

Fold left.

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

Definition at line 143 of file Utility.h.

144 {
145  return foldl(std::forward<F>(func), func(std::forward<T>(initial), std::forward<U>(value)), std::forward<Us>(values)...);
146 }
auto foldl(F &&func, T &&initial, U &&value, Us &&... values) -> decltype(func(std::forward< T >(initial), std::forward< U >(value)))
Fold left.
Definition: Utility.h:143

◆ for_each() [1/2]

◆ for_each() [2/2]

void arm_compute::utility::for_each ( F &&  func,
T &&  arg,
Ts &&...  args 
)
inline

Call the function for each of the arguments.

Parameters
[in]funcFunction to be called
[in]argArgument passed to the function
[in]argsRemaining arguments

Definition at line 119 of file Utility.h.

120 {
121  func(std::forward<T>(arg));
122  for_each(std::forward<F>(func), std::forward<Ts>(args)...);
123 }
void for_each(F &&func, T &&arg, Ts &&... args)
Call the function for each of the arguments.
Definition: Utility.h:119

References GemmTuner::args, and for_each().

◆ make_array()

std::array<typename std::iterator_traits<Iterator>::value_type, N> arm_compute::utility::make_array ( Iterator  first,
Iterator  last 
)

Definition at line 84 of file Utility.h.

85 {
86  ARM_COMPUTE_UNUSED(last);
87  return detail::make_array(first, index_sequence_t<N> {});
88 }
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
std::array< typename std::iterator_traits< Iterator >::value_type, N > make_array(Iterator first, Iterator last)
Definition: Utility.h:84

References ARM_COMPUTE_UNUSED, and arm_compute::utility::detail::make_array().

◆ sort_indices()

std::vector<size_t> arm_compute::utility::sort_indices ( const std::vector< T > &  v)

Perform an index sort of a given vector.

Parameters
[in]vVector to sort
Returns
Sorted index vector.

Definition at line 155 of file Utility.h.

156 {
157  std::vector<size_t> idx(v.size());
158  std::iota(idx.begin(), idx.end(), 0);
159 
160  std::sort(idx.begin(), idx.end(),
161  [&v](size_t i1, size_t i2)
162  {
163  return v[i1] < v[i2];
164  });
165 
166  return idx;
167 }

◆ tolower()

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

Convert string to lower case.

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

Definition at line 203 of file Utility.h.

204 {
205  std::transform(string.begin(), string.end(), string.begin(), [](unsigned char c)
206  {
207  return std::tolower(c);
208  });
209  return string;
210 }
std::string tolower(std::string string)
Convert string to lower case.
Definition: Utility.h:203

Referenced by GCScaleKernel::configure(), CLWarpPerspectiveKernel::configure(), CLWarpAffineKernel::configure(), CLScaleKernel::configure(), CLNonLinearFilterKernel::configure(), CLRemapKernel::configure(), arm_compute::graph::Convolution_method_from_name(), arm_compute::data_layout_from_name(), arm_compute::data_type_from_name(), arm_compute::graph::depthwise_convolution_method_from_name(), arm_compute::lower_string(), arm_compute::graph::target_from_name(), and arm_compute::tuner_mode_from_name().