31 template <
size_t dimension>
32 struct IncrementIterators
34 template <
typename T,
typename... Ts>
35 static void unroll(T &&it, Ts &&... iterators)
37 auto increment = [](T && it)
39 it.increment(dimension);
41 utility::for_each(increment, std::forward<T>(it), std::forward<Ts>(iterators)...);
50 struct ForEachDimension
52 template <
typename L,
typename... Ts>
53 static void unroll(
const Window &
w, Coordinates &
id, L &&lambda_function, Ts &&... iterators)
55 const auto &d = w[dim - 1];
57 for(
auto v = d.start(); v < d.end(); v += d.step(), IncrementIterators < dim - 1 >::unroll(iterators...))
60 ForEachDimension < dim - 1 >::unroll(w,
id, lambda_function, iterators...);
66 struct ForEachDimension<0>
68 template <
typename L,
typename... Ts>
69 static void unroll(
const Window &w, Coordinates &
id, L &&lambda_function, Ts &&... iterators)
76 template <
typename L,
typename... Ts>
87 ForEachDimension<Coordinates::num_max_dimensions>::unroll(w,
id, std::forward<L>(lambda_function), std::forward<Ts>(iterators)...);
91 : _ptr(nullptr), _dims()
102 const Strides &strides = info->strides_in_bytes();
104 _ptr = tensor->
buffer() + info->offset_first_element_in_bytes();
107 for(
unsigned int n = 0;
n < info->num_dimensions(); ++
n)
109 _dims[
n]._stride = win[
n].step() * strides[
n];
110 std::get<0>(_dims)._dim_start += static_cast<size_t>(strides[
n]) * win[
n].start();
116 _dims[
n]._dim_start = std::get<0>(_dims)._dim_start;
126 _dims[dimension]._dim_start += _dims[dimension]._stride;
128 for(
unsigned int n = 0;
n < dimension; ++
n)
130 _dims[
n]._dim_start = _dims[dimension]._dim_start;
136 return _dims.at(0)._dim_start;
141 return _ptr + _dims.at(0)._dim_start;
148 _dims[dimension]._dim_start = _dims[dimension + 1]._dim_start;
150 for(
unsigned int n = 0;
n < dimension; ++
n)
152 _dims[
n]._dim_start = _dims[dimension]._dim_start;
167 num_elements /= shape[d];
168 coord.
set(d, index / num_elements);
169 index %= num_elements;
186 index += coord[d] * stride;
197 const auto &it = std::find(dims.cbegin(), dims.cend(), data_layout_dimension);
199 return it - dims.cbegin();
Coordinates index2coords(const TensorShape &shape, int index)
Convert a linear index into n-dimensional coordinates.
void increment(size_t dimension)
Increment the iterator along the specified dimension of the step value associated to the dimension...
DataLayoutDimension
[DataLayout enum definition]
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Store the tensor's metadata.
#define ARM_COMPUTE_ERROR_ON_WINDOW_DIMENSIONS_GTE(w, md)
void validate() const
Will validate all the window's dimensions' values when asserts are enabled.
Interface for CPU tensor.
Copyright (c) 2017-2022 Arm Limited.
const std::map< DataLayout, std::vector< DataLayoutDimension > > & get_layout_map()
Returns a static map used to find an index or dimension based on a data layout.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
virtual uint8_t * buffer() const =0
Interface to be implemented by the child class to return a pointer to CPU memory. ...
size_t total_size() const
Collapses all dimensions to a single linear total size.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
int coords2index(const TensorShape &shape, const Coordinates &coord)
Convert n-dimensional coordinates into a linear index.
constexpr uint8_t * ptr() const
Return a pointer to the current pixel.
constexpr Iterator()
Default constructor to create an empty iterator.
void for_each(F &&)
Base case of for_each.
Strides of an item in bytes.
void reset(size_t dimension)
Move the iterator back to the beginning of the specified dimension.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
size_t get_data_layout_dimension_index(const DataLayout &data_layout, const DataLayoutDimension &data_layout_dimension)
Get the index of the given dimension.
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
DataLayoutDimension get_index_data_layout_dimension(const DataLayout &data_layout, const size_t index)
Get the DataLayoutDimension of a given index and layout.
void execute_window_loop(const Window &w, L &&lambda_function, Ts &&... iterators)
Iterate through the passed window, automatically adjusting the iterators and calling the lambda_funct...
constexpr size_t offset() const
Return the offset in bytes from the first element to the current position of the iterator.
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Iterator updated by execute_window_loop for each window element.
DataLayout
[DataLayout enum definition]
Describe a multidimensional execution window.
TensorShape & set(size_t dimension, size_t value, bool apply_dim_correction=true, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.