Compute Library
 21.08
Dimensions< T > Class Template Reference

Dimensions with dimensionality. More...

#include <Dimensions.h>

Public Member Functions

template<typename... Ts>
 Dimensions (Ts... dims)
 Constructor to initialize the tensor shape. More...
 
 Dimensions (const Dimensions &)=default
 Allow instances of this class to be copy constructed. More...
 
Dimensionsoperator= (const Dimensions &)=default
 Allow instances of this class to be copied. More...
 
 Dimensions (Dimensions &&)=default
 Allow instances of this class to be move constructed. More...
 
Dimensionsoperator= (Dimensions &&)=default
 Allow instances of this class to be moved. More...
 
void set (size_t dimension, T value, bool increase_dim_unit=true)
 Accessor to set the value of one of the dimensions. More...
 
x () const
 Alias to access the size of the first dimension. More...
 
y () const
 Alias to access the size of the second dimension. More...
 
z () const
 Alias to access the size of the third dimension. More...
 
void increment (size_t dim, T step=1)
 Increments the given dimension by a step size, avoiding overflows. More...
 
const T & operator[] (size_t dimension) const
 Generic accessor to get the size of any dimension. More...
 
T & operator[] (size_t dimension)
 Generic accessor to get the size of any dimension. More...
 
unsigned int num_dimensions () const
 Returns the effective dimensionality of the tensor. More...
 
void set_num_dimensions (size_t num_dimensions)
 Set number of dimensions. More...
 
void collapse (const size_t n, const size_t first=0)
 Collapse dimensions. More...
 
void collapse_from (size_t start)
 Collapse dimensions starting from a given point. More...
 
void remove (size_t idx)
 Remove dimension of a given index. More...
 
std::array< T, num_max_dimensions >::iterator begin ()
 Returns a read/write iterator that points to the first element in the dimension array. More...
 
std::array< T, num_max_dimensions >::const_iterator begin () const
 Returns a read-only (constant) iterator that points to the first element in the dimension array. More...
 
std::array< T, num_max_dimensions >::const_iterator cbegin () const
 Returns a read-only (constant) iterator that points to the first element in the dimension array. More...
 
std::array< T, num_max_dimensions >::iterator end ()
 Returns a read/write iterator that points one past the last element in the dimension array. More...
 
std::array< T, num_max_dimensions >::const_iterator end () const
 Returns a read-only (constant) iterator that points one past the last element in the dimension array. More...
 
std::array< T, num_max_dimensions >::const_iterator cend () const
 Returns a read-only (constant) iterator that points one past the last element in the dimension array. More...
 

Static Public Attributes

static constexpr size_t num_max_dimensions = MAX_DIMS
 Number of dimensions the tensor has. More...
 

Detailed Description

template<typename T>
class arm_compute::Dimensions< T >

Dimensions with dimensionality.

Definition at line 42 of file Dimensions.h.

Constructor & Destructor Documentation

◆ Dimensions() [1/3]

Dimensions ( Ts...  dims)
inlineexplicit

Constructor to initialize the tensor shape.

Parameters
[in]dimsValues to initialize the dimensions.

Definition at line 53 of file Dimensions.h.

Referenced by Dimensions< size_t >::Dimensions().

54  : _id{ { static_cast<T>(dims)... } }, _num_dimensions{ sizeof...(dims) }
55  {
56  }

◆ Dimensions() [2/3]

Dimensions ( const Dimensions< T > &  )
default

Allow instances of this class to be copy constructed.

◆ Dimensions() [3/3]

Dimensions ( Dimensions< T > &&  )
default

Allow instances of this class to be move constructed.

Member Function Documentation

◆ begin() [1/2]

std::array<T, num_max_dimensions>::iterator begin ( )
inline

Returns a read/write iterator that points to the first element in the dimension array.

Returns
an iterator.

Definition at line 215 of file Dimensions.h.

Referenced by arm_compute::misc::shape_calculator::calculate_reduce_mean_shape(), Dimensions< size_t >::cbegin(), NEReduceMean::configure(), CLReduceMean::configure(), arm_compute::permute(), and arm_compute::permute_strides().

216  {
217  return _id.begin();
218  }

◆ begin() [2/2]

std::array<T, num_max_dimensions>::const_iterator begin ( ) const
inline

Returns a read-only (constant) iterator that points to the first element in the dimension array.

Returns
an iterator.

Definition at line 223 of file Dimensions.h.

224  {
225  return _id.begin();
226  }

◆ cbegin()

std::array<T, num_max_dimensions>::const_iterator cbegin ( ) const
inline

Returns a read-only (constant) iterator that points to the first element in the dimension array.

Returns
an iterator.

Definition at line 231 of file Dimensions.h.

Referenced by ClFullyConnected::configure(), CpuFullyConnected::configure(), arm_compute::operator==(), arm_compute::test::validation::reference::slice(), arm_compute::test::validation::reference::strided_slice(), ClFullyConnected::validate(), CpuFullyConnected::validate(), NESlice::validate(), and CLSlice::validate().

232  {
233  return begin();
234  }
std::array< T, num_max_dimensions >::iterator begin()
Returns a read/write iterator that points to the first element in the dimension array.
Definition: Dimensions.h:215

◆ cend()

std::array<T, num_max_dimensions>::const_iterator cend ( ) const
inline

Returns a read-only (constant) iterator that points one past the last element in the dimension array.

Returns
an iterator.

Definition at line 255 of file Dimensions.h.

Referenced by ClFullyConnected::configure(), CpuFullyConnected::configure(), arm_compute::operator==(), ClFullyConnected::validate(), and CpuFullyConnected::validate().

256  {
257  return end();
258  }
std::array< T, num_max_dimensions >::iterator end()
Returns a read/write iterator that points one past the last element in the dimension array...
Definition: Dimensions.h:239

◆ collapse()

void collapse ( const size_t  n,
const size_t  first = 0 
)
inline

Collapse dimensions.

Parameters
[in]nNumber of dimensions to collapse into first.
[in]firstDimensions into which the following n are collapsed.

Definition at line 159 of file Dimensions.h.

Referenced by TensorShape::collapse(), and Dimensions< size_t >::collapse_from().

160  {
161  ARM_COMPUTE_ERROR_ON(first + n > _id.size());
162 
163  const size_t last = std::min(_num_dimensions, first + n);
164 
165  if(last > (first + 1))
166  {
167  // Collapse dimensions into the first
168  _id[first] = std::accumulate(&_id[first], &_id[last], 1, std::multiplies<T>());
169  // Shift the remaining dimensions down
170  std::copy(&_id[last], &_id[_num_dimensions], &_id[first + 1]);
171  // Reduce the number of dimensions
172  const size_t old_num_dimensions = _num_dimensions;
173  _num_dimensions -= last - first - 1;
174  // Fill the now empty dimensions with zero
175  std::fill(&_id[_num_dimensions], &_id[old_num_dimensions], 0);
176  }
177  }
#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
SimpleTensor< T > copy(const SimpleTensor< T > &src, const TensorShape &output_shape)
Definition: Copy.cpp:37
SimpleTensor< T2 > accumulate(const SimpleTensor< T1 > &src, DataType output_data_type)
Definition: Accumulate.cpp:38
library fill(src, distribution, 0)

◆ collapse_from()

void collapse_from ( size_t  start)
inline

Collapse dimensions starting from a given point.

Parameters
[in]startStarting point of collapsing dimensions

Definition at line 183 of file Dimensions.h.

Referenced by arm_compute::misc::shape_calculator::compute_softmax_shape().

184  {
186 
187  collapse(num_dimensions() - start, start);
188  }
#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
void collapse(const size_t n, const size_t first=0)
Collapse dimensions.
Definition: Dimensions.h:159
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
Definition: Dimensions.h:143

◆ end() [1/2]

std::array<T, num_max_dimensions>::iterator end ( )
inline

Returns a read/write iterator that points one past the last element in the dimension array.

Returns
an iterator.

Definition at line 239 of file Dimensions.h.

Referenced by Dimensions< size_t >::cend(), arm_compute::permute(), and arm_compute::permute_strides().

240  {
241  return _id.end();
242  }

◆ end() [2/2]

std::array<T, num_max_dimensions>::const_iterator end ( ) const
inline

Returns a read-only (constant) iterator that points one past the last element in the dimension array.

Returns
an iterator.

Definition at line 247 of file Dimensions.h.

248  {
249  return _id.end();
250  }

◆ increment()

void increment ( size_t  dim,
step = 1 
)
inline

Increments the given dimension by a step size, avoiding overflows.

Note
Precondition: dim < _num_dimensions
Parameters
[in]dimDimension to increment.
[in]stepStep to increment dim by.

Definition at line 108 of file Dimensions.h.

109  {
110  ARM_COMPUTE_ERROR_ON(dim >= _num_dimensions);
111  if((std::numeric_limits<T>::max() - _id[dim]) >= step)
112  {
113  _id[dim] += step;
114  }
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
constexpr int step
Definition: fp32.cpp:35

◆ num_dimensions()

unsigned int num_dimensions ( ) const
inline

Returns the effective dimensionality of the tensor.

Definition at line 143 of file Dimensions.h.

Referenced by TensorInfo::auto_padding(), TensorShape::broadcast_shape(), arm_compute::helpers::tensor_transform::calculate_end_on_index(), arm_compute::calculate_max_enlarged_window(), arm_compute::calculate_max_window(), arm_compute::calculate_max_window_horizontal(), arm_compute::misc::shape_calculator::calculate_reduce_mean_shape(), arm_compute::helpers::tensor_transform::calculate_start_on_index(), arm_compute::helpers::tensor_transform::calculate_stride_on_index(), arm_compute::helpers::tensor_transform::calculate_strided_slice_coords(), arm_compute::misc::shape_calculator::calculate_unstack_shape(), arm_compute::calculate_valid_region_scale(), Dimensions< size_t >::collapse_from(), arm_compute::test::validation::compare_dimensions(), arm_compute::misc::shape_calculator::compute_gather_shape(), arm_compute::misc::shape_calculator::compute_im2col_conv_shape(), DetectionOutputLayerNode::compute_output_descriptor(), SplitLayerNode::compute_output_descriptor(), FullyConnectedLayerNode::compute_output_descriptor(), arm_compute::misc::shape_calculator::compute_padded_shape(), arm_compute::misc::shape_calculator::compute_softmax_shape(), arm_compute::misc::shape_calculator::compute_split_shape(), arm_compute::helpers::tensor_transform::compute_strided_slice_output_shape(), FullyConnectedLayerNode::compute_weights_descriptor(), ClPermuteKernel::configure(), CLStridedSliceKernel::configure(), CLSelectKernel::configure(), CpuGemmLowpOffsetContributionKernel::configure(), NESelectKernel::configure(), ClGemmLowpOffsetContributionKernel::configure(), ClGemmLowpOffsetContributionOutputStageKernel::configure(), ClGemmLowpMatrixMultiplyReshapedOnlyRhsKernel::configure(), NEUnstack::configure(), CLUnstack::configure(), NEReduceMean::configure(), CLReduceMean::configure(), CpuGemmLowpOffsetContributionOutputStageKernel::configure(), CPPSplit< CLSlice, ICLTensor >::configure(), arm_compute::helpers::tensor_transform::construct_slice_end_mask(), arm_compute::convert_negative_axis(), arm_compute::test::coord2index(), arm_compute::coords2index(), arm_compute::test::validation::DATA_TEST_CASE(), arm_compute::test::validation::reference::fully_connected_layer(), arm_compute::test::index2coord(), arm_compute::index2coords(), arm_compute::intersect_valid_regions(), SubTensorInfo::num_dimensions(), TensorInfo::num_dimensions(), SubTensorInfo::offset_element_in_bytes(), TensorInfo::offset_element_in_bytes(), arm_compute::operator==(), arm_compute::permute(), arm_compute::permute_strides(), CLComparisonKernel::run(), ClElementwiseKernel::run_op(), ClMulKernel::run_op(), ClComplexMulKernel::run_op(), arm_compute::test::validation::reference::select(), Dimensions< size_t >::set_num_dimensions(), TensorInfo::set_tensor_shape(), arm_compute::test::shape_to_valid_region(), arm_compute::test::validation::reference::slice(), arm_compute::test::validation::reference::stack_layer(), arm_compute::test::validation::reference::strided_slice(), Window::use_tensor_dimensions(), CPPSplit< CLSlice, ICLTensor >::validate(), ClCropKernel::validate(), SplitLayerNode::validate(), NESelectKernel::validate(), NEUnstack::validate(), CLUnstack::validate(), NECropKernel::validate(), NESlice::validate(), arm_compute::test::validation::validate(), CLSlice::validate(), arm_compute::test::detail::validate_npy_header(), and arm_compute::test::validation::zeros().

144  {
145  return _num_dimensions;
146  }

◆ operator=() [1/2]

Dimensions& operator= ( const Dimensions< T > &  )
default

Allow instances of this class to be copied.

Referenced by Dimensions< size_t >::Dimensions().

◆ operator=() [2/2]

Dimensions& operator= ( Dimensions< T > &&  )
default

Allow instances of this class to be moved.

◆ operator[]() [1/2]

const T& operator[] ( size_t  dimension) const
inline

Generic accessor to get the size of any dimension.

Note
Precondition: dimension < Dimensions::num_max_dimensions
Parameters
[in]dimensionDimension of the wanted size
Returns
The size of the requested dimension.

Definition at line 124 of file Dimensions.h.

125  {
127  return _id[dimension];
128  }
#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
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:46

◆ operator[]() [2/2]

T& operator[] ( size_t  dimension)
inline

Generic accessor to get the size of any dimension.

Note
Precondition: dimension < Dimensions::num_max_dimensions
Parameters
[in]dimensionDimension of the wanted size
Returns
The size of the requested dimension.

Definition at line 137 of file Dimensions.h.

138  {
140  return _id[dimension];
141  }
#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
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:46

◆ remove()

void remove ( size_t  idx)
inline

Remove dimension of a given index.

Note
If index is greater than the number of dimensions no operation is performed
Parameters
[in]idxDimension index to remove

Definition at line 196 of file Dimensions.h.

197  {
198  ARM_COMPUTE_ERROR_ON(_num_dimensions < 1);
199  if(idx >= _num_dimensions)
200  {
201  return;
202  }
203 
204  std::copy(_id.begin() + idx + 1, _id.end(), _id.begin() + idx);
205  _num_dimensions--;
206 
207  // Make sure all empty dimensions are filled with 0
208  std::fill(_id.begin() + _num_dimensions, _id.end(), 0);
209  }
#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
SimpleTensor< T > copy(const SimpleTensor< T > &src, const TensorShape &output_shape)
Definition: Copy.cpp:37
library fill(src, distribution, 0)

◆ set()

void set ( size_t  dimension,
value,
bool  increase_dim_unit = true 
)
inline

Accessor to set the value of one of the dimensions.

Parameters
[in]dimensionDimension for which the value is set.
[in]valueValue to be set for the dimension.
[in]increase_dim_unit(Optional) Set to true if new unit dimensions increase the number of dimensions (e.g. for Coordinates), false otherwise (e.g. for TensorShapes)

Definition at line 76 of file Dimensions.h.

Referenced by arm_compute::test::validation::apply_2d_spatial_filter(), arm_compute::calculate_valid_region_scale(), arm_compute::test::colorconvert_helper::detail::colorconvert_iyuv_to_rgb(), arm_compute::test::colorconvert_helper::detail::colorconvert_nv12_to_rgb(), SplitLayerNode::compute_output_descriptor(), arm_compute::compute_strides(), AccessWindowTranspose::compute_valid_region(), AccessWindowStatic::compute_valid_region(), AccessWindowRectangle::compute_valid_region(), NEUnstack::configure(), CLUnstack::configure(), CpuWinogradConv2d::configure(), CPPSplit< CLSlice, ICLTensor >::configure(), arm_compute::convert_window_coord_to_position(), arm_compute::test::validation::reference::erode(), NPYLoader::fill_tensor(), arm_compute::test::validation::reference::gather(), arm_compute::intersect_valid_regions(), arm_compute::test::validation::reference::logical_binary_op(), NEGatherKernel::NEGatherKernel(), arm_compute::test::colorconvert_helper::detail::nv_to_yuv4(), arm_compute::permute(), arm_compute::permute_strides(), arm_compute::test::validation::reference::remap(), arm_compute::test::validation::reference::reorg_layer(), NEReorgLayerKernel::run(), TensorShape::set(), arm_compute::test::shape_to_valid_region(), arm_compute::test::validation::reference::slice(), arm_compute::test::validation::reference::softmax_layer_generic(), arm_compute::test::validation::reference::strided_slice(), arm_compute::test::validation::tensor_elem_at(), arm_compute::test::validation::transpose(), CPPSplit< CLSlice, ICLTensor >::validate(), NEUnstack::validate(), CLUnstack::validate(), and arm_compute::test::validation::validate().

77  {
79  _id[dimension] = value;
80  // Don't increase the number of dimensions if the new dimension is 1
81  if(increase_dim_unit || value != 1)
82  {
83  _num_dimensions = std::max(_num_dimensions, dimension + 1);
84  }
85  }
#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
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:46

◆ set_num_dimensions()

void set_num_dimensions ( size_t  num_dimensions)
inline

Set number of dimensions.

Definition at line 149 of file Dimensions.h.

Referenced by CpuTransposeKernel::configure(), CPPDetectionOutputLayer::configure(), CPPUpsampleKernel::configure(), CPPPermuteKernel::configure(), DATA_TEST_CASE(), and NPYLoader::init_tensor().

150  {
151  _num_dimensions = num_dimensions;
152  }
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
Definition: Dimensions.h:143

◆ x()

T x ( ) const
inline

Alias to access the size of the first dimension.

Definition at line 87 of file Dimensions.h.

Referenced by ImageAccessor::access_tensor(), ValidationInputAccessor::access_tensor(), arm_compute::cpu::add_qasymm8_neon(), arm_compute::cpu::add_qasymm8_signed_neon(), arm_compute::cpu::add_qsymm16_neon(), arm_compute::cpu::add_same_neon(), arm_compute::test::validation::apply_2d_spatial_filter(), arm_compute::test::validation::reference::col2im(), arm_compute::test::colorconvert_helper::detail::colorconvert_iyuv_to_rgb(), arm_compute::test::colorconvert_helper::detail::colorconvert_nv12_to_rgb(), 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_yuyv_to_rgb(), arm_compute::misc::shape_calculator::compute_output_stage_shape(), arm_compute::misc::shape_calculator::compute_vector_to_tensor_output_shape(), ClDequantizeKernel::configure(), ClElementWiseUnaryKernel::configure(), ClCopyKernel::configure(), ClQuantizeKernel::configure(), CLStridedSliceKernel::configure(), CLSelectKernel::configure(), CLTileKernel::configure(), ClGemmLowpOffsetContributionKernel::configure(), ClGemmLowpOffsetContributionOutputStageKernel::configure(), NEFFTConvolutionLayer::configure(), CLFFTConvolutionLayer::configure(), arm_compute::test::validation::reference::convert_fully_connected_weights(), ITensor::copy_from(), arm_compute::test::validation::reference::deconvolution_layer(), arm_compute::cpu::elementwise_comp_quantized_signed(), arm_compute::cpu::elementwise_op(), arm_compute::cpu::elementwise_op_quantized(), arm_compute::cpu::elementwise_op_quantized_signed(), arm_compute::test::validation::reference::erode(), SubTensorInfo::extend_padding(), AssetsLibrary::fill_borders_with_garbage(), arm_compute::cpu::neon_softmax_logits_1d_float(), arm_compute::cpu::neon_softmax_logits_1d_quantized(), arm_compute::test::validation::reference::non_maxima_suppression(), arm_compute::test::validation::reference::pad_layer(), arm_compute::cpu::poolingMxN_q8_neon_nhwc(), arm_compute::test::validation::reference::scale_core(), arm_compute::test::validation::reference::select(), arm_compute::test::shape_to_valid_region(), arm_compute::cpu::sub_qasymm8_neon(), arm_compute::cpu::sub_qasymm8_signed_neon(), arm_compute::cpu::sub_qsymm16_neon(), arm_compute::cpu::sub_same_neon(), arm_compute::test::validation::tensor_elem_at(), arm_compute::test::validation::TEST_CASE(), arm_compute::test::validation::reference::tile(), arm_compute::test::validation::reference::transpose(), arm_compute::test::validation::transpose(), NEQLSTMLayerNormalizationKernel::validate(), NESelectKernel::validate(), NEFFTConvolutionLayer::validate(), NEDeconvolutionLayer::validate(), and CLFFTConvolutionLayer::validate().

88  {
89  return _id[0];
90  }

◆ y()

T y ( ) const
inline

Alias to access the size of the second dimension.

Definition at line 92 of file Dimensions.h.

Referenced by ImageAccessor::access_tensor(), ValidationInputAccessor::access_tensor(), arm_compute::test::validation::apply_2d_spatial_filter(), arm_compute::test::validation::reference::col2im(), arm_compute::colorconvert_iyuv_to_rgb(), arm_compute::colorconvert_nv12_to_rgb(), arm_compute::misc::shape_calculator::compute_output_stage_shape(), CLSelectKernel::configure(), ClGemmLowpOffsetContributionKernel::configure(), ClGemmLowpOffsetContributionOutputStageKernel::configure(), NEFFTConvolutionLayer::configure(), CLFFTConvolutionLayer::configure(), arm_compute::test::validation::reference::convert_fully_connected_weights(), ITensor::copy_from(), arm_compute::test::validation::reference::deconvolution_layer(), DetectionOutputAccessor::DetectionOutputAccessor(), arm_compute::test::validation::reference::erode(), SubTensorInfo::extend_padding(), AssetsLibrary::fill_borders_with_garbage(), arm_compute::test::validation::reference::non_maxima_suppression(), arm_compute::cpu::offset_no_padding(), arm_compute::test::validation::reference::pad_layer(), arm_compute::cpu::poolingMxN_fp32_neon_nhwc(), arm_compute::cpu::poolingMxN_q8_neon_nhwc(), arm_compute::test::shape_to_valid_region(), arm_compute::test::validation::tensor_elem_at(), arm_compute::test::validation::reference::tile(), arm_compute::test::validation::reference::transpose(), arm_compute::test::validation::transpose(), CpuGemmLowpMatrixAReductionKernel::validate(), and NEDeconvolutionLayer::validate().

93  {
94  return _id[1];
95  }

◆ z()

Field Documentation

◆ num_max_dimensions

constexpr size_t num_max_dimensions = MAX_DIMS
static

Number of dimensions the tensor has.

Definition at line 46 of file Dimensions.h.


The documentation for this class was generated from the following file: