Skip to content

Commit 39c83d7

Browse files
committed
Move tests with dpnp.cov to dedicated class
1 parent 47789df commit 39c83d7

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

dpnp/tests/test_manipulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
assert_array_equal,
99
assert_equal,
1010
assert_raises,
11-
numpy_version,
1211
)
1312

1413
import dpnp
@@ -21,6 +20,7 @@
2120
get_float_dtypes,
2221
get_integer_dtypes,
2322
has_support_aspect64,
23+
numpy_version,
2424
)
2525
from .third_party.cupy import testing
2626

dpnp/tests/test_statistics.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -610,25 +610,36 @@ def test_corrcoef_scalar(self):
610610
assert_dtype_allclose(result, expected)
611611

612612

613-
@pytest.mark.parametrize(
614-
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
615-
)
616-
def test_cov_rowvar(dtype):
617-
a = dpnp.array([[0, 2], [1, 1], [2, 0]], dtype=dtype)
618-
b = numpy.array([[0, 2], [1, 1], [2, 0]], dtype=dtype)
619-
assert_allclose(dpnp.cov(a.T), dpnp.cov(a, rowvar=False))
620-
assert_allclose(numpy.cov(b, rowvar=False), dpnp.cov(a, rowvar=False))
613+
class TestCov:
614+
@pytest.mark.parametrize(
615+
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
616+
)
617+
def test_false_rowvar(self, dtype):
618+
a = numpy.array([[0, 2], [1, 1], [2, 0]], dtype=dtype)
619+
ia = dpnp.array(a)
621620

621+
assert_allclose(dpnp.cov(ia.T), dpnp.cov(ia, rowvar=False))
622+
assert_allclose(dpnp.cov(ia, rowvar=False), numpy.cov(a, rowvar=False))
622623

623-
# numpy 2.2 properly transposes 2d array when rowvar=False
624-
@with_requires("numpy>=2.2")
625-
@pytest.mark.parametrize(
626-
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
627-
)
628-
def test_cov_1D_rowvar(dtype):
629-
a = dpnp.array([[0, 1, 2]], dtype=dtype)
630-
b = numpy.array([[0, 1, 2]], dtype=dtype)
631-
assert_allclose(numpy.cov(b, rowvar=False), dpnp.cov(a, rowvar=False))
624+
# numpy 2.2 properly transposes 2d array when rowvar=False
625+
@with_requires("numpy>=2.2")
626+
def test_1D_false_rowvar(self):
627+
a = numpy.array([0, 1, 2])
628+
ia = dpnp.array(a)
629+
630+
expected = numpy.cov(a, rowvar=False)
631+
result = dpnp.cov(ia, rowvar=False)
632+
assert_allclose(expected, result)
633+
634+
# numpy 2.2 properly transposes 2d array when rowvar=False
635+
@with_requires("numpy>=2.2")
636+
def test_2D_rowvar(self):
637+
a = numpy.ones((3, 1))
638+
ia = dpnp.array(a)
639+
640+
expected = numpy.cov(a, ddof=0, rowvar=True)
641+
result = dpnp.cov(ia, ddof=0, rowvar=True)
642+
assert_allclose(expected, result)
632643

633644

634645
@pytest.mark.parametrize("axis", [None, 0, 1])

0 commit comments

Comments
 (0)