34 bool border_undefined,
39 return input_valid_region;
47 if (!border_undefined)
59 if (_info->dimension(0) > 1)
61 anchor.
set(0, std::max<int>(window.
y().
start() * _scale_x, anchor[1] + border_size.
top) + _x);
63 anchor.
set(1, std::max<int>(window.
x().
start() * _scale_y, anchor[0] + border_size.
left) + _y);
75 if (_info->dimension(0) > 1)
77 shape.set(0, std::min<int>((old_anchor[1] + old_shape[0]) * _scale_x - border_size.
right,
78 (window.
y().
end() - window.
y().
step()) * _scale_x + _width) -
81 shape.set(1, std::min<int>((old_anchor[0] + old_shape[1]) * _scale_y - border_size.
bottom,
82 (window.
x().
end() - window.
x().
step()) * _scale_y + _height) -
87 for (
size_t d = 2; d < _info->num_dimensions(); ++d)
89 anchor.
set(d, std::max(window[d].start(), input_valid_region.
anchor[d]));
90 shape.set(d, std::min<int>(window[d].
end(), input_valid_region.
shape[d]) - anchor[d]);
93 return input_valid_region;
99 if (_info ==
nullptr || _info->is_resizable())
105 const Strides &strides = _info->strides_in_bytes();
106 const size_t offset_first_element = _info->offset_first_element_in_bytes();
108 bool window_modified =
false;
113 const int min_y = window.
x().
start() * _scale_y + _y;
114 const int max_y = window.
x().
end() * _scale_y + _y;
120 const int front_pad_y_available = -offset_first_element / strides[1];
122 if (min_y < front_pad_y_available)
125 const int start =
adjust_up(min_y, front_pad_y_available, window.
x().
step() * _scale_y) - _y;
128 window_modified =
true;
132 front_pad_y = std::max(0,
static_cast<int>(std::floor(-window.
x().
start() * _scale_y)) - _y);
136 if (max_y >
static_cast<int>(
shape[1]))
138 const int stride_z = _info->num_dimensions() > 2 ? strides[2] : _info->total_size();
141 const int tail_pad_y_available = (stride_z / strides[1]) -
shape[1] - front_pad_y;
143 if (
static_cast<int>(
shape[1]) + tail_pad_y_available < max_y)
147 window.
x().
step() * _scale_y - _y - _height;
149 window_modified =
true;
156 const int min_x = window.
y().
start() * _scale_x + _x;
157 const int max_x = window.
y().
end() * _scale_x + _x;
159 const int stride_y = _info->num_dimensions() > 1 ? strides[1] : _info->total_size();
164 const int front_pad_x_available =
165 -std::min<int>(
static_cast<int>(offset_first_element) - front_pad_y * strides[1],
166 stride_y -
shape[0] * strides[0]) /
167 static_cast<int>(strides[0]);
169 if (min_x < front_pad_x_available)
172 const int start =
adjust_up(min_x, front_pad_x_available, window.
y().
step() * _scale_x) - _x;
174 window_modified =
true;
178 front_pad_x = std::max(0,
static_cast<int>(std::floor(-window.
y().
start() * _scale_x)) - _x);
182 if (max_x >
static_cast<int>(
shape[0]))
184 const int tail_pad_x_available = (stride_y / strides[0]) -
shape[0] - front_pad_x;
186 if (
static_cast<int>(
shape[0]) + tail_pad_x_available < max_x)
190 window.
y().
step() * _scale_x - _x - _width;
192 window_modified =
true;
198 return window_modified;
204 if (_info ==
nullptr || !_info->is_resizable())
212 const int min_x = window.
y().
start() * _scale_x + _x;
213 const int max_x = (window.
y().
end() - window.
y().
step()) * _scale_x + _x + _width;
214 const int min_y = window.
x().
start() * _scale_y + _y;
215 const int max_y = (window.
x().
end() - window.
x().
step()) * _scale_y + _y + _height;
220 padding.
left = std::max(0, -min_x);
221 padding.
right = std::max<int>(0, max_x -
shape[0]);
222 padding.
top = std::max(0, -min_y);
223 padding.
bottom = std::max<int>(0, max_y -
shape[1]);
226 return _info->extend_padding(padding);