From 9e4d4171602a1ba0851359879a08a2750b7b550b Mon Sep 17 00:00:00 2001 From: Alexander Kalistratov Date: Wed, 30 Oct 2024 16:18:50 +0100 Subject: [PATCH 1/3] Implementation of corrcoef --- dpnp/dpnp_iface_statistics.py | 66 +++++++++++++++++++ tests/skipped_tests_gpu.tbl | 5 -- tests/test_statistics.py | 45 +++++++++++++ .../cupy/statistics_tests/test_correlation.py | 8 +-- 4 files changed, 115 insertions(+), 9 deletions(-) diff --git a/dpnp/dpnp_iface_statistics.py b/dpnp/dpnp_iface_statistics.py index 03aa3a6516d6..c16e8cdf2cdc 100644 --- a/dpnp/dpnp_iface_statistics.py +++ b/dpnp/dpnp_iface_statistics.py @@ -37,6 +37,8 @@ """ +import warnings + import dpctl.tensor as dpt import numpy from dpctl.tensor._numpy_helper import ( @@ -65,6 +67,7 @@ "amin", "average", "bincount", + "corrcoef", "correlate", "cov", "max", @@ -403,6 +406,69 @@ def correlate(x1, x2, mode="valid"): return call_origin(numpy.correlate, x1, x2, mode=mode) +def corrcoef(x, y=None, rowvar=True, bias=None, ddof=None, *, dtype=None): + """ + Return Pearson product-moment correlation coefficients. + + For full documentation refer to :obj:`numpy.corrcoef`. + + Parameters + ---------- + x : {dpnp.ndarray, usm_ndarray} + A 1-D or 2-D array containing multiple variables and observations. + Each row of `x` represents a variable, and each column a single + observation of all those variables. Also see `rowvar` below. + y : {dpnp.ndarray, usm_ndarray}, optional + An additional set of variables and observations. `y` has the same + shape as `x`. + rowvar : {bool}, optional + If `rowvar` is True (default), then each row represents a + variable, with observations in the columns. Otherwise, the relationship + is transposed: each column represents a variable, while the rows + contain observations. + bias : {None}, optional + Has no effect, do not use. + ddof : {None}, optional + Has no effect, do not use. + dtype : data-type, optional + Data-type of the result. + + Returns + ------- + R : dpnp.ndarray + The correlation coefficient matrix of the variables. + + See Also + -------- + :obj:`dpnp.cov` : Covariance matrix. + """ + if bias is not None or ddof is not None: + warnings.warn( + "bias and ddof have no effect and are deprecated", + DeprecationWarning, + stacklevel=2, + ) + + out = dpnp.cov(x, y, rowvar, dtype=dtype) + try: + d = dpnp.diag(out) + except ValueError: + return out / out + + stddev = dpnp.sqrt(d.real) + out /= stddev[:, None] + out /= stddev[None, :] + + # Clip real and imaginary parts to [-1, 1]. This does not guarantee + # abs(a[i,j]) <= 1 for complex arrays, but is the best we can do without + # excessive work. + dpnp.clip(out.real, -1, 1, out=out.real) + if dpnp.iscomplexobj(out): + dpnp.clip(out.imag, -1, 1, out=out.imag) + + return out + + def cov( m, y=None, diff --git a/tests/skipped_tests_gpu.tbl b/tests/skipped_tests_gpu.tbl index 82e7c2abee13..797f1ecf86c3 100644 --- a/tests/skipped_tests_gpu.tbl +++ b/tests/skipped_tests_gpu.tbl @@ -320,11 +320,6 @@ tests/third_party/cupy/random_tests/test_sample.py::TestRandomIntegers2::test_bo tests/third_party/cupy/random_tests/test_sample.py::TestRandomIntegers2::test_goodness_of_fit tests/third_party/cupy/random_tests/test_sample.py::TestRandomIntegers2::test_goodness_of_fit_2 -tests/third_party/cupy/statistics_tests/test_correlation.py::TestCorrcoef::test_corrcoef -tests/third_party/cupy/statistics_tests/test_correlation.py::TestCorrcoef::test_corrcoef_diag_exception -tests/third_party/cupy/statistics_tests/test_correlation.py::TestCorrcoef::test_corrcoef_rowvar -tests/third_party/cupy/statistics_tests/test_correlation.py::TestCorrcoef::test_corrcoef_y - tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_defaults[linear] tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_defaults[lower] tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_defaults[higher] diff --git a/tests/test_statistics.py b/tests/test_statistics.py index 3baccad541b3..bb56f70b41f5 100644 --- a/tests/test_statistics.py +++ b/tests/test_statistics.py @@ -573,6 +573,51 @@ def test_std_error(self): dpnp.std(ia, ddof="1") +class TestCorrcoef: + @pytest.mark.usefixtures("suppress_divide_invalid_numpy_warnings") + @pytest.mark.parametrize("dtype", get_all_dtypes()) + @pytest.mark.parametrize("rowvar", [True, False]) + def test_corrcoef(self, dtype, rowvar): + dp_array = dpnp.array([[0, 1, 2], [3, 4, 0]], dtype=dtype) + np_array = dpnp.asnumpy(dp_array) + + expected = numpy.corrcoef(np_array, rowvar=rowvar) + result = dpnp.corrcoef(dp_array, rowvar=rowvar) + + assert_dtype_allclose(result, expected) + + @pytest.mark.usefixtures("suppress_divide_invalid_numpy_warnings") + @pytest.mark.parametrize("shape", [(2, 0), (0, 2)]) + def test_corrcoef_empty(self, shape): + dp_array = dpnp.empty(shape, dtype=dpnp.int64) + np_array = dpnp.asnumpy(dp_array) + + result = dpnp.corrcoef(dp_array) + expected = numpy.corrcoef(np_array) + assert_dtype_allclose(result, expected) + + @pytest.mark.usefixtures("suppress_complex_warning") + @pytest.mark.parametrize("dt_in", get_all_dtypes(no_bool=True)) + @pytest.mark.parametrize("dt_out", get_float_complex_dtypes()) + def test_corrcoef_dtype(self, dt_in, dt_out): + dp_array = dpnp.array([[0, 1, 2], [3, 4, 0]], dtype=dt_in) + np_array = dpnp.asnumpy(dp_array) + + expected = numpy.corrcoef(np_array, dtype=dt_out) + result = dpnp.corrcoef(dp_array, dtype=dt_out) + assert expected.dtype == result.dtype + assert_allclose(result, expected, rtol=1e-6) + + @pytest.mark.usefixtures("suppress_divide_invalid_numpy_warnings") + def test_corrcoef_scalar(self): + dp_array = dpnp.array(5) + np_array = dpnp.asnumpy(dp_array) + + result = dpnp.corrcoef(dp_array) + expected = numpy.corrcoef(np_array) + assert_dtype_allclose(result, expected) + + @pytest.mark.usefixtures("allow_fall_back_on_numpy") class TestBincount: @pytest.mark.parametrize( diff --git a/tests/third_party/cupy/statistics_tests/test_correlation.py b/tests/third_party/cupy/statistics_tests/test_correlation.py index be6b815629ff..59ea0ae435de 100644 --- a/tests/third_party/cupy/statistics_tests/test_correlation.py +++ b/tests/third_party/cupy/statistics_tests/test_correlation.py @@ -12,26 +12,26 @@ class TestCorrcoef(unittest.TestCase): @testing.for_all_dtypes() - @testing.numpy_cupy_allclose() + @testing.numpy_cupy_allclose(type_check=False) def test_corrcoef(self, xp, dtype): a = testing.shaped_arange((2, 3), xp, dtype) return xp.corrcoef(a) @testing.for_all_dtypes() - @testing.numpy_cupy_allclose() + @testing.numpy_cupy_allclose(type_check=False) def test_corrcoef_diag_exception(self, xp, dtype): a = testing.shaped_arange((1, 3), xp, dtype) return xp.corrcoef(a) @testing.for_all_dtypes() - @testing.numpy_cupy_allclose() + @testing.numpy_cupy_allclose(type_check=False) def test_corrcoef_y(self, xp, dtype): a = testing.shaped_arange((2, 3), xp, dtype) y = testing.shaped_arange((2, 3), xp, dtype) return xp.corrcoef(a, y=y) @testing.for_all_dtypes() - @testing.numpy_cupy_allclose() + @testing.numpy_cupy_allclose(type_check=False) def test_corrcoef_rowvar(self, xp, dtype): a = testing.shaped_arange((2, 3), xp, dtype) y = testing.shaped_arange((2, 3), xp, dtype) From 0efb5ded52679d5d86e85282fe5fb4fa88a81600 Mon Sep 17 00:00:00 2001 From: Alexander Kalistratov Date: Tue, 5 Nov 2024 15:45:13 +0100 Subject: [PATCH 2/3] Apply review comments --- dpnp/dpnp_iface_statistics.py | 184 ++++++++++++------ tests/skipped_tests.tbl | 5 - tests/test_statistics.py | 16 +- tests/test_sycl_queue.py | 6 + tests/test_usm_type.py | 6 + .../cupy/statistics_tests/test_correlation.py | 8 +- 6 files changed, 149 insertions(+), 76 deletions(-) diff --git a/dpnp/dpnp_iface_statistics.py b/dpnp/dpnp_iface_statistics.py index c16e8cdf2cdc..6467c6b82984 100644 --- a/dpnp/dpnp_iface_statistics.py +++ b/dpnp/dpnp_iface_statistics.py @@ -37,8 +37,6 @@ """ -import warnings - import dpctl.tensor as dpt import numpy from dpctl.tensor._numpy_helper import ( @@ -363,50 +361,7 @@ def bincount(x1, weights=None, minlength=0): return call_origin(numpy.bincount, x1, weights=weights, minlength=minlength) -def correlate(x1, x2, mode="valid"): - """ - Cross-correlation of two 1-dimensional sequences. - - For full documentation refer to :obj:`numpy.correlate`. - - Limitations - ----------- - Input arrays are supported as :obj:`dpnp.ndarray`. - Size and shape of input arrays are supported to be equal. - Parameter `mode` is supported only with default value ``"valid"``. - Otherwise the function will be executed sequentially on CPU. - Input array data types are limited by supported DPNP :ref:`Data types`. - - See Also - -------- - :obj:`dpnp.convolve` : Discrete, linear convolution of - two one-dimensional sequences. - - Examples - -------- - >>> import dpnp as np - >>> x = np.correlate([1, 2, 3], [0, 1, 0.5]) - >>> [i for i in x] - [3.5] - - """ - - x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False) - x2_desc = dpnp.get_dpnp_descriptor(x2, copy_when_nondefault_queue=False) - if x1_desc and x2_desc: - if x1_desc.size != x2_desc.size or x1_desc.size == 0: - pass - elif x1_desc.shape != x2_desc.shape: - pass - elif mode != "valid": - pass - else: - return dpnp_correlate(x1_desc, x2_desc).get_pyobj() - - return call_origin(numpy.correlate, x1, x2, mode=mode) - - -def corrcoef(x, y=None, rowvar=True, bias=None, ddof=None, *, dtype=None): +def corrcoef(x, y=None, rowvar=True, *, dtype=None): """ Return Pearson product-moment correlation coefficients. @@ -418,20 +373,19 @@ def corrcoef(x, y=None, rowvar=True, bias=None, ddof=None, *, dtype=None): A 1-D or 2-D array containing multiple variables and observations. Each row of `x` represents a variable, and each column a single observation of all those variables. Also see `rowvar` below. - y : {dpnp.ndarray, usm_ndarray}, optional + y : {None, dpnp.ndarray, usm_ndarray}, optional An additional set of variables and observations. `y` has the same shape as `x`. + Default: ``None``. rowvar : {bool}, optional - If `rowvar` is True (default), then each row represents a - variable, with observations in the columns. Otherwise, the relationship + If `rowvar` is ``True``, then each row represents a variable, + with observations in the columns. Otherwise, the relationship is transposed: each column represents a variable, while the rows contain observations. - bias : {None}, optional - Has no effect, do not use. - ddof : {None}, optional - Has no effect, do not use. - dtype : data-type, optional + Default: ``True``. + dtype : {None, dtype}, optional Data-type of the result. + Default: ``None``. Returns ------- @@ -441,25 +395,84 @@ def corrcoef(x, y=None, rowvar=True, bias=None, ddof=None, *, dtype=None): See Also -------- :obj:`dpnp.cov` : Covariance matrix. + + Examples + -------- + In this example we generate two random arrays, ``xarr`` and ``yarr``, and + compute the row-wise and column-wise Pearson correlation coefficients, + ``R``. Since ``rowvar`` is true by default, we first find the row-wise + Pearson correlation coefficients between the variables of ``xarr``. + + >>> import dpnp as np + >>> np.random.seed(123) + >>> xarr = np.random.rand(3, 3).astype(np.float32) + >>> xarr + array([[7.2858386e-17, 2.2066992e-02, 3.9520904e-01], + [4.8012391e-01, 5.9377134e-01, 4.5147297e-01], + [9.0728188e-01, 9.9387854e-01, 5.8399546e-01]], dtype=float32) + >>> R1 = np.corrcoef(xarr) + >>> R1 + array([[ 0.99999994, -0.6173796 , -0.9685411 ], + [-0.6173796 , 1. , 0.7937219 ], + [-0.9685411 , 0.7937219 , 0.9999999 ]], dtype=float32) + + If we add another set of variables and observations ``yarr``, we can + compute the row-wise Pearson correlation coefficients between the + variables in ``xarr`` and ``yarr``. + + >>> yarr = np.random.rand(3, 3).astype(np.float32) + >>> yarr + array([[0.17615308, 0.65354985, 0.15716429], + [0.09373496, 0.2123185 , 0.84086883], + [0.9011005 , 0.45206687, 0.00225109]], dtype=float32) + >>> R2 = np.corrcoef(xarr, yarr) + >>> R2 + array([[ 0.99999994, -0.6173796 , -0.968541 , -0.48613155, 0.9951523 , + -0.8900264 ], + [-0.6173796 , 1. , 0.7937219 , 0.9875833 , -0.53702235, + 0.19083664], + [-0.968541 , 0.7937219 , 0.9999999 , 0.6883078 , -0.9393724 , + 0.74857277], + [-0.48613152, 0.9875833 , 0.6883078 , 0.9999999 , -0.39783284, + 0.0342579 ], + [ 0.9951523 , -0.53702235, -0.9393725 , -0.39783284, 0.99999994, + -0.9305482 ], + [-0.89002645, 0.19083665, 0.7485727 , 0.0342579 , -0.9305482 , + 1. ]], dtype=float32) + + Finally if we use the option ``rowvar=False``, the columns are now + being treated as the variables and we will find the column-wise Pearson + correlation coefficients between variables in ``xarr`` and ``yarr``. + + >>> R3 = np.corrcoef(xarr, yarr, rowvar=False) + >>> R3 + array([[ 1. , 0.9724453 , -0.9909503 , 0.8104691 , -0.46436927, + -0.1643624 ], + [ 0.9724453 , 1. , -0.9949381 , 0.6515728 , -0.6580445 , + 0.07012729], + [-0.99095035, -0.994938 , 1. , -0.72450536, 0.5790461 , + 0.03047091], + [ 0.8104691 , 0.65157276, -0.72450536, 1. , 0.14243561, + -0.71102554], + [-0.4643693 , -0.6580445 , 0.57904613, 0.1424356 , 0.99999994, + -0.79727215], + [-0.1643624 , 0.07012729, 0.03047091, -0.7110255 , -0.7972722 , + 0.99999994]], dtype=float32) """ - if bias is not None or ddof is not None: - warnings.warn( - "bias and ddof have no effect and are deprecated", - DeprecationWarning, - stacklevel=2, - ) out = dpnp.cov(x, y, rowvar, dtype=dtype) - try: - d = dpnp.diag(out) - except ValueError: + if out.ndim == 0: + # scalar covariance + # nan if incorrect value (nan, inf, 0), 1 otherwise return out / out + d = dpnp.diag(out) + stddev = dpnp.sqrt(d.real) out /= stddev[:, None] out /= stddev[None, :] - # Clip real and imaginary parts to [-1, 1]. This does not guarantee + # Clip real and imaginary parts to [-1, 1]. This does not guarantee # abs(a[i,j]) <= 1 for complex arrays, but is the best we can do without # excessive work. dpnp.clip(out.real, -1, 1, out=out.real) @@ -469,6 +482,49 @@ def corrcoef(x, y=None, rowvar=True, bias=None, ddof=None, *, dtype=None): return out +def correlate(x1, x2, mode="valid"): + """ + Cross-correlation of two 1-dimensional sequences. + + For full documentation refer to :obj:`numpy.correlate`. + + Limitations + ----------- + Input arrays are supported as :obj:`dpnp.ndarray`. + Size and shape of input arrays are supported to be equal. + Parameter `mode` is supported only with default value ``"valid"``. + Otherwise the function will be executed sequentially on CPU. + Input array data types are limited by supported DPNP :ref:`Data types`. + + See Also + -------- + :obj:`dpnp.convolve` : Discrete, linear convolution of + two one-dimensional sequences. + + Examples + -------- + >>> import dpnp as np + >>> x = np.correlate([1, 2, 3], [0, 1, 0.5]) + >>> [i for i in x] + [3.5] + + """ + + x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False) + x2_desc = dpnp.get_dpnp_descriptor(x2, copy_when_nondefault_queue=False) + if x1_desc and x2_desc: + if x1_desc.size != x2_desc.size or x1_desc.size == 0: + pass + elif x1_desc.shape != x2_desc.shape: + pass + elif mode != "valid": + pass + else: + return dpnp_correlate(x1_desc, x2_desc).get_pyobj() + + return call_origin(numpy.correlate, x1, x2, mode=mode) + + def cov( m, y=None, diff --git a/tests/skipped_tests.tbl b/tests/skipped_tests.tbl index d0ee8bb0b617..db1beb0c6fc9 100644 --- a/tests/skipped_tests.tbl +++ b/tests/skipped_tests.tbl @@ -310,11 +310,6 @@ tests/third_party/cupy/random_tests/test_sample.py::TestRandomIntegers2::test_bo tests/third_party/cupy/random_tests/test_sample.py::TestRandomIntegers2::test_goodness_of_fit tests/third_party/cupy/random_tests/test_sample.py::TestRandomIntegers2::test_goodness_of_fit_2 -tests/third_party/cupy/statistics_tests/test_correlation.py::TestCorrcoef::test_corrcoef -tests/third_party/cupy/statistics_tests/test_correlation.py::TestCorrcoef::test_corrcoef_diag_exception -tests/third_party/cupy/statistics_tests/test_correlation.py::TestCorrcoef::test_corrcoef_rowvar -tests/third_party/cupy/statistics_tests/test_correlation.py::TestCorrcoef::test_corrcoef_y - tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_defaults[linear] tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_defaults[lower] tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_defaults[higher] diff --git a/tests/test_statistics.py b/tests/test_statistics.py index bb56f70b41f5..b0567216825a 100644 --- a/tests/test_statistics.py +++ b/tests/test_statistics.py @@ -574,7 +574,10 @@ def test_std_error(self): class TestCorrcoef: - @pytest.mark.usefixtures("suppress_divide_invalid_numpy_warnings") + @pytest.mark.usefixtures( + "suppress_divide_invalid_numpy_warnings", + "suppress_dof_numpy_warnings", + ) @pytest.mark.parametrize("dtype", get_all_dtypes()) @pytest.mark.parametrize("rowvar", [True, False]) def test_corrcoef(self, dtype, rowvar): @@ -586,7 +589,11 @@ def test_corrcoef(self, dtype, rowvar): assert_dtype_allclose(result, expected) - @pytest.mark.usefixtures("suppress_divide_invalid_numpy_warnings") + @pytest.mark.usefixtures( + "suppress_divide_invalid_numpy_warnings", + "suppress_dof_numpy_warnings", + "suppress_mean_empty_slice_numpy_warnings", + ) @pytest.mark.parametrize("shape", [(2, 0), (0, 2)]) def test_corrcoef_empty(self, shape): dp_array = dpnp.empty(shape, dtype=dpnp.int64) @@ -608,7 +615,10 @@ def test_corrcoef_dtype(self, dt_in, dt_out): assert expected.dtype == result.dtype assert_allclose(result, expected, rtol=1e-6) - @pytest.mark.usefixtures("suppress_divide_invalid_numpy_warnings") + @pytest.mark.usefixtures( + "suppress_divide_invalid_numpy_warnings", + "suppress_dof_numpy_warnings", + ) def test_corrcoef_scalar(self): dp_array = dpnp.array(5) np_array = dpnp.asnumpy(dp_array) diff --git a/tests/test_sycl_queue.py b/tests/test_sycl_queue.py index a4e969f68430..604a60446c78 100644 --- a/tests/test_sycl_queue.py +++ b/tests/test_sycl_queue.py @@ -442,6 +442,7 @@ def test_meshgrid(device): pytest.param("ceil", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]), pytest.param("conjugate", [[1.0 + 1.0j, 0.0], [0.0, 1.0 + 1.0j]]), pytest.param("copy", [1.0, 2.0, 3.0]), + pytest.param("corrcoef", [[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]]), pytest.param( "cos", [-dpnp.pi / 2, -dpnp.pi / 4, 0.0, dpnp.pi / 4, dpnp.pi / 2] ), @@ -693,6 +694,11 @@ def test_reduce_hypot(device): pytest.param("append", [1, 2, 3], [4, 5, 6]), pytest.param("arctan2", [-1, +1, +1, -1], [-1, -1, +1, +1]), pytest.param("copysign", [0.0, 1.0, 2.0], [-1.0, 0.0, 1.0]), + pytest.param( + "corrcoef", + [[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]], + [[0.7, 0.8, 0.9], [1.0, 1.1, 1.2]], + ), pytest.param("cross", [1.0, 2.0, 3.0], [4.0, 5.0, 6.0]), pytest.param("digitize", [0.2, 6.4, 3.0], [0.0, 1.0, 2.5, 4.0]), pytest.param( diff --git a/tests/test_usm_type.py b/tests/test_usm_type.py index aa76443dad40..4aa74182ce77 100644 --- a/tests/test_usm_type.py +++ b/tests/test_usm_type.py @@ -576,6 +576,7 @@ def test_norm(usm_type, ord, axis): pytest.param("cbrt", [1, 8, 27]), pytest.param("ceil", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]), pytest.param("conjugate", [[1.0 + 1.0j, 0.0], [0.0, 1.0 + 1.0j]]), + pytest.param("corrcoef", [[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]]), pytest.param( "cos", [-dp.pi / 2, -dp.pi / 4, 0.0, dp.pi / 4, dp.pi / 2] ), @@ -685,6 +686,11 @@ def test_1in_1out(func, data, usm_type): pytest.param("copysign", [0.0, 1.0, 2.0], [-1.0, 0.0, 1.0]), pytest.param("cross", [1.0, 2.0, 3.0], [4.0, 5.0, 6.0]), pytest.param("digitize", [0.2, 6.4, 3.0], [0.0, 1.0, 2.5, 4.0]), + pytest.param( + "corrcoef", + [[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]], + [[0.7, 0.8, 0.9], [1.0, 1.1, 1.2]], + ), # dpnp.dot has 3 different implementations based on input arrays dtype # checking all of them pytest.param("dot", [3.0, 4.0, 5.0], [1.0, 2.0, 3.0]), diff --git a/tests/third_party/cupy/statistics_tests/test_correlation.py b/tests/third_party/cupy/statistics_tests/test_correlation.py index 59ea0ae435de..2a4cef5f8c55 100644 --- a/tests/third_party/cupy/statistics_tests/test_correlation.py +++ b/tests/third_party/cupy/statistics_tests/test_correlation.py @@ -12,26 +12,26 @@ class TestCorrcoef(unittest.TestCase): @testing.for_all_dtypes() - @testing.numpy_cupy_allclose(type_check=False) + @testing.numpy_cupy_allclose(type_check=has_support_aspect64()) def test_corrcoef(self, xp, dtype): a = testing.shaped_arange((2, 3), xp, dtype) return xp.corrcoef(a) @testing.for_all_dtypes() - @testing.numpy_cupy_allclose(type_check=False) + @testing.numpy_cupy_allclose(type_check=has_support_aspect64()) def test_corrcoef_diag_exception(self, xp, dtype): a = testing.shaped_arange((1, 3), xp, dtype) return xp.corrcoef(a) @testing.for_all_dtypes() - @testing.numpy_cupy_allclose(type_check=False) + @testing.numpy_cupy_allclose(type_check=has_support_aspect64()) def test_corrcoef_y(self, xp, dtype): a = testing.shaped_arange((2, 3), xp, dtype) y = testing.shaped_arange((2, 3), xp, dtype) return xp.corrcoef(a, y=y) @testing.for_all_dtypes() - @testing.numpy_cupy_allclose(type_check=False) + @testing.numpy_cupy_allclose(type_check=has_support_aspect64()) def test_corrcoef_rowvar(self, xp, dtype): a = testing.shaped_arange((2, 3), xp, dtype) y = testing.shaped_arange((2, 3), xp, dtype) From c835118f70cafca7cadeda246664633463346414 Mon Sep 17 00:00:00 2001 From: Alexander Kalistratov Date: Tue, 12 Nov 2024 15:38:37 +0100 Subject: [PATCH 3/3] Fix docs --- dpnp/dpnp_iface_statistics.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dpnp/dpnp_iface_statistics.py b/dpnp/dpnp_iface_statistics.py index 6467c6b82984..cdb8743b1ec2 100644 --- a/dpnp/dpnp_iface_statistics.py +++ b/dpnp/dpnp_iface_statistics.py @@ -389,7 +389,7 @@ def corrcoef(x, y=None, rowvar=True, *, dtype=None): Returns ------- - R : dpnp.ndarray + R : {dpnp.ndarray} The correlation coefficient matrix of the variables. See Also @@ -400,7 +400,7 @@ def corrcoef(x, y=None, rowvar=True, *, dtype=None): -------- In this example we generate two random arrays, ``xarr`` and ``yarr``, and compute the row-wise and column-wise Pearson correlation coefficients, - ``R``. Since ``rowvar`` is true by default, we first find the row-wise + ``R``. Since `rowvar` is true by default, we first find the row-wise Pearson correlation coefficients between the variables of ``xarr``. >>> import dpnp as np