Skip to content

Commit ba0bfd9

Browse files
committed
Add tests for well-behaved OOB indices
1 parent a4f6d77 commit ba0bfd9

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

dpctl/tests/test_usm_ndarray_indexing.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,3 +1798,38 @@ def test__copy_utils():
17981798
check__take_multi_index(cu._take_multi_index)
17991799
check__place_impl_validation(cu._place_impl)
18001800
check__put_multi_index_validation(cu._put_multi_index)
1801+
1802+
1803+
@pytest.mark.parametrize("mode", ["wrap", "clip"])
1804+
def test_take_indices_oob_py_ssize_t(mode):
1805+
get_queue_or_skip()
1806+
1807+
x = dpt.arange(10, dtype="i4")
1808+
inds1 = dpt.full(5, dpt.iinfo(dpt.uint64).max, dtype=dpt.uint64)
1809+
inds2 = dpt.full(5, dpt.iinfo(dpt.uint64).max, dtype=dpt.uint64)
1810+
1811+
# sweep through a small range of indices
1812+
# to check that OOB indices are well-behaved
1813+
for i in range(1, 10):
1814+
inds2 -= i
1815+
r1 = dpt.take(x, inds1, mode=mode)
1816+
r2 = dpt.take(x, inds2, mode=mode)
1817+
1818+
assert dpt.all(r1 == r2)
1819+
1820+
1821+
@pytest.mark.parametrize("mode", ["wrap", "clip"])
1822+
def test_put_indices_oob_py_ssize_t(mode):
1823+
get_queue_or_skip()
1824+
1825+
x = dpt.full(10, -1, dtype="i4")
1826+
inds = dpt.full(1, dpt.iinfo(dpt.uint64).max, dtype=dpt.uint64)
1827+
1828+
# OOB inds are positive, so always
1829+
# clip to the top of range
1830+
for i in range(1, 10):
1831+
inds -= i
1832+
dpt.put(x, inds, i, mode=mode)
1833+
1834+
assert dpt.all(x[:-1] == -1)
1835+
assert x[-1] == i

0 commit comments

Comments
 (0)