41 return input_valid_region;
58 anchor.
set(0, std::max<int>(window.
x().
start() * _scale_x, anchor[0] + border_size.
left) + _x);
61 anchor.
set(1, std::max<int>(window.
y().
start() * _scale_y, anchor[1] + border_size.
top) + _y);
72 shape.set(0, std::min<int>(old_anchor[0] +
shape[0] - border_size.
right, (window.
x().
end() - window.
x().
step()) * _scale_x + _width) - anchor[0]);
75 shape.set(1, std::min<int>(old_anchor[1] +
shape[1] - border_size.
bottom, (window.
y().
end() - window.
y().
step()) * _scale_y + _height) - anchor[1]);
82 anchor.
set(d, std::max(window[d].start(), input_valid_region.
anchor[d]));
83 shape.set(d, std::min<int>(window[d].
end(), input_valid_region.
shape[d]) - anchor[d]);
86 return input_valid_region;
119 bool window_modified =
false;
123 const int min_y = window.
y().
start() * _scale_y + _y;
124 const int max_y = (window.
y().
end() - window.
y().
step()) * _scale_y + _y + _height;
130 const int front_pad_y_available = -static_cast<int>(offset_first_element / strides[1]);
132 if(min_y < front_pad_y_available)
135 int start =
adjust_up(min_y, front_pad_y_available, window.
y().
step() * _scale_y) - _y;
136 start = std::min<int>(start / _scale_y, window.
y().
end());
139 window_modified =
true;
143 front_pad_y = std::max(0, static_cast<int>(std::floor(-window.
y().
start() * _scale_y)) - _y);
147 if(max_y > static_cast<int>(
shape[1]))
152 const int tail_pad_y_available = (stride_z / strides[1]) -
shape[1] - front_pad_y;
154 if(static_cast<int>(
shape[1]) + tail_pad_y_available < max_y)
158 end = std::max<int>(window.
y().
start(),
end / _scale_y);
161 window_modified =
true;
167 const int min_x = window.
x().
start() * _scale_x + _x;
168 const int max_x = (window.
x().
end() - window.
x().
step()) * _scale_x + _x + _width;
175 const int front_pad_x_available = -std::min<int>(static_cast<int>(offset_first_element) - front_pad_y * strides[1], stride_y -
shape[0] * strides[0]) / static_cast<int>(strides[0]);
177 if(min_x < front_pad_x_available)
180 int start =
adjust_up(min_x, front_pad_x_available, window.
x().
step() * _scale_x) - _x;
181 start = std::min<int>(start / _scale_x, window.
x().
end());
184 window_modified =
true;
188 front_pad_x = std::max(0, static_cast<int>(std::floor(-window.
x().
start() * _scale_x)) - _x);
192 if(max_x > static_cast<int>(
shape[0]))
194 const int tail_pad_x_available = (stride_y / strides[0]) -
shape[0] - front_pad_x;
196 if(static_cast<int>(
shape[0]) + tail_pad_x_available < max_x)
200 end = std::max<int>(window.
x().
start(),
end / _scale_x);
203 window_modified =
true;
209 return window_modified;
228 const int min_x = window.
x().
start() * _scale_x + _x;
229 const int max_x = (window.
x().
end() - window.
x().
step()) * _scale_x + _x + _width;
230 const int min_y = window.
y().
start() * _scale_y + _y;
231 const int max_y = (window.
y().
end() - window.
y().
step()) * _scale_y + _y + _height;
236 padding.
left = std::max(0, -min_x);
237 padding.
right = std::max<int>(0, max_x -
shape[0]);
238 padding.
top = std::max(0, -min_y);
239 padding.
bottom = std::max<int>(0, max_y -
shape[1]);
void set(size_t dimension, T value, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
unsigned int top
top of the border
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
TensorShape shape
Shape of the valid region.
Container for 2D border size.
constexpr int step() const
Return the step of the dimension.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
ValidRegion compute_valid_region(const Window &window, const ValidRegion &input_valid_region) const
Compute the valid region based on access pattern, valid region of the inputs and border mode.
Describe one of the image's dimensions with a start, end and step.
unsigned int bottom
bottom of the border
void validate() const
Will validate all the window's dimensions' values when asserts are enabled.
Copyright (c) 2017-2021 Arm Limited.
virtual void set_valid_region(const ValidRegion &valid_region)=0
Set the valid region of the tensor.
virtual bool is_resizable() const =0
Flag indicating whether the size of the tensor can be changed.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
int adjust_up(int required, int available, int step)
Increase required in steps of step until it's greater than available.
bool update_window_if_needed(Window &window) const override
Shrink the window if padding is not large enough.
void end(TokenStream &in, bool &valid)
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
virtual PaddingSize padding() const =0
Padding of tensor.
unsigned int left
left of the border
unsigned int right
right of the border
Strides of an item in bytes.
virtual size_t offset_first_element_in_bytes() const =0
The offset from the beginning of the memory allocation to the first element of the tensor.
bool update_padding_if_needed(const Window &window) override
Increase the padding to be large enough for the window.
virtual size_t total_size() const =0
Returns the total size of the tensor in bytes.
constexpr const Dimension & y() const
Alias to access the second dimension of the window.
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.
Container for valid region of a window.
constexpr int end() const
Return the end of the dimension.
int adjust_down(int required, int available, int step)
Decrease required in steps of step until it's less than available.
constexpr int start() const
Return the start of the dimension.
virtual bool extend_padding(const PaddingSize &padding)=0
Update the offset to the first element, the strides and the total size.
Describe a multidimensional execution window.
Coordinates anchor
Anchor for the start of the valid region.
void set_valid_region(const Window &window, const ValidRegion &input_valid_region, bool border_undefined=false, const BorderSize &border_size=BorderSize(0))
Set the valid region based on access pattern, valid region of the inputs and border mode.
constexpr const Dimension & x() const
Alias to access the first dimension of the window.