Skip to content

Commit

Permalink
add tests for negative use cases to improve covergae
Browse files Browse the repository at this point in the history
  • Loading branch information
vtavana committed Oct 30, 2023
1 parent 6c3991d commit 2028535
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions tests/test_search.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dpctl.tensor as dpt
import numpy
import pytest
from numpy.testing import assert_allclose
Expand Down Expand Up @@ -47,23 +48,40 @@ def test_argmax_argmin_bool(axis, keepdims):
assert_allclose(dpnp_res, np_res)


@pytest.mark.parametrize("axis", [None, 0, 1, -1, 2, -2])
@pytest.mark.parametrize("keepdims", [False, True])
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
def test_argmax_argmin_out(axis, keepdims, dtype):
a = numpy.arange(768, dtype=dtype).reshape((4, 4, 6, 8))
def test_argmax_argmin_out():
a = numpy.arange(6).reshape((2, 3))
ia = dpnp.array(a)

np_res = numpy.argmax(a, axis=axis, keepdims=keepdims)
np_res = numpy.argmax(a, axis=0)
dpnp_res = dpnp.array(numpy.empty_like(np_res))
dpnp.argmax(ia, axis=axis, keepdims=keepdims, out=dpnp_res)
dpnp.argmax(ia, axis=0, out=dpnp_res)
assert_allclose(dpnp_res, np_res)

assert dpnp_res.shape == np_res.shape
dpnp_res = dpt.asarray(numpy.empty_like(np_res))
dpnp.argmax(ia, axis=0, out=dpnp_res)
assert_allclose(dpnp_res, np_res)

np_res = numpy.argmin(a, axis=axis, keepdims=keepdims)
dpnp_res = numpy.empty_like(np_res)
with pytest.raises(TypeError):
dpnp.argmax(ia, axis=0, out=dpnp_res)

dpnp_res = dpnp.array(numpy.empty((2, 3)))
with pytest.raises(ValueError):
dpnp.argmax(ia, axis=0, out=dpnp_res)

np_res = numpy.argmin(a, axis=0)
dpnp_res = dpnp.array(numpy.empty_like(np_res))
dpnp.argmin(ia, axis=axis, keepdims=keepdims, out=dpnp_res)
dpnp.argmin(ia, axis=0, out=dpnp_res)
assert_allclose(dpnp_res, np_res)

assert dpnp_res.shape == np_res.shape
dpnp_res = dpt.asarray(numpy.empty_like(np_res))
dpnp.argmin(ia, axis=0, out=dpnp_res)
assert_allclose(dpnp_res, np_res)

dpnp_res = numpy.empty_like(np_res)
with pytest.raises(TypeError):
dpnp.argmin(ia, axis=0, out=dpnp_res)

dpnp_res = dpnp.array(numpy.empty((2, 3)))
with pytest.raises(ValueError):
dpnp.argmin(ia, axis=0, out=dpnp_res)

0 comments on commit 2028535

Please sign in to comment.