Compute Library
 19.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)
 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...
 
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 41 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 52 of file Dimensions.h.

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

◆ 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 194 of file Dimensions.h.

195  {
196  return _id.begin();
197  }

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

◆ 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 202 of file Dimensions.h.

203  {
204  return _id.begin();
205  }

◆ 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 210 of file Dimensions.h.

211  {
212  return begin();
213  }
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:194

Referenced by GCIm2ColKernel::configure(), GCFullyConnectedLayer::configure(), NEFullyConnectedLayer::configure(), CLFullyConnectedLayer::configure(), arm_compute::operator==(), arm_compute::test::validation::reference::slice(), arm_compute::test::validation::reference::strided_slice(), NESlice::validate(), CLSlice::validate(), NEFullyConnectedLayer::validate(), and CLFullyConnectedLayer::validate().

◆ 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 234 of file Dimensions.h.

235  {
236  return end();
237  }
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:218

Referenced by GCIm2ColKernel::configure(), GCFullyConnectedLayer::configure(), NEFullyConnectedLayer::configure(), CLFullyConnectedLayer::configure(), arm_compute::operator==(), NEFullyConnectedLayer::validate(), and CLFullyConnectedLayer::validate().

◆ 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 138 of file Dimensions.h.

139  {
140  ARM_COMPUTE_ERROR_ON(first + n > _id.size());
141 
142  const size_t last = std::min(_num_dimensions, first + n);
143 
144  if(last > (first + 1))
145  {
146  // Collapse dimensions into the first
147  _id[first] = std::accumulate(&_id[first], &_id[last], 1, std::multiplies<T>());
148  // Shift the remaining dimensions down
149  std::copy(&_id[last], &_id[_num_dimensions], &_id[first + 1]);
150  // Reduce the number of dimensions
151  const size_t old_num_dimensions = _num_dimensions;
152  _num_dimensions -= last - first - 1;
153  // Fill the now empty dimensions with zero
154  std::fill(&_id[_num_dimensions], &_id[old_num_dimensions], 0);
155  }
156  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:337
SimpleTensor< T > copy(const SimpleTensor< T > &src, const TensorShape &output_shape)
Definition: Copy.cpp:37
library fill(src, distribution, 0)
__kernel void accumulate(__global uchar *input_ptr, uint input_stride_x, uint input_step_x, uint input_stride_y, uint input_step_y, uint input_offset_first_element_in_bytes, __global uchar *accu_ptr, uint accu_stride_x, uint accu_step_x, uint accu_stride_y, uint accu_step_y, uint accu_offset_first_element_in_bytes)
This function accumulates an input image into output image.
Definition: accumulate.cl:41

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

◆ 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 162 of file Dimensions.h.

163  {
165 
166  collapse(num_dimensions() - start, start);
167  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:337
void collapse(const size_t n, const size_t first=0)
Collapse dimensions.
Definition: Dimensions.h:138
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
Definition: Dimensions.h:122

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

◆ 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 218 of file Dimensions.h.

219  {
220  return _id.end();
221  }

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

◆ 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 226 of file Dimensions.h.

227  {
228  return _id.end();
229  }

◆ num_dimensions()

unsigned int num_dimensions ( ) const
inline

Returns the effective dimensionality of the tensor.

Definition at line 122 of file Dimensions.h.

123  {
124  return _num_dimensions;
125  }

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::helpers::tensor_transform::calculate_start_on_index(), arm_compute::helpers::tensor_transform::calculate_stride_on_index(), 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(), DetectionOutputLayerNode::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(), FullyConnectedLayerNode::compute_weights_descriptor(), CLReduceMean::configure(), NEReduceMean::configure(), CLPermuteKernel::configure(), NEUnstack::configure(), CLUnstack::configure(), CLSelectKernel::configure(), NESelectKernel::configure(), CLGEMMLowpOffsetContributionOutputStageKernel::configure(), CLGEMMLowpOffsetContributionKernel::configure(), NEGEMMLowpOffsetContributionKernel::configure(), NEGEMMLowpOffsetContributionOutputStageKernel::configure(), arm_compute::helpers::tensor_transform::construct_slice_end_mask(), arm_compute::test::coord2index(), arm_compute::coords2index(), arm_compute::test::validation::reference::fully_connected_layer(), 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::operator==(), arm_compute::permute(), arm_compute::permute_strides(), CLElementwiseOperationKernel::run(), CLComparisonKernel::run(), CLPixelWiseMultiplicationKernel::run(), NEPixelWiseMultiplicationKernel::run(), CLComplexPixelWiseMultiplicationKernel::run(), arm_compute::test::validation::reference::select(), Dimensions< size_t >::set_num_dimensions(), TensorInfo::set_tensor_shape(), arm_compute::test::validation::reference::slice(), arm_compute::test::validation::reference::strided_slice(), Window::use_tensor_dimensions(), CLReduceMean::validate(), NEReduceMean::validate(), NEUnstack::validate(), NESlice::validate(), CLUnstack::validate(), CLSlice::validate(), CLCropKernel::validate(), NESelectKernel::validate(), NECropKernel::validate(), arm_compute::test::validation::validate(), and arm_compute::test::validation::zeros().

◆ operator=() [1/2]

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

Allow instances of this class to be copied.

◆ 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 103 of file Dimensions.h.

104  {
106  return _id[dimension];
107  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:337
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:45

◆ 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 116 of file Dimensions.h.

117  {
119  return _id[dimension];
120  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:337
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:45

◆ 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 175 of file Dimensions.h.

176  {
177  ARM_COMPUTE_ERROR_ON(_num_dimensions < 1);
178  if(idx >= _num_dimensions)
179  {
180  return;
181  }
182 
183  std::copy(_id.begin() + idx + 1, _id.end(), _id.begin() + idx);
184  _num_dimensions--;
185 
186  // Make sure all empty dimensions are filled with 0
187  std::fill(_id.begin() + _num_dimensions, _id.end(), 0);
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:337
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 
)
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.

Definition at line 74 of file Dimensions.h.

75  {
77  _id[dimension] = value;
78  _num_dimensions = std::max(_num_dimensions, dimension + 1);
79  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:337
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:45

Referenced by arm_compute::test::validation::apply_2d_spatial_filter(), arm_compute::calculate_valid_region_scale(), SplitLayerNode::compute_output_descriptor(), arm_compute::compute_strides(), AccessWindowTranspose::compute_valid_region(), AccessWindowStatic::compute_valid_region(), AccessWindowRectangle::compute_valid_region(), CLSplit::configure(), NESplit::configure(), NEUnstack::configure(), CLUnstack::configure(), NEWinogradConvolutionLayer::configure(), arm_compute::convert_window_coord_to_position(), arm_compute::test::validation::reference::depthwise_convolution(), arm_compute::test::validation::reference::dilate(), arm_compute::test::validation::reference::erode(), NPYLoader::fill_tensor(), CPPFlipWeightsKernel::flip_weights(), arm_compute::intersect_valid_regions(), arm_compute::permute(), arm_compute::permute_strides(), arm_compute::test::validation::reference::remap(), arm_compute::test::validation::reference::reorg_layer(), NEReorgLayerKernel::run(), ValidRegion::set(), arm_compute::test::shape_to_valid_region(), arm_compute::test::shape_to_valid_region_gaussian_pyramid_half(), arm_compute::test::shape_to_valid_region_laplacian_pyramid(), arm_compute::test::validation::tensor_elem_at(), arm_compute::test::validation::transpose(), NEUnstack::validate(), CLSplit::validate(), NESplit::validate(), CLUnstack::validate(), and arm_compute::test::validation::validate().

◆ set_num_dimensions()

void set_num_dimensions ( size_t  num_dimensions)
inline

Set number of dimensions.

Definition at line 128 of file Dimensions.h.

129  {
130  _num_dimensions = num_dimensions;
131  }
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
Definition: Dimensions.h:122

Referenced by CPPDetectionOutputLayer::configure(), CLPermuteKernel::configure(), CPPFlipWeightsKernel::configure(), NEChannelShuffleLayerKernel::configure(), CPPUpsampleKernel::configure(), NEQuantizationLayerKernel::configure(), CPPPermuteKernel::configure(), and NEPermuteKernel::configure().

◆ x()

T x ( ) const
inline

Alias to access the size of the first dimension.

Definition at line 81 of file Dimensions.h.

82  {
83  return _id[0];
84  }

Referenced by ImageAccessor::access_tensor(), ValidationInputAccessor::access_tensor(), arm_compute::test::validation::apply_2d_spatial_filter(), arm_compute::test::validation::reference::channel_combine(), 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::test::validation::compare_dimensions(), arm_compute::misc::shape_calculator::compute_output_stage_shape(), arm_compute::misc::shape_calculator::compute_vector_to_tensor_output_shape(), CLElementWiseUnaryLayerKernel::configure(), NELogits1DMaxKernel::configure(), CLDequantizationLayerKernel::configure(), CLQuantizationLayerKernel::configure(), CLTileKernel::configure(), CLSelectKernel::configure(), CLGEMMLowpOffsetContributionOutputStageKernel::configure(), CLStridedSliceKernel::configure(), CLGEMMLowpOffsetContributionKernel::configure(), CLFFTConvolutionLayer::configure(), NEFFTConvolutionLayer::configure(), CLCopyToArrayKernel::configure(), arm_compute::test::validation::reference::convert_fully_connected_weights(), arm_compute::test::validation::DATA_TEST_CASE(), arm_compute::test::validation::reference::dilate(), arm_compute::test::validation::reference::erode(), arm_compute::error_on_invalid_subtensor(), arm_compute::test::validation::reference::fast_corners(), PyramidInfo::init(), NEDepthwiseConvolutionAssemblyDispatch::is_optimized_supported(), WindowIterator< L >::iterate_2D(), arm_compute::test::validation::reference::median3x3(), arm_compute::test::validation::reference::non_linear_filter(), arm_compute::test::validation::reference::non_maxima_suppression(), arm_compute::test::validation::reference::pad_layer(), NEGEMMLowpOffsetContributionKernel::run(), NEWeightsReshapeKernel::run(), NELogits1DSoftmaxKernel::run(), arm_compute::test::validation::reference::scale_core(), arm_compute::test::validation::reference::select(), arm_compute::test::shape_to_valid_region_gaussian_pyramid_half(), arm_compute::test::validation::tensor_elem_at(), arm_compute::test::validation::reference::tile(), arm_compute::test::validation::reference::transpose(), arm_compute::test::validation::transpose(), NESelectKernel::validate(), CLFFTConvolutionLayer::validate(), NEFFTConvolutionLayer::validate(), arm_compute::test::validation::reference::warp_affine(), arm_compute::test::validation::reference::warp_perspective(), and PyramidInfo::width().

◆ y()

T y ( ) const
inline

Alias to access the size of the second dimension.

Definition at line 86 of file Dimensions.h.

87  {
88  return _id[1];
89  }

Referenced by ImageAccessor::access_tensor(), ValidationInputAccessor::access_tensor(), arm_compute::test::validation::apply_2d_spatial_filter(), arm_compute::test::validation::reference::channel_combine(), arm_compute::test::validation::reference::col2im(), arm_compute::misc::shape_calculator::compute_output_stage_shape(), CLSelectKernel::configure(), CLGEMMLowpOffsetContributionOutputStageKernel::configure(), CLGEMMLowpOffsetContributionKernel::configure(), CLFFTConvolutionLayer::configure(), NEFFTConvolutionLayer::configure(), arm_compute::test::validation::reference::convert_fully_connected_weights(), arm_compute::test::validation::DATA_TEST_CASE(), arm_compute::test::validation::reference::dilate(), arm_compute::test::validation::reference::erode(), arm_compute::error_on_invalid_subtensor(), arm_compute::test::validation::reference::fast_corners(), PyramidInfo::height(), PyramidInfo::init(), NEDepthwiseConvolutionAssemblyDispatch::is_optimized_supported(), WindowIterator< L >::iterate_2D(), arm_compute::test::validation::reference::non_maxima_suppression(), arm_compute::test::validation::reference::pad_layer(), NEDepthwiseConvolutionAssemblyDispatch::prepare(), NEGEMMLowpOffsetContributionKernel::run(), CLWinogradOutputTransformKernel::run(), NEWeightsReshapeKernel::run(), NEDepthwiseConvolutionAssemblyDispatch::run(), arm_compute::test::shape_to_valid_region_gaussian_pyramid_half(), arm_compute::test::validation::tensor_elem_at(), arm_compute::test::validation::reference::tile(), arm_compute::test::validation::reference::transpose(), and arm_compute::test::validation::transpose().

◆ z()

Field Documentation

◆ num_max_dimensions

constexpr size_t num_max_dimensions = MAX_DIMS
static

Number of dimensions the tensor has.

Definition at line 45 of file Dimensions.h.

Referenced by Dimensions< size_t >::operator[]().


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