Compute Library
 21.11
arm_compute::utility Namespace Reference

Namespaces

 detail
 

Functions

template<std::size_t N, typename Iterator >
std::array< typename std::iterator_traits< Iterator >::value_type, Nmake_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...
 
std::string getenv (const std::string &env_name)
 Get environment variable as a string. 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 194 of file Utility.h.

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

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

◆ 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

◆ 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 178 of file Utility.h.

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

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

◆ foldl() [1/2]

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

Base case of foldl.

Returns
value.

Definition at line 132 of file Utility.h.

References arm_compute::utils::cast::U.

Referenced by foldl(), and arm_compute::intersect_valid_regions().

133 {
134  return std::forward<T>(value);
135 }

◆ 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 145 of file Utility.h.

References foldl().

146 {
147  return foldl(std::forward<F>(func), func(std::forward<T>(initial), std::forward<U>(value)), std::forward<Us>(values)...);
148 }
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:145

◆ 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 121 of file Utility.h.

References GemmTuner::args, and for_each().

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

◆ getenv()

std::string arm_compute::utility::getenv ( const std::string &  env_name)
inline

Get environment variable as a string.

Note
Return empty string on bare-metal
Parameters
[in]env_nameName of the Environment variable to retrieve
Returns
Environment variable content, or empty string if the variable is undefined or on bare-metal

Definition at line 222 of file Utility.h.

References ARM_COMPUTE_UNUSED.

223 {
224 #ifdef BARE_METAL
225  ARM_COMPUTE_UNUSED(env_name);
226  return std::string{};
227 #else // BARE_METAL
228  const auto env_chr = std::getenv(env_name.c_str());
229  return env_chr == nullptr ? std::string{} : std::string{ env_chr };
230 #endif // BARE_METAL
231 }
std::string getenv(const std::string &env_name)
Get environment variable as a string.
Definition: Utility.h:222
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152

◆ make_array()

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

Definition at line 86 of file Utility.h.

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

87 {
88  ARM_COMPUTE_UNUSED(last);
89  return detail::make_array(first, index_sequence_t<N> {});
90 }
#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:86

◆ 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 157 of file Utility.h.

Referenced by InstrumentsStats::InstrumentsStats().

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

◆ 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 205 of file Utility.h.

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

Referenced by HeuristicTree::add_branch(), ClScaleKernel::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::utils::operator>>(), CommandLineParser::parse(), arm_compute::graph::target_from_name(), and arm_compute::tuner_mode_from_name().

206 {
207  std::transform(string.begin(), string.end(), string.begin(), [](unsigned char c)
208  {
209  return std::tolower(c);
210  });
211  return string;
212 }
std::string tolower(std::string string)
Convert string to lower case.
Definition: Utility.h:205
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290