MCPcopy Create free account
hub / github.com/NVIDIA/DALI / _check_absdiff

Function _check_absdiff

dali/test/python/test_utils.py:185–203  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

183
184
185def _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
206def get_absdiff(left, right):

Callers 1

get_absdiffFunction · 0.85

Calls 2

_get_absdiffFunction · 0.85
absFunction · 0.50

Tested by

no test coverage detected