27 : _dims(), _is_broadcasted(utility::generate_array<bool,
Coordinates::num_max_dimensions, false>::value)
46 return _dims.at(dimension);
52 _dims[dimension] = dim;
59 _is_broadcasted[dimension] =
true;
65 return _is_broadcasted[dimension];
69 const size_t last,
bool *has_collapsed)
const 73 bool is_collapsable =
true;
74 int collapsed_end = _dims[first].end();
76 for(
size_t d = first + 1; is_collapsable && (d < last); ++d)
79 is_collapsable = (_dims[d].start() == 0) && (full_window[d].
start() == 0) && (_dims[d].
step() <= 1)
80 && (full_window[d].
end() == _dims[d].end());
81 collapsed_end *= _dims[d].end();
86 collapsed._dims.at(first).set_end(collapsed_end);
87 for(
size_t d = first + 1; is_collapsable && (d < last); ++d)
93 if(has_collapsed !=
nullptr)
95 *has_collapsed = is_collapsable;
106 shifted_window.
set(n, _dims[n + shift_value]);
108 return shifted_window;
113 bool has_collapsed =
false;
122 Window broadcastWin(*
this);
159 const int scaled_step = d.
step() * scale_value;
160 const int scaled_start = d.
start() * scale_value;
161 const int scaled_diff = (d.
end() - d.
start()) * scale_value;
162 const int scaled_end = scaled_start +
ceil_to_multiple(scaled_diff, scaled_step);
170 _dims[dimension].set_step(step);
186 return (_dims.at(dimension).end() - _dims.at(dimension).start()) / _dims.at(dimension).step();
200 int start = _dims[d].start();
201 int end = _dims[d].end();
202 const int step = _dims[d].step();
205 const int rem = num_it % total;
206 int work = num_it / total;
208 int it_start = work * id;
220 start += it_start *
step;
221 end = std::min(end, start + work * step);
227 out.
set(d, _dims[d]);
234 template <
unsigned int window_dimension>
235 inline bool Window::slide_window_slice(
Window &
slice)
const 240 const int v = slice._dims[n].start() + 1;
242 if(v < _dims[n].
end())
248 for(
unsigned int lower = window_dimension; lower < n; ++lower)
260 template <
unsigned int window_dimension>
261 inline Window Window::first_slice_window()
const 265 std::copy_n(_dims.begin(), window_dimension, slice._dims.begin());
278 for(
unsigned int n = first_dimension; n < shape.
num_dimensions(); ++n)
306 lhs._dims.swap(rhs._dims);
void scale(size_t dimension, float scale_value)
Scale the values of a given dimension by the given scale_value.
void shift(size_t dimension, int shift_value)
Shift the values of a given dimension by the given shift_value.
constexpr int step() const
Return the step of the dimension.
friend void swap(Window &lhs, Window &rhs)
Friend function that swaps the contents of two windows.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Window split_window(size_t dimension, size_t id, size_t total) const
Split a window into a set of sub windows along a given dimension.
Describe one of the image's dimensions with a start, end and step.
void validate() const
Will validate all the window's dimensions' values when asserts are enabled.
constexpr size_t num_iterations(size_t dimension) const
Return the number of iterations needed to iterate through a given dimension.
void use_tensor_dimensions(const TensorShape &shape, size_t first_dimension=Window::DimX)
Use the tensor's dimensions to fill the window dimensions.
SimpleTensor< float > src
Copyright (c) 2017-2021 Arm Limited.
Window collapse(const Window &full_window, size_t first, size_t last=Coordinates::num_max_dimensions) const
Collapse the dimensions between first and last.
Window collapse_if_possible(const Window &full_window, size_t first, size_t last, bool *has_collapsed=nullptr) const
Collapse the dimensions between first and last if possible.
auto ceil_to_multiple(S value, T divisor) -> decltype(((value+divisor - 1)/divisor) *divisor)
Computes the smallest number larger or equal to value that is a multiple of divisor.
Window & operator=(const Window &rhs)
Copy assignment operator.
constexpr const Dimension & operator[](size_t dimension) const
Read only access to a given dimension of the window.
constexpr Window()
Default constructor: create a window containing a single element.
void end(TokenStream &in, bool &valid)
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Window broadcast_if_dimension_le_one(const TensorShape &shape) const
Don't advance in the dimension where shape is less equal to 1.
bool is_broadcasted(size_t dimension) const
Return whether a dimension has been broadcasted.
void set_dimension_step(size_t dimension, int step)
Set the step of a given dimension.
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
TensorShape shape() const
Return the shape of the window in number of steps.
constexpr int end() const
Return the end of the dimension.
void adjust(size_t dimension, int adjust_value, bool is_at_start)
Adjust the start or end of a given dimension by the given value.
void set_broadcasted(size_t dimension)
Set the dimension as broadcasted dimension.
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
constexpr int start() const
Return the start of the dimension.
size_t num_iterations_total() const
Return the total number of iterations needed to iterate through the entire window.
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.
Window shift_dimensions(unsigned int shift_value) const
Shift down all the dimensions of a window.
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)