Compute Library  18.05
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...
 
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 ( Ts...  dims)
inlineexplicit

Constructor to initialize the tensor shape.

Parameters
[in]dimsValues to initialize the dimensions.

Definition at line 52 of file Dimensions.h.

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

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

Allow instances of this class to be copy constructed.

Dimensions ( Dimensions< T > &&  )
default

Allow instances of this class to be move constructed.

Member Function Documentation

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

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

174  {
175  return _id.begin();
176  }
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 181 of file Dimensions.h.

182  {
183  return _id.begin();
184  }
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 189 of file Dimensions.h.

Referenced by arm_compute::operator==(), and SimpleTensor< T >::size().

190  {
191  return begin();
192  }
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:173
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 213 of file Dimensions.h.

Referenced by arm_compute::operator==(), and SimpleTensor< T >::size().

214  {
215  return end();
216  }
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:197
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.

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

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  }
fixed_point< T > min(fixed_point< T > x, fixed_point< T > y)
Definition: FixedPoint.h:897
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:328
SimpleTensor< T > copy(const SimpleTensor< T > &src, const TensorShape &output_shape)
Definition: Copy.cpp:37
__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
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:328
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
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 197 of file Dimensions.h.

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

198  {
199  return _id.end();
200  }
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 205 of file Dimensions.h.

206  {
207  return _id.end();
208  }
unsigned int num_dimensions ( ) const
inline

Returns the effective dimensionality of the tensor.

Definition at line 122 of file Dimensions.h.

Referenced by NumPyBinLoader::access_tensor(), TensorShape::broadcast_shape(), Dimensions< size_t >::collapse_from(), arm_compute::test::validation::compare_dimensions(), arm_compute::test::coord2index(), arm_compute::coords2index(), arm_compute::test::validation::DATA_TEST_CASE(), arm_compute::test::validation::reference::fully_connected_layer(), LeNet5Network< TensorType, Accessor, ActivationLayerFunction, ConvolutionLayerFunction, FullyConnectedLayerFunction, PoolingLayerFunction, SoftmaxLayerFunction >::get_classifications(), MobileNetNetwork< TensorType, Accessor, ActivationLayerFunction, ConvolutionLayerFunction, DirectConvolutionLayerFunction, DepthwiseConvolutionLayerFunction, ReshapeFunction, PoolingLayerFunction >::get_classifications(), MobileNetV1Network< TensorType, Accessor, ActivationLayerFunction, BatchNormalizationLayerFunction, ConvolutionLayerFunction, DirectConvolutionLayerFunction, DepthwiseConvolutionFunction, ReshapeFunction, PoolingLayerFunction, SoftmaxLayerFunction >::get_classifications(), AlexNetNetwork< ITensorType, TensorType, SubTensorType, Accessor, ActivationLayerFunction, ConvolutionLayerFunction, DirectConvolutionLayerFunction, FullyConnectedLayerFunction, NormalizationLayerFunction, PoolingLayerFunction, SoftmaxLayerFunction >::get_classifications(), arm_compute::test::index2coord(), arm_compute::index2coords(), arm_compute::intersect_valid_regions(), SubTensorInfo::num_dimensions(), TensorInfo::num_dimensions(), arm_compute::operator==(), arm_compute::permute(), Dimensions< size_t >::set_num_dimensions(), arm_compute::test::shape_to_valid_region(), arm_compute::test::shape_to_valid_region_gaussian_pyramid_half(), Window::use_tensor_dimensions(), and arm_compute::test::validation::validate().

123  {
124  return _num_dimensions;
125  }
Dimensions& operator= ( const Dimensions< T > &  )
default

Allow instances of this class to be copied.

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

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

Allow instances of this class to be moved.

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:328
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:45
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:328
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:45
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.

Referenced by arm_compute::test::validation::apply_2d_spatial_filter(), arm_compute::compute_strides(), arm_compute::test::validation::reference::depthwise_convolution(), arm_compute::test::validation::reference::dilate(), arm_compute::test::validation::reference::erode(), arm_compute::intersect_valid_regions(), arm_compute::permute(), arm_compute::test::validation::reference::remap(), TensorShape::set(), arm_compute::test::shape_to_valid_region(), arm_compute::test::shape_to_valid_region_gaussian_pyramid_half(), arm_compute::test::validation::tensor_elem_at(), arm_compute::test::validation::transpose(), and arm_compute::test::validation::validate().

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:328
fixed_point< T > max(fixed_point< T > x, fixed_point< T > y)
Definition: FixedPoint.h:902
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:45
void set_num_dimensions ( size_t  num_dimensions)
inline

Set number of dimensions.

Definition at line 128 of file Dimensions.h.

Referenced by NPYLoader::init_tensor().

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

Alias to access the size of the first dimension.

Definition at line 81 of file Dimensions.h.

Referenced by PPMAccessor::access_tensor(), arm_compute::test::validation::apply_2d_spatial_filter(), arm_compute::calculate_depth_concatenate_shape(), arm_compute::misc::shape_calculator::calculate_width_concatenate_shape(), arm_compute::test::validation::reference::channel_combine(), arm_compute::test::validation::compare_dimensions(), arm_compute::misc::shape_calculator::compute_winograd_input_transform_shape(), arm_compute::test::validation::reference::convert_fully_connected_weights(), arm_compute::test::create_multi_image(), arm_compute::test::validation::DATA_TEST_CASE(), arm_compute::test::validation::reference::depthwise_convolution(), arm_compute::test::validation::reference::dilate(), arm_compute::test::validation::reference::erode(), arm_compute::test::validation::reference::fast_corners(), AssetsLibrary::fill_borders_with_garbage(), arm_compute::test::generate_random_keypoints(), arm_compute::test::generate_random_rois(), LeNet5Network< TensorType, Accessor, ActivationLayerFunction, ConvolutionLayerFunction, FullyConnectedLayerFunction, PoolingLayerFunction, SoftmaxLayerFunction >::get_classifications(), MobileNetNetwork< TensorType, Accessor, ActivationLayerFunction, ConvolutionLayerFunction, DirectConvolutionLayerFunction, DepthwiseConvolutionLayerFunction, ReshapeFunction, PoolingLayerFunction >::get_classifications(), MobileNetV1Network< TensorType, Accessor, ActivationLayerFunction, BatchNormalizationLayerFunction, ConvolutionLayerFunction, DirectConvolutionLayerFunction, DepthwiseConvolutionFunction, ReshapeFunction, PoolingLayerFunction, SoftmaxLayerFunction >::get_classifications(), AlexNetNetwork< ITensorType, TensorType, SubTensorType, Accessor, ActivationLayerFunction, ConvolutionLayerFunction, DirectConvolutionLayerFunction, FullyConnectedLayerFunction, NormalizationLayerFunction, PoolingLayerFunction, SoftmaxLayerFunction >::get_classifications(), 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::scale(), arm_compute::setup_assembly_kernel(), arm_compute::test::shape_to_valid_region(), arm_compute::test::shape_to_valid_region_gaussian_pyramid_half(), arm_compute::test::validation::tensor_elem_at(), arm_compute::test::validation::reference::transpose(), arm_compute::test::validation::transpose(), arm_compute::test::validation::reference::warp_affine(), and arm_compute::test::validation::reference::warp_perspective().

82  {
83  return _id[0];
84  }

Field Documentation

constexpr size_t num_max_dimensions = MAX_DIMS
static

Number of dimensions the tensor has.

Definition at line 45 of file Dimensions.h.


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