Skip to content

Commit 9f0fa41

Browse files
author
Holger Kohr
committed
TST: add test for slicing with None for new axis
1 parent 4d108bb commit 9f0fa41

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

pygpu/tests/test_gpu_ndarray.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def test_empty_no_params():
273273

274274

275275
def test_mapping_getitem_ellipsis():
276-
for shp in [(5,), (6, 7), (4, 8, 9), (1, 8, 9)]:
276+
for shp in [(), (5,), (6, 7), (4, 8, 9), (1, 8, 9)]:
277277
for dtype in dtypes_all:
278278
for offseted in [True, False]:
279279
yield mapping_getitem_ellipsis, shp, dtype, offseted
@@ -289,6 +289,27 @@ def mapping_getitem_ellipsis(shp, dtype, offseted):
289289
assert numpy.allclose(a, b_cpu)
290290

291291

292+
def test_getitem_none():
293+
for shp in [(), (5,), (6, 7), (4, 8, 9), (1, 8, 9)]:
294+
yield getitem_none, shp
295+
296+
297+
def getitem_none(shp):
298+
a, a_gpu = gen_gpuarray(shp, ctx=ctx)
299+
300+
assert numpy.allclose(a_gpu[..., None], a[..., None])
301+
302+
for _ in range(5):
303+
# Choose something to slice with, always works
304+
indcs = tuple(numpy.random.choice([0, slice(None), slice(1, None)],
305+
size=len(shp)))
306+
indcs = indcs[:1] + (None,) + indcs[1:]
307+
assert numpy.allclose(a_gpu[indcs], a[indcs])
308+
309+
if shp:
310+
assert numpy.allclose(a_gpu[1:, None], a[1:, None])
311+
312+
292313
def test_mapping_setitem_ellipsis():
293314
for shp in [(9,), (8, 9), (4, 8, 9), (1, 8, 9)]:
294315
for dtype in dtypes_all:

0 commit comments

Comments
 (0)