Compute Library
 21.02
arm_compute::utils::cast Namespace Reference

Functions

template<typename Target , typename Source >
Target polymorphic_cast (Source *v)
 Polymorphic cast between two types. More...
 
template<typename Target , typename Source >
Target polymorphic_downcast (Source *v)
 Polymorphic down cast between two types. More...
 
template<typename Target , typename Source , typename Deleter >
std::unique_ptr< Target, Deleter > polymorphic_cast_unique_ptr (std::unique_ptr< Source, Deleter > &&v)
 Polymorphic cast between two unique pointer types. More...
 
template<typename Target , typename Source , typename Deleter >
std::unique_ptr< Target, Deleter > polymorphic_downcast_unique_ptr (std::unique_ptr< Source, Deleter > &&v)
 Polymorphic down cast between two unique pointer types. More...
 
template<typename T , typename U , typename std::enable_if< std::is_same< T, U >::value, int >::type = 0>
saturate_cast (U v)
 
template<typename T , typename U , typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value &&std::is_signed< U >() &&std::is_signed< T >() &&!std::is_same< T, U >::value &&sizeof(T) > = sizeof(U), int >
std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value &&std::is_signed< U >) &&std::is_signed< T >) &&!std::is_same< T, U >::value &&sizeof(T)< sizeof(U), int >::type=0 > T saturate_cast (U v)
 

Variables

template<typename T , typename U , typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value &&std::is_signed< U >() &&std::is_signed< T >() &&!std::is_same< T, U >::value &&sizeof(T) > = sizeof(U), int >
 U
 

Function Documentation

◆ polymorphic_cast()

Target arm_compute::utils::cast::polymorphic_cast ( Source *  v)
inline

Polymorphic cast between two types.

Warning
Will throw an exception if cast cannot take place
Template Parameters
TargetTarget to cast type
SourceSource from cast type
Parameters
[in]vValue to cast
Returns
The casted value

Definition at line 47 of file Cast.h.

References ARM_COMPUTE_THROW.

48 {
49  if(dynamic_cast<Target>(v) == nullptr)
50  {
51  ARM_COMPUTE_THROW(std::bad_cast());
52  }
53  return static_cast<Target>(v);
54 }
#define ARM_COMPUTE_THROW(ex)
Definition: Error.h:480

◆ polymorphic_cast_unique_ptr()

std::unique_ptr<Target, Deleter> arm_compute::utils::cast::polymorphic_cast_unique_ptr ( std::unique_ptr< Source, Deleter > &&  v)

Polymorphic cast between two unique pointer types.

Warning
Will throw an exception if cast cannot take place
Template Parameters
TargetTarget to cast type
SourceSource from cast type
DeleterDeleter function type
Parameters
[in]vValue to cast
Returns
The casted value

Definition at line 87 of file Cast.h.

References ARM_COMPUTE_THROW.

88 {
89  if(dynamic_cast<Target *>(v.get()) == nullptr)
90  {
91  ARM_COMPUTE_THROW(std::bad_cast());
92  }
93  auto r = static_cast<Target *>(v.release());
94  return std::unique_ptr<Target, Deleter>(r, std::move(v.get_deleter()));
95 }
#define ARM_COMPUTE_THROW(ex)
Definition: Error.h:480

◆ polymorphic_downcast()

Target arm_compute::utils::cast::polymorphic_downcast ( Source *  v)
inline

Polymorphic down cast between two types.

Warning
Will assert if cannot take place
Template Parameters
TargetTarget to cast type
SourceSource from cast type
Parameters
[in]vValue to cast
Returns
The casted value

Definition at line 68 of file Cast.h.

References ARM_COMPUTE_ERROR_ON.

69 {
70  ARM_COMPUTE_ERROR_ON(dynamic_cast<Target>(v) != static_cast<Target>(v));
71  return static_cast<Target>(v);
72 }
#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

◆ polymorphic_downcast_unique_ptr()

std::unique_ptr<Target, Deleter> arm_compute::utils::cast::polymorphic_downcast_unique_ptr ( std::unique_ptr< Source, Deleter > &&  v)

Polymorphic down cast between two unique pointer types.

Warning
Will assert if cannot take place
Template Parameters
TargetTarget to cast type
SourceSource from cast type
DeleterDeleter function type
Parameters
[in]vValue to cast
Returns
The casted value

Definition at line 110 of file Cast.h.

References ARM_COMPUTE_ERROR_ON.

111 {
112  ARM_COMPUTE_ERROR_ON(dynamic_cast<Target *>(v.get()) != static_cast<Target *>(v.get()));
113  auto r = static_cast<Target *>(v.release());
114  return std::unique_ptr<Target, Deleter>(r, std::move(v.get_deleter()));
115 }
#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

◆ saturate_cast() [1/2]

T saturate_cast ( U  v)
inline

Definition at line 43 of file SaturateCast.h.

References U.

44 {
45  return v;
46 }

◆ saturate_cast() [2/2]

std::enable_if<std::is_integral<T>::value && std::is_integral<U>::value && std::is_signed<U>) && std::is_signed<T>) && !std::is_same<T, U>::value && sizeof(T) < sizeof(U), int >::type = 0 > T arm_compute::utils::cast::saturate_cast ( U  v)
inline

Definition at line 72 of file SaturateCast.h.

References arm_compute::support::cpp11::lowest(), and U.

73 {
74  return static_cast<T>(utility::clamp<U>(v, std::numeric_limits<T>::lowest(), std::numeric_limits<T>::max()));
75 }

Variable Documentation

◆ U

U

Definition at line 57 of file SaturateCast.h.

Referenced by arm_compute::adjust_odd_shape(), arm_compute::test::validation::reference::box3x3(), arm_compute::calculate_subsampled_shape(), arm_compute::test::validation::reference::channel_combine(), arm_compute::test::colorconvert_helper::detail::colorconvert_rgb_to_iyuv(), arm_compute::test::colorconvert_helper::detail::colorconvert_rgb_to_nv12(), arm_compute::test::colorconvert_helper::detail::colorconvert_rgb_to_yuv4(), arm_compute::test::validation::combine(), arm_compute::test::validation::compare_dimensions(), arm_compute::test::validation::reference::concatenate_layer(), CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure(), CLGEMMDefaultConfigReshapedRHSOnlyValhall::configure(), FusedConvolutionBatchNormalizationFunction< TargetInfo, FusedLayerTypes >::configure(), arm_compute::test::validation::reference::conv2d_dft(), arm_compute::graph::backends::detail::create_convolution_layer(), arm_compute::graph::backends::detail::create_convolution_layer< GCConvolutionLayerFunctions, GCTargetInfo >(), arm_compute::create_lws_hint_parallel_implementations(), arm_compute::test::validation::DATA_TEST_CASE(), DATA_TEST_CASE(), arm_compute::test::validation::reference::deconvolution_layer(), arm_compute::test::validation::reference::dft_2d(), arm_compute::error_on_mismatching_shapes(), NPYLoader::fill_tensor(), arm_compute::test::validation::FIXTURE_DATA_TEST_CASE(), arm_compute::test::validation::reference::gaussian3x3(), arm_compute::test::validation::reference::gaussian5x5(), GCGEMMMatrixAccumulateBiasesKernel::GCGEMMMatrixAccumulateBiasesKernel(), GCTensorShiftKernel::GCTensorShiftKernel(), arm_compute::softmax_helpers::get_permutation_vector_from_softmax_axis(), IGCKernel::IGCKernel(), compare< RelativeTolerance< U > >::operator bool(), arm_compute::graph_utils::permute_shape(), arm_compute::permute_strides(), arm_compute::test::validation::reference::pooling_layer_internal(), arm_compute::test::validation::reference::rdft_2d(), PaddingCalculator::required_padding(), arm_compute::test::validation::reference::ridft_2d(), saturate_cast(), arm_compute::test::validation::reference::scale_core(), ZipDataset< T, U >::size(), JoinDataset< T, U >::size(), CartesianProductDataset< T, U >::size(), arm_compute::test::validation::TEST_CASE(), arm_compute::test::validation::validate(), and arm_compute::test::validation::validate_wrap().