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()
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;
158 int num_elements =
shape.total_size();
165 for(
int d =
shape.num_dimensions() - 1; d >= 0; --d)
167 num_elements /=
shape[d];
168 coord.set(d, index / num_elements);
169 index %= num_elements;
177 int num_elements =
shape.total_size();
186 index += coord[d] * stride;
202 switch(data_layout_dimension)
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.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
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.
const DataLayout data_layout
Store the tensor's metadata.
#define ARM_COMPUTE_ERROR_ON_WINDOW_DIMENSIONS_GTE(w, md)
Interface for CPU tensor.
Copyright (c) 2017-2021 Arm Limited.
#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.
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.
DataLayoutDimension get_index_data_layout_dimension(const DataLayout data_layout, const size_t index)
Get the DataLayoutDimension of a given index and layout.
constexpr Iterator()
Default constructor to create an empty iterator.
Num samples, channels, height, width.
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)
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
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.
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
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.