|
16 | 16 | get_float_complex_dtypes,
|
17 | 17 | has_support_aspect64,
|
18 | 18 | )
|
| 19 | +from .third_party.cupy.testing import with_requires |
19 | 20 |
|
20 | 21 |
|
21 | 22 | class TestAverage:
|
@@ -682,23 +683,38 @@ def test_correlate_another_sycl_queue(self):
|
682 | 683 | dpnp.correlate(a, v)
|
683 | 684 |
|
684 | 685 |
|
685 |
| -@pytest.mark.parametrize( |
686 |
| - "dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True) |
687 |
| -) |
688 |
| -def test_cov_rowvar(dtype): |
689 |
| - a = dpnp.array([[0, 2], [1, 1], [2, 0]], dtype=dtype) |
690 |
| - b = numpy.array([[0, 2], [1, 1], [2, 0]], dtype=dtype) |
691 |
| - assert_allclose(dpnp.cov(a.T), dpnp.cov(a, rowvar=False)) |
692 |
| - assert_allclose(numpy.cov(b, rowvar=False), dpnp.cov(a, rowvar=False)) |
| 686 | +class TestCov: |
| 687 | + @pytest.mark.parametrize( |
| 688 | + "dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True) |
| 689 | + ) |
| 690 | + def test_false_rowvar_dtype(self, dtype): |
| 691 | + a = numpy.array([[0, 2], [1, 1], [2, 0]], dtype=dtype) |
| 692 | + ia = dpnp.array(a) |
693 | 693 |
|
| 694 | + assert_allclose(dpnp.cov(ia.T), dpnp.cov(ia, rowvar=False)) |
| 695 | + assert_allclose(dpnp.cov(ia, rowvar=False), numpy.cov(a, rowvar=False)) |
694 | 696 |
|
695 |
| -@pytest.mark.parametrize( |
696 |
| - "dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True) |
697 |
| -) |
698 |
| -def test_cov_1D_rowvar(dtype): |
699 |
| - a = dpnp.array([[0, 1, 2]], dtype=dtype) |
700 |
| - b = numpy.array([[0, 1, 2]], dtype=dtype) |
701 |
| - assert_allclose(numpy.cov(b, rowvar=False), dpnp.cov(a, rowvar=False)) |
| 697 | + # numpy 2.2 properly transposes 2d array when rowvar=False |
| 698 | + @with_requires("numpy>=2.2") |
| 699 | + @pytest.mark.filterwarnings("ignore::RuntimeWarning") |
| 700 | + def test_false_rowvar_1x3(self): |
| 701 | + a = numpy.array([[0, 1, 2]]) |
| 702 | + ia = dpnp.array(a) |
| 703 | + |
| 704 | + expected = numpy.cov(a, rowvar=False) |
| 705 | + result = dpnp.cov(ia, rowvar=False) |
| 706 | + assert_allclose(expected, result) |
| 707 | + |
| 708 | + # numpy 2.2 properly transposes 2d array when rowvar=False |
| 709 | + @with_requires("numpy>=2.2") |
| 710 | + @pytest.mark.usefixtures("allow_fall_back_on_numpy") |
| 711 | + def test_true_rowvar(self): |
| 712 | + a = numpy.ones((3, 1)) |
| 713 | + ia = dpnp.array(a) |
| 714 | + |
| 715 | + expected = numpy.cov(a, ddof=0, rowvar=True) |
| 716 | + result = dpnp.cov(ia, ddof=0, rowvar=True) |
| 717 | + assert_allclose(expected, result) |
702 | 718 |
|
703 | 719 |
|
704 | 720 | @pytest.mark.parametrize("axis", [None, 0, 1])
|
|
0 commit comments