Skip to content

Commit 335c434

Browse files
committed
Update third party tests
1 parent 0b7f643 commit 335c434

1 file changed

Lines changed: 66 additions & 1 deletion

File tree

dpnp/tests/third_party/cupy/core_tests/test_ndarray_adv_indexing.py

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import itertools
24

35
import numpy
@@ -435,6 +437,15 @@ def test_invalid_adv_getitem(self):
435437
a[self.indexes]
436438

437439

440+
class TestArrayBadDTypeIndexAdvGetitem:
441+
@pytest.mark.parametrize("dtype", [object, "i,i", "float32", "str"])
442+
def test_bad_dtype_adv_getitem(self, dtype):
443+
# Test various bad dtypes, supported by CuPy or not.
444+
a = cupy.arange(10)
445+
with pytest.raises(IndexError, match="arrays used as indices"):
446+
a[numpy.array([1, 2], dtype=dtype)]
447+
448+
438449
@testing.parameterize(
439450
{"shape": (0,), "indexes": ([False],)},
440451
{
@@ -950,6 +961,60 @@ class TestArrayAdvancedIndexingSetitemTranspose:
950961
def test_adv_setitem_transp(self, xp):
951962
shape = (2, 3, 4)
952963
a = xp.zeros(shape).transpose(0, 2, 1)
953-
slices = (xp.array([1, 0]), slice(None), xp.array([2, 1]))
964+
slices = (numpy.array([1, 0]), slice(None), numpy.array([2, 1]))
954965
a[slices] = 1
955966
return a
967+
968+
969+
class TestHugeArrays:
970+
# These tests require a lot of memory
971+
@testing.slow
972+
def test_advanced(self):
973+
try:
974+
arr = cupy.ones((1, 2**30), dtype=cupy.int8)
975+
idx = cupy.zeros(3, dtype=cupy.int32)
976+
res = arr[idx, :]
977+
# sanity check, we mostly care about it not crashing.
978+
assert res.sum() == 3 * 2**30
979+
del res
980+
981+
arr[idx, :] = cupy.array([[3], [3], [3]], dtype=cupy.int8)
982+
# Check 3 got written (order may not be strictly guaranteed)
983+
assert arr.sum() == 2**30 * 3
984+
except MemoryError:
985+
pytest.skip("out of memory in test.")
986+
987+
@testing.slow
988+
def test_take_array(self):
989+
try:
990+
arr = cupy.ones((1, 2**32), dtype=cupy.int8)
991+
arr[0, 2**30] = 0 # We should see each of these once
992+
arr[0, -1] = 0
993+
res = arr.take(cupy.array([0, 0]), axis=0)
994+
# sanity check, we mostly care about it not crashing.
995+
assert res.sum() == 2 * (2**32 - 2)
996+
except MemoryError:
997+
pytest.skip("out of memory in test.")
998+
999+
@testing.slow
1000+
def test_take_scalar(self):
1001+
try:
1002+
arr = cupy.ones((1, 2**32), dtype=cupy.int8)
1003+
arr[0, 2**30] = 0 # We should see each of these once
1004+
arr[0, -1] = 0
1005+
res = arr.take(0, axis=0)
1006+
# sanity check, we mostly care about it not crashing.
1007+
assert res.sum() == 2**32 - 2
1008+
except MemoryError:
1009+
pytest.skip("out of memory in test.")
1010+
1011+
@testing.slow
1012+
def test_choose(self):
1013+
try:
1014+
choices = cupy.zeros((2, 2**31), dtype=cupy.int8)
1015+
choices[1, :] = 1
1016+
res = choices[1, :].choose(choices)
1017+
# sanity check, we mostly care about it not crashing.
1018+
assert res.sum() == 2**31
1019+
except MemoryError:
1020+
pytest.skip("out of memory in test.")

0 commit comments

Comments
 (0)