24 #ifndef ARM_COMPUTE_DIMENSIONS_H 25 #define ARM_COMPUTE_DIMENSIONS_H 52 template <
typename... Ts>
54 : _id{ {
static_cast<T
>(dims)... } }, _num_dimensions{
sizeof...(dims) }
76 void set(
size_t dimension, T value,
bool increase_dim_unit =
true)
79 _id[dimension] = value;
81 if(increase_dim_unit || value != 1)
83 _num_dimensions = std::max(_num_dimensions, dimension + 1);
111 if((std::numeric_limits<T>::max() - _id[dim]) >=
step)
127 return _id[dimension];
140 return _id[dimension];
145 return _num_dimensions;
159 void collapse(
const size_t n,
const size_t first = 0)
163 const size_t last = std::min(_num_dimensions, first + n);
165 if(last > (first + 1))
168 _id[first] =
std::accumulate(&_id[first], &_id[last], 1, std::multiplies<T>());
170 std::copy(&_id[last], &_id[_num_dimensions], &_id[first + 1]);
172 const size_t old_num_dimensions = _num_dimensions;
173 _num_dimensions -= last - first - 1;
175 std::fill(&_id[_num_dimensions], &_id[old_num_dimensions], 0);
196 void remove(
size_t idx)
199 if(idx >= _num_dimensions)
204 std::copy(_id.begin() + idx + 1, _id.end(), _id.begin() + idx);
208 std::fill(_id.begin() + _num_dimensions, _id.end(), 0);
215 typename std::array<T, num_max_dimensions>::iterator
begin()
223 typename std::array<T, num_max_dimensions>::const_iterator
begin()
const 231 typename std::array<T, num_max_dimensions>::const_iterator
cbegin()
const 239 typename std::array<T, num_max_dimensions>::iterator
end()
247 typename std::array<T, num_max_dimensions>::const_iterator
end()
const 255 typename std::array<T, num_max_dimensions>::const_iterator
cend()
const 264 std::array<T, num_max_dimensions> _id;
265 size_t _num_dimensions{ 0 };
275 template <
typename T>
287 template <
typename T>
290 return !(lhs == rhs);
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...
T & operator[](size_t dimension)
Generic accessor to get the size of any dimension.
Dimensions & operator=(const Dimensions &)=default
Allow instances of this class to be copied.
bool operator!=(const Dimensions< T > &lhs, const Dimensions< T > &rhs)
Check that given dimensions are not equal.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
bool operator==(const Dimensions< T > &lhs, const Dimensions< T > &rhs)
Check that given dimensions are equal.
SimpleTensor< T > copy(const SimpleTensor< T > &src, const TensorShape &output_shape)
void collapse(const size_t n, const size_t first=0)
Collapse dimensions.
Copyright (c) 2017-2021 Arm Limited.
constexpr size_t MAX_DIMS
Constant value used to indicate maximum dimensions of a Window, TensorShape and Coordinates.
T x() const
Alias to access the size of the first dimension.
void collapse_from(size_t start)
Collapse dimensions starting from a given point.
library fill(src, distribution, 0)
T z() const
Alias to access the size of the third dimension.
Dimensions with dimensionality.
std::array< T, num_max_dimensions >::iterator begin()
Returns a read/write iterator that points to the first element in the dimension array.
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...
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...
const T & operator[](size_t dimension) const
Generic accessor to get the size of any dimension.
std::array< T, num_max_dimensions >::iterator end()
Returns a read/write iterator that points one past the last element in the dimension array...
void increment(size_t dim, T step=1)
Increments the given dimension by a step size, avoiding overflows.
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
Dimensions(Ts... dims)
Constructor to initialize the tensor shape.
__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.
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...
void set_num_dimensions(size_t num_dimensions)
Set number of dimensions.
T y() const
Alias to access the size of the second dimension.
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.