Skip to content

Commit

Permalink
add new tests to improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
vtavana committed Oct 30, 2023
1 parent 5401195 commit 07a5ca0
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions tests/test_statistics.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 @@ -61,27 +62,44 @@ def test_max_min_bool(axis, keepdims):
assert_allclose(dpnp_res, np_res)


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

np_res = numpy.max(a, axis=axis, keepdims=keepdims)
np_res = numpy.max(a, axis=0)
dpnp_res = dpnp.array(numpy.empty_like(np_res))
dpnp.max(ia, axis=axis, keepdims=keepdims, out=dpnp_res)
dpnp.max(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.max(ia, axis=0, out=dpnp_res)
assert_allclose(dpnp_res, np_res)

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

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

np_res = numpy.min(a, axis=0)
dpnp_res = dpnp.array(numpy.empty_like(np_res))
dpnp.min(ia, axis=axis, keepdims=keepdims, out=dpnp_res)
dpnp.min(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.min(ia, axis=0, out=dpnp_res)
assert_allclose(dpnp_res, np_res)

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

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


def test_max_min_NotImplemented():
ia = dpnp.arange(5)
Expand All @@ -94,7 +112,7 @@ def test_max_min_NotImplemented():
with pytest.raises(NotImplementedError):
dpnp.min(ia, where=False)
with pytest.raises(NotImplementedError):
dpnp.max(ia, initial=6)
dpnp.min(ia, initial=6)


@pytest.mark.usefixtures("allow_fall_back_on_numpy")
Expand Down

0 comments on commit 07a5ca0

Please sign in to comment.