24.02
|
Go to the documentation of this file.
25 #ifndef ACL_ARM_COMPUTE_CORE_WINDOW_INL
26 #define ACL_ARM_COMPUTE_CORE_WINDOW_INL
31 : _dims(), _is_broadcasted(utility::generate_array<bool,
Coordinates::num_max_dimensions, false>::value)
36 _is_broadcasted[i] =
src.is_broadcasted(i);
50 return _dims.at(dimension);
56 _dims[dimension] = dim;
63 _is_broadcasted[dimension] =
true;
69 return _is_broadcasted[dimension];
75 bool *has_collapsed)
const
79 bool is_collapsable =
true;
80 int collapsed_end = _dims[first].end();
82 for (
size_t d = first + 1; is_collapsable && (d < last); ++d)
85 is_collapsable = (_dims[d].start() == 0) && (full_window[d].start() == 0) && (_dims[d].
step() <= 1) &&
86 (full_window[d].
end() == _dims[d].end());
87 collapsed_end *= _dims[d].end();
92 collapsed._dims.at(first).set_end(collapsed_end);
93 for (
size_t d = first + 1; is_collapsable && (d < last); ++d)
99 if (has_collapsed !=
nullptr)
101 *has_collapsed = is_collapsable;
112 for (; n < start_dim; ++n)
114 shifted_window.
set(n, _dims[n]);
119 shifted_window.
set(n, _dims[n + shift_value]);
122 return shifted_window;
127 bool has_collapsed =
false;
136 Window broadcastWin(*
this);
173 const int scaled_step = d.
step() * scale_value;
174 const int scaled_start = d.
start() * scale_value;
175 const int scaled_diff = (d.
end() - d.
start()) * scale_value;
176 const int scaled_end = scaled_start +
ceil_to_multiple(scaled_diff, scaled_step);
184 _dims[dimension].set_step(
step);
200 return (_dims.at(dimension).end() - _dims.at(dimension).start()) / _dims.at(dimension).step();
214 int start = _dims[d].start();
215 int end = _dims[d].end();
216 const int step = _dims[d].step();
219 const int rem = num_it % total;
220 int work = num_it / total;
222 int it_start = work * id;
234 start += it_start *
step;
241 out.
set(d, _dims[d]);
248 template <
unsigned int window_dimension>
249 inline bool Window::slide_window_slice(
Window &
slice)
const
254 const int v =
slice._dims[n].start() + 1;
256 if (v < _dims[n].
end())
259 slice._dims[n] = Dimension(v, v + 1, 1);
262 for (
unsigned int lower = window_dimension; lower < n; ++lower)
264 slice._dims[lower] = Dimension(_dims[lower].start(), _dims[lower].start() + 1, 1);
274 template <
unsigned int window_dimension>
275 inline Window Window::first_slice_window()
const
279 std::copy_n(_dims.begin(), window_dimension,
slice._dims.begin());
284 slice._dims[n] = Dimension(_dims[n].start(), _dims[n].start() + 1, 1);
320 lhs._dims.swap(rhs._dims);
325 return (lhs._dims == rhs._dims) && (lhs._is_broadcasted == rhs._is_broadcasted);
329 #endif // ACL_ARM_COMPUTE_CORE_WINDOW_INL
constexpr int start() const
Return the start of the dimension.
SimpleTensor< float > src
void scale(size_t dimension, float scale_value)
Scale the values of a given dimension by the given scale_value.
constexpr int step() const
Return the step of the dimension.
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.
void use_tensor_dimensions(const TensorShape &shape, size_t first_dimension=Window::DimX)
Use the tensor's dimensions to fill the window dimensions.
constexpr size_t num_iterations(size_t dimension) const
Return the number of iterations needed to iterate through a given dimension.
void shift(size_t dimension, int shift_value)
Shift the values of a given dimension by the given shift_value.
Window shift_dimensions(unsigned int shift_value, unsigned int start_dim=0) const
Shift down all the dimensions of a window starting from the specified dimension.
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.
bool operator==(const Dimensions< T > &lhs, const Dimensions< T > &rhs)
Check that given dimensions are equal.
void set_dimension_step(size_t dimension, int step)
Set the step of a given dimension.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
constexpr Window()
Default constructor: create a window containing a single element.
Window collapse(const Window &full_window, size_t first, size_t last=Coordinates::num_max_dimensions) const
Collapse the dimensions between first and last.
friend void swap(Window &lhs, Window &rhs)
Friend function that swaps the contents of two windows.
TensorShape shape() const
Return the shape of the window in number of steps.
void validate() const
Will validate all the window's dimensions' values when asserts are enabled.
bool is_broadcasted(size_t dimension) const
Return whether a dimension has been broadcasted.
Window & operator=(const Window &rhs)
Copy assignment operator.
Describe one of the image's dimensions with a start, end and step.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
void set_broadcasted(size_t dimension)
Set the dimension as broadcasted dimension.
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.
constexpr const Dimension & operator[](size_t dimension) const
Read only access to a given dimension of the window.
Describe a multidimensional execution window.
void swap(Window &lhs, Window &rhs)
Copyright (c) 2017-2024 Arm Limited.
void end(TokenStream &in, bool &valid)
size_t num_iterations_total() const
Return the total number of iterations needed to iterate through the entire window.
Window broadcast_if_dimension_le_one(const TensorShape &shape) const
Don't advance in the dimension where shape is less equal to 1.
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.
constexpr int end() const
Return the end of the dimension.
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
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.