24 #ifndef ARM_COMPUTE_DIMENSIONS_H 25 #define ARM_COMPUTE_DIMENSIONS_H 51 template <
typename... Ts>
53 : _id{ { static_cast<T>(dims)... } }, _num_dimensions{
sizeof...(dims) }
74 void set(
size_t dimension, T value)
77 _id[dimension] = value;
78 _num_dimensions = std::max(_num_dimensions, dimension + 1);
106 return _id[dimension];
119 return _id[dimension];
124 return _num_dimensions;
138 void collapse(
const size_t n,
const size_t first = 0)
142 const size_t last = std::min(_num_dimensions, first + n);
144 if(last > (first + 1))
147 _id[first] =
std::accumulate(&_id[first], &_id[last], 1, std::multiplies<T>());
149 std::copy(&_id[last], &_id[_num_dimensions], &_id[first + 1]);
151 const size_t old_num_dimensions = _num_dimensions;
152 _num_dimensions -= last - first - 1;
154 std::fill(&_id[_num_dimensions], &_id[old_num_dimensions], 0);
178 if(idx >= _num_dimensions)
183 std::copy(_id.begin() + idx + 1, _id.end(), _id.begin() + idx);
187 std::fill(_id.begin() + _num_dimensions, _id.end(), 0);
194 typename std::array<T, num_max_dimensions>::iterator
begin()
202 typename std::array<T, num_max_dimensions>::const_iterator
begin()
const 210 typename std::array<T, num_max_dimensions>::const_iterator
cbegin()
const 218 typename std::array<T, num_max_dimensions>::iterator
end()
226 typename std::array<T, num_max_dimensions>::const_iterator
end()
const 234 typename std::array<T, num_max_dimensions>::const_iterator
cend()
const 243 std::array<T, num_max_dimensions> _id;
244 size_t _num_dimensions{ 0 };
254 template <
typename T>
266 template <
typename T>
269 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.
void remove(size_t idx)
Remove dimension of a given index.
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 set(size_t dimension, T value)
Accessor to set the value of one of the dimensions.
void collapse(const size_t n, const size_t first=0)
Collapse dimensions.
Copyright (c) 2017-2020 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.
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.