| 94 | } |
| 95 | |
| 96 | bool AccessWindowTranspose::update_window_if_needed(Window &window) const |
| 97 | { |
| 98 | // Only update the window size if we can't use padding |
| 99 | if (_info == nullptr || _info->is_resizable()) |
| 100 | { |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | const TensorShape &shape = _info->tensor_shape(); |
| 105 | const Strides &strides = _info->strides_in_bytes(); |
| 106 | const size_t offset_first_element = _info->offset_first_element_in_bytes(); |
| 107 | |
| 108 | bool window_modified = false; |
| 109 | |
| 110 | int front_pad_y = 0; |
| 111 | |
| 112 | // Transpose and scale |
| 113 | const int min_y = window.x().start() * _scale_y + _y; |
| 114 | const int max_y = window.x().end() * _scale_y + _y; |
| 115 | |
| 116 | // Adjust window start for output's Y dimension (so X in (input) window) |
| 117 | if (min_y < 0) |
| 118 | { |
| 119 | // Calculate rows available above the tensor |
| 120 | const int front_pad_y_available = -offset_first_element / strides[1]; |
| 121 | |
| 122 | if (min_y < front_pad_y_available) |
| 123 | { |
| 124 | // Not enough padding available, need to shrink the window |
| 125 | const int start = adjust_up(min_y, front_pad_y_available, window.x().step() * _scale_y) - _y; |
| 126 | |
| 127 | window.set(0, Window::Dimension(start / _scale_y, window.x().end(), window.x().step())); |
| 128 | window_modified = true; |
| 129 | } |
| 130 | |
| 131 | // Update front padding with reconstructed value |
| 132 | front_pad_y = std::max(0, static_cast<int>(std::floor(-window.x().start() * _scale_y)) - _y); |
| 133 | } |
| 134 | |
| 135 | // Adjust window end for Y dimension |
| 136 | if (max_y > static_cast<int>(shape[1])) |
| 137 | { |
| 138 | const int stride_z = _info->num_dimensions() > 2 ? strides[2] : _info->total_size(); |
| 139 | |
| 140 | // Calculate rows available below the tensor |
| 141 | const int tail_pad_y_available = (stride_z / strides[1]) - shape[1] - front_pad_y; |
| 142 | |
| 143 | if (static_cast<int>(shape[1]) + tail_pad_y_available < max_y) |
| 144 | { |
| 145 | // Not enough padding available, need to shrink the window |
| 146 | const int end = adjust_down(max_y, shape[1] + tail_pad_y_available, window.x().step() * _scale_y) + |
| 147 | window.x().step() * _scale_y - _y - _height; |
| 148 | window.set(0, Window::Dimension(window.x().start(), end / _scale_y, window.x().step())); |
| 149 | window_modified = true; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | int front_pad_x = 0; |
nothing calls this directly
no test coverage detected