Compute Library
 21.02
arm_compute::support::cpp11 Namespace Reference

Enumerations

enum  NumericBase { BASE_10, BASE_16 }
 

Functions

int stoi (const std::string &str, std::size_t *pos=0, NumericBase base=NumericBase::BASE_10)
 Convert string values to integer. More...
 
unsigned long stoul (const std::string &str, std::size_t *pos=0, NumericBase base=NumericBase::BASE_10)
 Convert string values to unsigned long. More...
 
template<typename T >
std::string to_string (T &&value)
 Convert integer and float values to string. More...
 
template<typename... Ts>
int stof (Ts &&... args)
 Convert string values to float. More...
 
std::string to_string (bool value)
 
template<typename T >
nearbyint (T value)
 Rounds the floating-point argument arg to an integer value in floating-point format, using the current rounding mode. More...
 
template<typename T , typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
round (T value)
 Round floating-point value with half value rounding away from zero. More...
 
template<typename T , typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
trunc (T value)
 Truncate floating-point value. More...
 
template<typename T , typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
copysign (T x, T y)
 Composes a floating point value with the magnitude of x and the sign of y. More...
 
template<typename T , typename = typename std::enable_if < std::is_floating_point<T>::value >::type>
fma (T x, T y, T z)
 Computes (x*y) + z as if to infinite precision and rounded only once to fit the result type. More...
 
template<typename... Ts>
int snprintf (char *s, std::size_t n, const char *fmt, Ts &&... args)
 Loads the data from the given location, converts them to character string equivalents and writes the result to a character string buffer. More...
 
template<typename T >
lowest ()
 
template<>
bfloat16 lowest< bfloat16 > ()
 
template<typename T , typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
bool isfinite (T value)
 
bool isfinite (half_float::half value)
 
bool isfinite (bfloat16 value)
 

Enumeration Type Documentation

◆ NumericBase

enum NumericBase
strong
Enumerator
BASE_10 
BASE_16 

Definition at line 38 of file StringSupport.h.

Function Documentation

◆ copysign()

T arm_compute::support::cpp11::copysign ( x,
y 
)
inline

Composes a floating point value with the magnitude of x and the sign of y.

Note
This function implements the same behaviour as std::copysign except that it doesn't support Integral type. The latter is not in the namespace std in some Android toolchains.
Parameters
[in]xvalue that contains the magnitude to be used in constructing the result.
[in]yvalue that contains the sign to be used in construct in the result.
Returns
Floating-point value with magnitude of x and sign of y.

Definition at line 201 of file ToolchainSupport.h.

Referenced by arm_compute::utils::rounding::round_half_even().

202 {
203  return std::copysign(x, y);
204 }
T copysign(T x, T y)
Composes a floating point value with the magnitude of x and the sign of y.

◆ fma()

T arm_compute::support::cpp11::fma ( x,
y,
z 
)
inline

Computes (x*y) + z as if to infinite precision and rounded only once to fit the result type.

Note
This function implements the same behaviour as std::fma except that it doesn't support Integral type. The latter is not in the namespace std in some Android toolchains.
Parameters
[in]xfloating-point value
[in]yfloating-point value
[in]zfloating-point value
Returns
Result floating point value equal to (x*y) + z.

Definition at line 222 of file ToolchainSupport.h.

223 {
224  return std::fma(x, y, z);
225 }
T fma(T x, T y, T z)
Computes (x*y) + z as if to infinite precision and rounded only once to fit the result type...

◆ isfinite() [1/3]

bool arm_compute::support::cpp11::isfinite ( value)
inline

◆ isfinite() [2/3]

bool arm_compute::support::cpp11::isfinite ( half_float::half  value)
inline

Definition at line 273 of file ToolchainSupport.h.

References isfinite().

274 {
275  return half_float::isfinite(value);
276 }
bool isfinite(bfloat16 value)

◆ isfinite() [3/3]

bool arm_compute::support::cpp11::isfinite ( bfloat16  value)
inline

Definition at line 278 of file ToolchainSupport.h.

Referenced by isfinite().

279 {
280  return std::isfinite(float(value));
281 }
bool isfinite(bfloat16 value)

◆ lowest()

◆ lowest< bfloat16 >()

Definition at line 261 of file ToolchainSupport.h.

References bfloat16::lowest().

262 {
263  return bfloat16::lowest();
264 }

◆ nearbyint()

T arm_compute::support::cpp11::nearbyint ( value)
inline

Rounds the floating-point argument arg to an integer value in floating-point format, using the current rounding mode.

Note
This function acts as a convenience wrapper around std::nearbyint. The latter is missing in some Android toolchains.
Parameters
[in]valueValue to be rounded.
Returns
The rounded value.

Definition at line 154 of file ToolchainSupport.h.

Referenced by arm_compute::cpu::elementwise_op_scalar_imp(), and arm_compute::test::validation::reference::elementwise_unary().

155 {
156  return static_cast<T>(std::nearbyint(value));
157 }
T nearbyint(T value)
Rounds the floating-point argument arg to an integer value in floating-point format, using the current rounding mode.

◆ round()

T arm_compute::support::cpp11::round ( value)
inline

Round floating-point value with half value rounding away from zero.

Note
This function implements the same behaviour as std::round except that it doesn't support Integral type. The latter is not in the namespace std in some Android toolchains.
Parameters
[in]valuefloating-point value to be rounded.
Returns
Floating-point value of rounded value.

Definition at line 169 of file ToolchainSupport.h.

Referenced by arm_compute::quantization::calculate_quantized_multiplier_greater_than_one(), arm_compute::quantization::calculate_quantized_multiplier_less_than_one(), choose_quantization_params(), arm_compute::round(), arm_compute::utils::rounding::round_half_even(), and NEROIPoolingLayerKernel::run().

170 {
171  //Workaround Valgrind's mismatches: when running from Valgrind the call to std::round(-4.500000) == -4.000000 instead of 5.00000
172  return (value < 0.f) ? static_cast<int>(value - 0.5f) : static_cast<int>(value + 0.5f);
173 }

◆ snprintf()

int arm_compute::support::cpp11::snprintf ( char *  s,
std::size_t  n,
const char *  fmt,
Ts &&...  args 
)
inline

Loads the data from the given location, converts them to character string equivalents and writes the result to a character string buffer.

Parameters
[in]sPointer to a character string to write to
[in]nUp to buf_size - 1 characters may be written, plus the null terminator
[in]fmtPointer to a null-terminated multibyte string specifying how to interpret the data.
[in]argsArguments forwarded to std::snprintf.
Returns
Number of characters that would have been written for a sufficiently large buffer if successful (not including the terminating null character), or a negative value if an error occurred.

Definition at line 239 of file ToolchainSupport.h.

References GemmTuner::args.

Referenced by arm_compute::create_error_msg(), and arm_compute::logging::string_with_format().

240 {
241  return std::snprintf(s, n, fmt, std::forward<Ts>(args)...);
242 }
int snprintf(char *s, std::size_t n, const char *fmt, Ts &&... args)
Loads the data from the given location, converts them to character string equivalents and writes the ...

◆ stof()

int arm_compute::support::cpp11::stof ( Ts &&...  args)

Convert string values to float.

Note
This function acts as a convenience wrapper around std::stof. The latter is missing in some Android toolchains.
Parameters
[in]argsArguments forwarded to std::stof.
Returns
Float representation of input string.

Definition at line 177 of file StringSupport.h.

References GemmTuner::args.

178 {
179  return ::std::stof(std::forward<Ts>(args)...);
180 }
int stof(Ts &&... args)
Convert string values to float.

◆ stoi()

int arm_compute::support::cpp11::stoi ( const std::string &  str,
std::size_t *  pos = 0,
NumericBase  base = NumericBase::BASE_10 
)
inline

Convert string values to integer.

Note
This function implements the same behaviour as std::stoi. The latter is missing in some Android toolchains.
Parameters
[in]strString to be converted to int.
[in]posIf idx is not a null pointer, the function sets the value of pos to the position of the first character in str after the number.
[in]baseNumeric base used to interpret the string.
Returns
Integer representation of str.

Definition at line 55 of file StringSupport.h.

References BASE_10, BASE_16, arm_compute::test::validation::ss(), and caffe_data_extractor::str.

Referenced by CLTuningParams::from_string().

56 {
57  assert(base == NumericBase::BASE_10 || base == NumericBase::BASE_16);
58  unsigned int x;
59  std::stringstream ss;
60  if(base == NumericBase::BASE_16)
61  {
62  ss << std::hex;
63  }
64  ss << str;
65  ss >> x;
66 
67  if(pos)
68  {
69  std::string s;
70  std::stringstream ss_p;
71 
72  ss_p << x;
73  ss_p >> s;
74  *pos = s.length();
75  }
76 
77  return x;
78 }
std::stringstream ss(mlgo_str)

◆ stoul()

unsigned long arm_compute::support::cpp11::stoul ( const std::string &  str,
std::size_t *  pos = 0,
NumericBase  base = NumericBase::BASE_10 
)
inline

Convert string values to unsigned long.

Note
This function implements the same behaviour as std::stoul. The latter is missing in some Android toolchains.
Parameters
[in]strString to be converted to unsigned long.
[in]posIf idx is not a null pointer, the function sets the value of pos to the position of the first character in str after the number.
[in]baseNumeric base used to interpret the string.
Returns
Unsigned long representation of str.

Definition at line 91 of file StringSupport.h.

References BASE_10, and BASE_16.

92 {
93  assert(base == NumericBase::BASE_10 || base == NumericBase::BASE_16);
94  std::stringstream stream;
95  unsigned long value = 0;
96  if(base == NumericBase::BASE_16)
97  {
98  stream << std::hex;
99  }
100  stream << str;
101  stream >> value;
102 
103  if(pos)
104  {
105  std::string s;
106  std::stringstream ss_p;
107 
108  ss_p << value;
109  ss_p >> s;
110  *pos = s.length();
111  }
112 
113  return value;
114 }

◆ to_string() [1/2]

std::string arm_compute::support::cpp11::to_string ( T &&  value)
inline

Convert integer and float values to string.

Note
This function acts as a convenience wrapper around std::to_string. The latter is missing in some Android toolchains.
Parameters
[in]valueValue to be converted to string.
Returns
String representation of value.

Definition at line 162 of file StringSupport.h.

Referenced by GCLogits1DMaxKernel::configure(), GCScaleKernel::configure(), GCTransposeKernel::configure(), ClFloorKernel::configure(), CLIntegralImageHorKernel::configure(), ClCopyKernel::configure(), ClElementWiseUnaryKernel::configure(), GCGEMMMatrixAccumulateBiasesKernel::configure(), CLMedian3x3Kernel::configure(), ClActivationKernel::configure(), ClWidthConcatenate2TensorsKernel::configure(), CLTransposeKernel::configure(), CLStridedSliceKernel::configure(), ClHeightConcatenateKernel::configure(), ClPoolingKernel::configure(), ClWidthConcatenateKernel::configure(), CLScaleKernel::configure(), ClWidthConcatenate4TensorsKernel::configure(), CLWarpAffineKernel::configure(), ClBatchConcatenateKernel::configure(), ClDepthConcatenateKernel::configure(), ClFillKernel::configure(), GCDepthwiseConvolutionLayer3x3Kernel::configure(), GCPixelWiseMultiplicationKernel::configure(), GCFillBorderKernel::configure(), GCGEMMMatrixAdditionKernel::configure(), GCNormalizationLayerKernel::configure(), GCPoolingLayerKernel::configure(), GCAbsoluteDifferenceKernel::configure(), GCNormalizePlanarYUVLayerKernel::configure(), CLDequantizationLayerKernel::configure(), GCArithmeticAdditionKernel::configure(), GCGEMMTranspose1xWKernel::configure(), CLMaxUnpoolingLayerKernel::configure(), CLGaussianPyramidHorKernel::configure(), CLMinMaxLayerKernel::configure(), CLBitwiseKernel::configure(), CLDepthwiseConvolutionLayerReshapeWeightsKernel::configure(), CLReverseKernel::configure(), CLSelectKernel::configure(), GCActivationLayerKernel::configure(), GCBatchNormalizationLayerKernel::configure(), CLHistogramKernel::configure(), GCDepthConcatenateLayerKernel::configure(), GCDirectConvolutionLayerKernel< kernel_size >::configure(), CLChannelShuffleLayerKernel::configure(), ClPermuteKernel::configure(), CLMinMaxKernel::configure(), CLBatchToSpaceLayerKernel::configure(), CLDepthToSpaceLayerKernel::configure(), CLSpaceToDepthLayerKernel::configure(), CLComputeAllAnchorsKernel::configure(), GCLogits1DShiftExpSumKernel::configure(), CLFFTScaleKernel::configure(), CLNormalizationLayerKernel::configure(), CLQLSTMLayerNormalizationKernel::configure(), CLGatherKernel::configure(), CLSpaceToBatchLayerKernel::configure(), CLGradientKernel::configure(), GCDropoutLayerKernel::configure(), CLComparisonKernel::configure(), CLGEMMLowpQuantizeDownInt32ScaleByFixedPointKernel::configure(), CLTileKernel::configure(), GCGEMMMatrixMultiplyKernel::configure(), CLFFTDigitReverseKernel::configure(), CLQuantizationLayerKernel::configure(), CLReorgLayerKernel::configure(), CLHOGOrientationBinningKernel::configure(), CLInstanceNormalizationLayerKernel::configure(), ClCropKernel::configure(), CLMeanStdDevNormalizationKernel::configure(), CLSobel3x3Kernel::configure(), CLDerivativeKernel::configure(), CLColorConvertKernel::configure(), CLNormalizePlanarYUVLayerKernel::configure(), CLRangeKernel::configure(), CLSobel5x5HorKernel::configure(), CLSobel7x7HorKernel::configure(), CLLogits1DMaxShiftExpSumKernel::configure(), GCGEMMInterleave4x4Kernel::configure(), CLPadLayerKernel::configure(), CLFFTRadixStageKernel::configure(), CLConvertFullyConnectedWeightsKernel::configure(), CLPriorBoxLayerKernel::configure(), CLReductionOperationKernel::configure(), GCTensorShiftKernel::configure(), CLL2NormalizeLayerKernel::configure(), CLBoundingBoxTransformKernel::configure(), CLMagnitudePhaseKernel::configure(), CLGEMMLowpMatrixMultiplyNativeKernel::configure(), CLIntegralImageVertKernel::configure(), CLFillBorderKernel::configure(), CLStackLayerKernel::configure(), CLFastCornersKernel::configure(), CLDepthConvertLayerKernel::configure(), CLDepthwiseConvolutionLayer3x3NCHWKernel::configure(), CLGEMMReshapeLHSMatrixKernel::configure(), CLArgMinMaxLayerKernel::configure(), CLGEMMLowpQuantizeDownInt32ScaleKernel::configure(), CLDepthwiseConvolutionLayer3x3NHWCKernel::configure(), GCWeightsReshapeKernel::configure(), CLROIPoolingLayerKernel::configure(), GCCol2ImKernel::configure(), GCIm2ColKernel::configure(), CLROIAlignLayerKernel::configure(), CLDeconvolutionReshapeOutputKernel::configure(), CLHarrisScoreKernel::configure(), CLWinogradInputTransformKernel::configure(), CLHOGDetectorKernel::configure(), CLBatchNormalizationLayerKernel::configure(), CLCol2ImKernel::configure(), CLFuseBatchNormalizationKernel::configure(), CLWinogradFilterTransformKernel::configure(), CLGEMMMatrixMultiplyNativeKernel::configure(), CLGEMMMatrixMultiplyKernel::configure(), CLGEMMLowpMatrixMultiplyReshapedKernel::configure(), CLGEMMLowpOffsetContributionKernel::configure(), CLWinogradOutputTransformKernel::configure(), CLDepthwiseConvolutionLayerNativeKernel::configure(), CLDirectConvolutionLayerKernel::configure(), CLGEMMLowpOffsetContributionOutputStageKernel::configure(), CLWeightsReshapeKernel::configure(), GCLogits1DNormKernel::configure(), CLIm2ColKernel::configure(), CLGEMMReshapeRHSMatrixKernel::configure(), CLHistogramBorderKernel::configure(), CLGaussianPyramidVertKernel::configure(), CLPixelWiseMultiplicationKernel::configure(), CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel::configure(), CLGEMMLowpMatrixAReductionKernel::configure(), CLHOGBlockNormalizationKernel::configure(), CLGEMMMatrixMultiplyReshapedOnlyRHSKernel::configure(), CLEdgeNonMaxSuppressionKernel::configure(), CLSeparableConvolutionHorKernel< matrix_size >::configure(), CLCopyToArrayKernel::configure(), CLSobel7x7VertKernel::configure(), CLSobel5x5VertKernel::configure(), CLLogits1DNormKernel::configure(), CLSeparableConvolutionVertKernel< matrix_size >::configure(), CLGEMMLowpMatrixBReductionKernel::configure(), CLEdgeTraceKernel::configure(), CLConvolutionRectangleKernel::configure(), RangeDataset< T >::iterator::description(), SingletonDataset< T >::iterator::description(), ContainerDataset< T >::iterator::description(), arm_compute::utils::get_typestring(), arm_compute::test::get_typestring(), arm_compute::test::join(), main(), OpenCLClock< output_timestamps >::measurements(), MaliCounter::measurements(), SchedulerClock< output_timestamps >::measurements(), DotGraphPrinter::print(), arm_compute::utils::run_example(), CLCompileContext::set_context(), Size2D::to_string(), CLTuningParams::to_string(), arm_compute::to_string(), and CLTuner::tune_kernel_dynamic().

163 {
164  return ::std::to_string(std::forward<T>(value));
165 }
std::string to_string(bool value)

◆ to_string() [2/2]

std::string arm_compute::support::cpp11::to_string ( bool  value)
inline

Definition at line 184 of file StringSupport.h.

185 {
186  std::stringstream str;
187  str << std::boolalpha << value;
188  return str.str();
189 }

◆ trunc()

T arm_compute::support::cpp11::trunc ( value)
inline

Truncate floating-point value.

Note
This function implements the same behaviour as std::truncate except that it doesn't support Integral type. The latter is not in the namespace std in some Android toolchains.
Parameters
[in]valuefloating-point value to be truncated.
Returns
Floating-point value of truncated value.

Definition at line 185 of file ToolchainSupport.h.

Referenced by arm_compute::test::validation::apply_2d_spatial_filter(), and FilePrinter::FilePrinter().

186 {
187  return std::trunc(value);
188 }
T trunc(T value)
Truncate floating-point value.