Commit 930b764
Hoist CropAndResize index offset to a named int64_t (microsoft#29623)
### Description
Follow-up to the merged microsoft#29605, addressing a review nit from @apsonawane
on the base-offset index arithmetic in `CropAndResizeForward`.
The suggestion was that the `static_cast<int64_t>(...)` around the
per-channel base offset looked redundant. It turns out the cast could
**not** simply be removed: the offset expression is a
`SafeInt<int64_t>`, and `pointer + SafeInt<int64_t>` is ambiguous —
`SafeInt` exposes many implicit conversion operators (`char`, `short`,
`int`, …), so the operand for pointer arithmetic cannot be resolved
unambiguously (and `SafeInt`'s own `operator+(U, SafeInt)` tries to
treat the pointer as an integer). The cast was therefore load-bearing.
To honor the readability intent without the awkward inline cast, this
change hoists the offset into a named `int64_t` local in both the
bilinear and nearest branches:
```cpp
const int64_t bottom_data_offset = (SafeInt<int64_t>(roi_batch_ind) * channels + c) * height * width;
const T* offset_bottom_data = bottom_data + bottom_data_offset;
```
Initializing an `int64_t` directly from the `SafeInt<int64_t>`
expression is unambiguous (it selects `operator int64_t()`), so this
compiles cleanly, keeps the `SafeInt` overflow checking on the offset
computation, and reads more clearly than the inline cast. **No behavior
change.**
### Motivation and Context
Improves readability of the index arithmetic introduced in microsoft#29605 while
keeping the overflow-checked offset computation intact.
### Tests
Covered by the existing `CropAndResizeTest` suite — all 10 tests pass:
```
onnxruntime_provider_test --gtest_filter='CropAndResizeTest.*'
```
Signed-off-by: Tita Wang <titaiwang@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 73260b2 commit 930b764
1 file changed
Lines changed: 4 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
153 | | - | |
154 | | - | |
| 152 | + | |
| 153 | + | |
155 | 154 | | |
156 | 155 | | |
157 | 156 | | |
| |||
169 | 168 | | |
170 | 169 | | |
171 | 170 | | |
172 | | - | |
173 | | - | |
174 | | - | |
| 171 | + | |
| 172 | + | |
175 | 173 | | |
176 | 174 | | |
177 | 175 | | |
| |||
0 commit comments