23.11
|
Go to the documentation of this file.
24 #ifndef ARM_COMPUTE_DIMENSIONS_H
25 #define ARM_COMPUTE_DIMENSIONS_H
52 template <
typename... Ts>
53 explicit Dimensions(Ts... dims) : _id{{
static_cast<T
>(dims)...}}, _num_dimensions{
sizeof...(dims)}
75 void set(
size_t dimension, T value,
bool increase_dim_unit =
true)
78 _id[dimension] = value;
80 if (increase_dim_unit || value != 1)
82 _num_dimensions = std::max(_num_dimensions, dimension + 1);
110 if ((std::numeric_limits<T>::max() - _id[dim]) >=
step)
126 return _id[dimension];
139 return _id[dimension];
144 return _num_dimensions;
158 void collapse(
const size_t n,
const size_t first = 0)
162 const size_t last = std::min(_num_dimensions, first + n);
164 if (last > (first + 1))
167 _id[first] =
std::accumulate(&_id[first], &_id[last], 1, std::multiplies<T>());
169 std::copy(&_id[last], &_id[_num_dimensions], &_id[first + 1]);
171 const size_t old_num_dimensions = _num_dimensions;
172 _num_dimensions -= last - first - 1;
174 std::fill(&_id[_num_dimensions], &_id[old_num_dimensions], 0);
198 if (idx >= _num_dimensions)
203 std::copy(_id.begin() + idx + 1, _id.end(), _id.begin() + idx);
207 std::fill(_id.begin() + _num_dimensions, _id.end(), 0);
214 typename std::array<T, num_max_dimensions>::iterator
begin()
222 typename std::array<T, num_max_dimensions>::const_iterator
begin()
const
230 typename std::array<T, num_max_dimensions>::const_iterator
cbegin()
const
238 typename std::array<T, num_max_dimensions>::iterator
end()
246 typename std::array<T, num_max_dimensions>::const_iterator
end()
const
254 typename std::array<T, num_max_dimensions>::const_iterator
cend()
const
263 std::array<T, num_max_dimensions> _id;
264 size_t _num_dimensions{0};
274 template <
typename T>
286 template <
typename T>
289 return !(lhs == rhs);
void remove(size_t idx)
Remove dimension of a given index.
void set(size_t dimension, T value, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
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.
T z() const
Alias to access the size of the third dimension.
bool operator==(const Dimensions< T > &lhs, const Dimensions< T > &rhs)
Check that given dimensions are equal.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
constexpr size_t MAX_DIMS
Constant value used to indicate maximum dimensions of a Window, TensorShape and Coordinates.
void collapse(const size_t n, const size_t first=0)
Collapse dimensions.
library fill(src, distribution, 0)
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.
T x() const
Alias to access the size of the first dimension.
SimpleTensor< T > copy(const SimpleTensor< T > &src, const TensorShape &output_shape)
SimpleTensor< T2 > accumulate(const SimpleTensor< T1 > &src, DataType output_data_type)
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.
void collapse_from(size_t start)
Collapse dimensions starting from a given point.
std::array< T, num_max_dimensions >::iterator begin()
Returns a read/write 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.
Dimensions(Ts... dims)
Constructor to initialize the tensor shape.
Copyright (c) 2017-2023 Arm Limited.
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.
void increment(size_t dim, T step=1)
Increments the given dimension by a step size, avoiding overflows.
std::array< T, num_max_dimensions >::iterator end()
Returns a read/write iterator that points one past the last element in the dimension array.
Dimensions with dimensionality.
T y() const
Alias to access the size of the second dimension.
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
bool operator!=(const Dimensions< T > &lhs, const Dimensions< T > &rhs)
Check that given dimensions are not equal.
Dimensions & operator=(const Dimensions &)=default
Allow instances of this class to be copied.