| 106 | } |
| 107 | |
| 108 | bool AccessWindowRectangle::update_window_if_needed(Window &window) const |
| 109 | { |
| 110 | // Only update the window size if we can't use padding |
| 111 | if (_info == nullptr || _info->is_resizable()) |
| 112 | { |
| 113 | return false; |
| 114 | } |
| 115 | |
| 116 | PaddingSize needed = get_needed_padding(window); |
| 117 | PaddingSize available = _info->padding(); |
| 118 | |
| 119 | if (needed.top <= available.top && needed.right <= available.right && needed.bottom <= available.bottom && |
| 120 | needed.left <= available.left) |
| 121 | { |
| 122 | return false; |
| 123 | } |
| 124 | |
| 125 | const TensorShape &shape = _info->tensor_shape(); |
| 126 | const Strides &strides = _info->strides_in_bytes(); |
| 127 | const size_t offset_first_element = _info->offset_first_element_in_bytes(); |
| 128 | |
| 129 | bool window_modified = false; |
| 130 | |
| 131 | int front_pad_y = 0; |
| 132 | |
| 133 | const int min_y = window.y().start() * _scale_y + _y; |
| 134 | const int max_y = (window.y().end() - window.y().step()) * _scale_y + _y + _height; |
| 135 | |
| 136 | // Adjust window start for Y dimension |
| 137 | if (min_y < 0) |
| 138 | { |
| 139 | // Calculate rows available above the tensor |
| 140 | const int front_pad_y_available = -static_cast<int>(offset_first_element / strides[1]); |
| 141 | |
| 142 | if (min_y < front_pad_y_available) |
| 143 | { |
| 144 | // Not enough padding available, need to shrink the window |
| 145 | int start = adjust_up(min_y, front_pad_y_available, window.y().step() * _scale_y) - _y; |
| 146 | start = std::min<int>(start / _scale_y, window.y().end()); |
| 147 | |
| 148 | window.set(1, Window::Dimension(start, window.y().end(), window.y().step())); |
| 149 | window_modified = true; |
| 150 | } |
| 151 | |
| 152 | // Update front padding with reconstructed value |
| 153 | front_pad_y = std::max(0, static_cast<int>(std::floor(-window.y().start() * _scale_y)) - _y); |
| 154 | } |
| 155 | |
| 156 | // Adjust window end for Y dimension |
| 157 | if (max_y > static_cast<int>(shape[1])) |
| 158 | { |
| 159 | const int stride_z = _info->num_dimensions() > 2 ? strides[2] : _info->total_size(); |
| 160 | |
| 161 | // Calculate rows available below the tensor |
| 162 | const int tail_pad_y_available = (stride_z / strides[1]) - shape[1] - front_pad_y; |
| 163 | |
| 164 | if (static_cast<int>(shape[1]) + tail_pad_y_available < max_y) |
| 165 | { |
no test coverage detected