In principle, overflow on signed int is UB (that we relied on so far anyway). The following one-time check aims to verify the overflow wraps as expected.
()
| 183 | |
| 184 | |
| 185 | def _check_absdiff(): |
| 186 | """ |
| 187 | In principle, overflow on signed int is UB (that we relied on so far anyway). |
| 188 | The following one-time check aims to verify the overflow wraps as expected. |
| 189 | """ |
| 190 | for i in range(-128, 127): |
| 191 | for j in range(-128, 127): |
| 192 | left = np.array([i, i], dtype=np.int8) |
| 193 | right = np.array([j, j], dtype=np.int8) |
| 194 | diff = _get_absdiff(left, right) |
| 195 | expected_diff = np.array([abs(i - j), abs(i - j)], dtype=np.uint8) |
| 196 | assert np.array_equal(diff, expected_diff), f"{diff} {expected_diff} {i} {j}" |
| 197 | for i in range(0, 255): |
| 198 | for j in range(0, 255): |
| 199 | left = np.array([i, i], dtype=np.uint8) |
| 200 | right = np.array([j, j], dtype=np.uint8) |
| 201 | diff = _get_absdiff(left, right) |
| 202 | expected_diff = np.array([abs(i - j), abs(i - j)], dtype=np.uint8) |
| 203 | assert np.array_equal(diff, expected_diff), f"{diff} {expected_diff} {i} {j}" |
| 204 | |
| 205 | |
| 206 | def get_absdiff(left, right): |
no test coverage detected