Skip to content

Commit 7b7616f

Browse files
author
Vahid Tavanashad
committed
Add more tests
1 parent dab480a commit 7b7616f

File tree

2 files changed

+53
-30
lines changed

2 files changed

+53
-30
lines changed

dpnp/dpnp_iface_manipulation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def _check_stack_arrays(arrays):
119119
def _delete_with_slice(a, obj, axis):
120120
"""Utility function for ``dpnp.delete`` when obj is slice."""
121121

122-
a_ndim, order, axis, slobj, n, a_shape = _calc_parameters(a, axis)
122+
a, a_ndim, order, axis, slobj, n, a_shape = _calc_parameters(a, axis)
123123
start, stop, step = obj.indices(n)
124124
xr = range(start, stop, step)
125125
num_del = len(xr)
@@ -179,7 +179,7 @@ def _delete_with_slice(a, obj, axis):
179179
def _delete_without_slice(a, obj, axis, single_value):
180180
"""Utility function for ``dpnp.delete`` when obj is int or array of int."""
181181

182-
a_ndim, order, axis, slobj, n, a_shape = _calc_parameters(a, axis)
182+
a, a_ndim, order, axis, slobj, n, a_shape = _calc_parameters(a, axis)
183183
if single_value:
184184
# optimization for a single value
185185
if obj < -n or obj >= n:
@@ -242,7 +242,7 @@ def _calc_parameters(a, axis):
242242
n = a.shape[axis]
243243
a_shape = list(a.shape)
244244

245-
return a_ndim, order, axis, slobj, n, a_shape
245+
return a, a_ndim, order, axis, slobj, n, a_shape
246246

247247

248248
def _unique_1d(

tests/test_manipulation.py

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -333,34 +333,56 @@ def test_no_copy(self):
333333

334334

335335
class TestDelete:
336-
def _check_inverse_of_slicing(self, indices):
336+
@pytest.mark.parametrize(
337+
"obj", [slice(0, 4, 2), 3, [2, 3]], ids=["slice", "int", "list"]
338+
)
339+
@pytest.mark.parametrize("dt", get_all_dtypes(no_none=True))
340+
def test_dtype(self, dt, obj):
341+
a = numpy.array([0, 1, 2, 3, 4, 5], dtype=dt)
342+
a_dp = dpnp.array(a)
343+
344+
expected = numpy.delete(a, obj)
345+
result = dpnp.delete(a_dp, obj)
346+
assert result.dtype == dt
347+
assert_array_equal(result, expected)
348+
349+
@pytest.mark.parametrize("start", [-6, -2, 0, 1, 2, 4, 5])
350+
@pytest.mark.parametrize("stop", [-6, -2, 0, 1, 2, 4, 5])
351+
@pytest.mark.parametrize("step", [-3, -1, 1, 3])
352+
def test_slice_1D(self, start, stop, step):
353+
indices = slice(start, stop, step)
354+
# 1D array
337355
a = numpy.arange(5)
338-
b = numpy.arange(10).reshape(1, 5, 2)
339356
a_dp = dpnp.array(a)
340-
b_dp = dpnp.array(b)
357+
expected = numpy.delete(a, indices)
358+
result = dpnp.delete(a_dp, indices)
359+
assert_array_equal(result, expected)
360+
361+
# N-D array
362+
a = numpy.arange(10).reshape(1, 5, 2)
363+
a_dp = dpnp.array(a)
364+
for axis in [None, 1, -1]:
365+
expected = numpy.delete(a, indices, axis=axis)
366+
result = dpnp.delete(a_dp, indices, axis=axis)
367+
assert_array_equal(result, expected)
341368

342-
expected1 = numpy.delete(a, indices)
343-
expected2 = numpy.delete(b, indices, axis=1)
344-
result1 = dpnp.delete(a_dp, indices)
345-
result2 = dpnp.delete(b_dp, indices, axis=1)
346-
assert_array_equal(result1, expected1)
347-
assert_array_equal(result2, expected2)
348-
349-
def test_slices(self):
350-
lims = [-6, -2, 0, 1, 2, 4, 5]
351-
steps = [-3, -1, 1, 3]
352-
for start in lims:
353-
for stop in lims:
354-
for step in steps:
355-
s = slice(start, stop, step)
356-
self._check_inverse_of_slicing(s)
357-
358-
def test_obj(self):
359-
self._check_inverse_of_slicing([0, -1, 2, 2])
360-
self._check_inverse_of_slicing([True, False, False, True, False])
361-
self._check_inverse_of_slicing(0)
362-
self._check_inverse_of_slicing(-4)
363-
self._check_inverse_of_slicing([])
369+
@pytest.mark.parametrize(
370+
"indices", [0, -4, [], [0, -1, 2, 2], [True, False, False, True, False]]
371+
)
372+
def test_indices_1D(self, indices):
373+
# 1D array
374+
a = numpy.arange(5)
375+
a_dp = dpnp.array(a)
376+
expected = numpy.delete(a, indices)
377+
result = dpnp.delete(a_dp, indices)
378+
assert_array_equal(result, expected)
379+
380+
# N-D array
381+
a = numpy.arange(10).reshape(1, 5, 2)
382+
a_dp = dpnp.array(a)
383+
expected = numpy.delete(a, indices, axis=1)
384+
result = dpnp.delete(a_dp, indices, axis=1)
385+
assert_array_equal(result, expected)
364386

365387
def test_obj_ndarray(self):
366388
# 1D array
@@ -413,8 +435,9 @@ def test_error(self):
413435
with pytest.raises(IndexError):
414436
dpnp.delete(a, dpnp.array([], dtype=float))
415437

416-
def test_order(self):
417-
a = numpy.arange(10).reshape(2, 5, order="F")
438+
@pytest.mark.parametrize("order", ["C", "F"])
439+
def test_order(self, order):
440+
a = numpy.arange(10).reshape(2, 5, order=order)
418441
a_dp = dpnp.array(a)
419442

420443
expected = numpy.delete(a, slice(3, None), axis=1)

0 commit comments

Comments
 (0)