36 return input_valid_region;
56 if(_info->dimension(0) > 1)
58 anchor.
set(0, std::max<int>(window.
y().
start() * _scale_x, anchor[1] + border_size.
top) + _x);
60 anchor.
set(1, std::max<int>(window.
x().
start() * _scale_y, anchor[0] + border_size.
left) + _y);
72 if(_info->dimension(0) > 1)
74 shape.
set(0, std::min<int>((old_anchor[1] + old_shape[0]) * _scale_x - border_size.
right, (window.
y().
end() - window.
y().
step()) * _scale_x + _width) - anchor[0]);
76 shape.
set(1, std::min<int>((old_anchor[0] + old_shape[1]) * _scale_y - border_size.
bottom, (window.
x().
end() - window.
x().
step()) * _scale_y + _height) - anchor[1]);
80 for(
size_t d = 2; d < _info->num_dimensions(); ++d)
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;
92 if(_info ==
nullptr || _info->is_resizable())
98 const Strides &strides = _info->strides_in_bytes();
99 const size_t offset_first_element = _info->offset_first_element_in_bytes();
101 bool window_modified =
false;
106 const int min_y = window.
x().
start() * _scale_y + _y;
107 const int max_y = window.
x().
end() * _scale_y + _y;
113 const int front_pad_y_available = -offset_first_element / strides[1];
115 if(min_y < front_pad_y_available)
118 const int start =
adjust_up(min_y, front_pad_y_available, window.
x().
step() * _scale_y) - _y;
121 window_modified =
true;
125 front_pad_y = std::max(0, static_cast<int>(std::floor(-window.
x().
start() * _scale_y)) - _y);
129 if(max_y > static_cast<int>(shape[1]))
131 const int stride_z = _info->num_dimensions() > 2 ? strides[2] : _info->total_size();
134 const int tail_pad_y_available = (stride_z / strides[1]) - shape[1] - front_pad_y;
136 if(static_cast<int>(shape[1]) + tail_pad_y_available < max_y)
139 const int end =
adjust_down(max_y, shape[1] + tail_pad_y_available, window.
x().
step() * _scale_y) + window.
x().
step() * _scale_y - _y - _height;
141 window_modified =
true;
148 const int min_x = window.
y().
start() * _scale_x + _x;
149 const int max_x = window.
y().
end() * _scale_x + _x;
151 const int stride_y = _info->num_dimensions() > 1 ? strides[1] : _info->total_size();
156 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]);
158 if(min_x < front_pad_x_available)
161 const int start =
adjust_up(min_x, front_pad_x_available, window.
y().
step() * _scale_x) - _x;
163 window_modified =
true;
167 front_pad_x = std::max(0, static_cast<int>(std::floor(-window.
y().
start() * _scale_x)) - _x);
171 if(max_x > static_cast<int>(shape[0]))
173 const int tail_pad_x_available = (stride_y / strides[0]) - shape[0] - front_pad_x;
175 if(static_cast<int>(shape[0]) + tail_pad_x_available < max_x)
178 const int end =
adjust_down(max_x, shape[0] + tail_pad_x_available, window.
y().
step() * _scale_x) + window.
y().
step() * _scale_x - _x - _width;
180 window_modified =
true;
186 return window_modified;
192 if(_info ==
nullptr || !_info->is_resizable())
200 const int min_x = window.
y().
start() * _scale_x + _x;
201 const int max_x = (window.
y().
end() - window.
y().
step()) * _scale_x + _x + _width;
202 const int min_y = window.
x().
start() * _scale_y + _y;
203 const int max_y = (window.
x().
end() - window.
x().
step()) * _scale_y + _y + _height;
208 padding.
left = std::max(0, -min_x);
209 padding.
right = std::max<int>(0, max_x - shape[0]);
210 padding.
top = std::max(0, -min_y);
211 padding.
bottom = std::max<int>(0, max_y - shape[1]);
214 return _info->extend_padding(padding);
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
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.
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.
ValidRegion compute_valid_region(const Window &window, ValidRegion input_valid_region, bool border_undefined, BorderSize border_size) const override
Compute the valid region based on access pattern and valid region of the inputs.
Copyright (c) 2017-2021 Arm Limited.
int adjust_up(int required, int available, int step)
Increase required in steps of step until it's greater than available.
void end(TokenStream &in, bool &valid)
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
unsigned int left
left of the border
unsigned int right
right of the border
Strides of an item in bytes.
constexpr const Dimension & y() const
Alias to access the second dimension of the window.
bool update_window_if_needed(Window &window) const override
Shrink the window if padding is not large enough.
bool update_padding_if_needed(const Window &window) override
Increase the padding to be large enough for the window.
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.
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.
Coordinates anchor
Anchor for the start of the valid region.
constexpr const Dimension & x() const
Alias to access the first dimension of the window.