Skip to content

fix_cov_for_no_fp64 #1385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dpnp/backend/kernels/dpnp_krnl_statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ DPCTLSyclEventRef dpnp_cov_c(DPCTLSyclQueueRef q_ref,
nrows, // std::int64_t n,
ncols, // std::int64_t k,
alpha, // T alpha,
temp, //const T* a,
temp, // const T* a,
ncols, // std::int64_t lda,
beta, // T beta,
result, // T* c,
Expand Down Expand Up @@ -1384,7 +1384,7 @@ void func_map_init_statistics(func_map_t& fmap)

fmap[DPNPFuncName::DPNP_FN_COV_EXT][eft_INT][eft_INT] = {eft_DBL, (void*)dpnp_cov_ext_c<double>};
fmap[DPNPFuncName::DPNP_FN_COV_EXT][eft_LNG][eft_LNG] = {eft_DBL, (void*)dpnp_cov_ext_c<double>};
fmap[DPNPFuncName::DPNP_FN_COV_EXT][eft_FLT][eft_FLT] = {eft_DBL, (void*)dpnp_cov_ext_c<double>};
fmap[DPNPFuncName::DPNP_FN_COV_EXT][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_cov_ext_c<float>};
fmap[DPNPFuncName::DPNP_FN_COV_EXT][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_cov_ext_c<double>};

fmap[DPNPFuncName::DPNP_FN_MAX][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_max_default_c<int32_t>};
Expand Down
1 change: 0 additions & 1 deletion dpnp/dpnp_algo/dpnp_algo_statistics.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ cpdef utils.dpnp_descriptor dpnp_correlate(utils.dpnp_descriptor x1, utils.dpnp_
return result


# supports "double" input only
cpdef utils.dpnp_descriptor dpnp_cov(utils.dpnp_descriptor array1):
cdef shape_type_c input_shape = array1.shape

Expand Down
55 changes: 27 additions & 28 deletions dpnp/dpnp_iface_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@


import numpy

import dpctl.tensor as dpt
from dpnp.dpnp_algo import *
from dpnp.dpnp_utils import *
from dpnp.dpnp_array import dpnp_array
Expand Down Expand Up @@ -247,7 +247,7 @@ def cov(x1, y=None, rowvar=True, bias=False, ddof=None, fweights=None, aweights=
Limitations
-----------
Input array ``m`` is supported as :obj:`dpnp.ndarray`.
Dimension of input array ``m`` is limited by ``m.ndim > 2``.
Dimension of input array ``m`` is limited by ``m.ndim <= 2``.
Size and shape of input arrays are supported to be equal.
Prameters ``y`` is supported only with default value ``None``.
Prameters ``bias`` is supported only with default value ``False``.
Expand All @@ -257,7 +257,7 @@ def cov(x1, y=None, rowvar=True, bias=False, ddof=None, fweights=None, aweights=
Otherwise the function will be executed sequentially on CPU.
Input array data types are limited by supported DPNP :ref:`Data types`.

.. seealso:: :obj:`dpnp.corrcoef` normalized covariance matrix.
.. see also:: :obj:`dpnp.corrcoef` normalized covariance matrix.

Examples
--------
Expand All @@ -274,31 +274,30 @@ def cov(x1, y=None, rowvar=True, bias=False, ddof=None, fweights=None, aweights=
[1.0, -1.0, -1.0, 1.0]

"""

x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False)
if x1_desc:
if x1_desc.ndim > 2:
pass
elif y is not None:
pass
elif bias:
pass
elif ddof is not None:
pass
elif fweights is not None:
pass
elif aweights is not None:
pass
else:
if not rowvar and x1.shape[0] != 1:
x1 = x1.get_array() if isinstance(x1, dpnp_array) else x1
x1 = dpnp_array._create_from_usm_ndarray(x1.mT)
x1 = dpnp.astype(x1, dpnp.float64) if x1_desc.dtype != dpnp.float64 else x1
x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False)
elif x1_desc.dtype != dpnp.float64:
x1 = dpnp.astype(x1, dpnp.float64)
x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False)

if not isinstance(x1, (dpnp_array, dpt.usm_ndarray)):
pass
elif x1.ndim > 2:
pass
elif y is not None:
pass
elif bias:
pass
elif ddof is not None:
pass
elif fweights is not None:
pass
elif aweights is not None:
pass
else:
if not rowvar and x1.shape[0] != 1:
x1 = x1.get_array() if isinstance(x1, dpnp_array) else x1
x1 = dpnp_array._create_from_usm_ndarray(x1.mT)

if not x1.dtype in (dpnp.float32, dpnp.float64):
x1 = dpnp.astype(x1, dpnp.default_float_type(sycl_queue=x1.sycl_queue))

x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False)
if x1_desc:
return dpnp_cov(x1_desc).get_pyobj()

return call_origin(numpy.cov, x1, y, rowvar, bias, ddof, fweights, aweights)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ def test_bincount_weights(self, array, weights):
numpy.testing.assert_array_equal(expected, result)

@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True))
def test_cov_rowvar1(dtype):
def test_cov_rowvar(dtype):
a = dpnp.array([[0, 2], [1, 1], [2, 0]], dtype=dtype)
b = numpy.array([[0, 2], [1, 1], [2, 0]], dtype=dtype)
numpy.testing.assert_array_equal(dpnp.cov(a.T), dpnp.cov(a,rowvar=False))
numpy.testing.assert_array_equal(numpy.cov(b,rowvar=False), dpnp.cov(a,rowvar=False))

@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True))
def test_cov_rowvar2(dtype):
def test_cov_1D_rowvar(dtype):
a = dpnp.array([[0, 1, 2]], dtype=dtype)
b = numpy.array([[0, 1, 2]], dtype=dtype)
numpy.testing.assert_array_equal(numpy.cov(b,rowvar=False), dpnp.cov(a,rowvar=False))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def generate_input(self, a_shape, y_shape, xp, dtype):
return a, y

@testing.for_all_dtypes()
@testing.numpy_cupy_allclose()
@testing.numpy_cupy_allclose(type_check=False)
def check(self, a_shape, y_shape=None, rowvar=True, bias=False,
ddof=None, xp=None, dtype=None):
a, y = self.generate_input(a_shape, y_shape, xp, dtype)
Expand Down