Skip to content

Commit 326a75e

Browse files
committed
fix_cov_for_no_fp64
1 parent 2dfa804 commit 326a75e

File tree

5 files changed

+32
-34
lines changed

5 files changed

+32
-34
lines changed

dpnp/backend/kernels/dpnp_krnl_statistics.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ DPCTLSyclEventRef dpnp_cov_c(DPCTLSyclQueueRef q_ref,
192192
nrows, // std::int64_t n,
193193
ncols, // std::int64_t k,
194194
alpha, // T alpha,
195-
temp, //const T* a,
195+
temp, // const T* a,
196196
ncols, // std::int64_t lda,
197197
beta, // T beta,
198198
result, // T* c,
@@ -1384,7 +1384,7 @@ void func_map_init_statistics(func_map_t& fmap)
13841384

13851385
fmap[DPNPFuncName::DPNP_FN_COV_EXT][eft_INT][eft_INT] = {eft_DBL, (void*)dpnp_cov_ext_c<double>};
13861386
fmap[DPNPFuncName::DPNP_FN_COV_EXT][eft_LNG][eft_LNG] = {eft_DBL, (void*)dpnp_cov_ext_c<double>};
1387-
fmap[DPNPFuncName::DPNP_FN_COV_EXT][eft_FLT][eft_FLT] = {eft_DBL, (void*)dpnp_cov_ext_c<double>};
1387+
fmap[DPNPFuncName::DPNP_FN_COV_EXT][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_cov_ext_c<float>};
13881388
fmap[DPNPFuncName::DPNP_FN_COV_EXT][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_cov_ext_c<double>};
13891389

13901390
fmap[DPNPFuncName::DPNP_FN_MAX][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_max_default_c<int32_t>};

dpnp/dpnp_algo/dpnp_algo_statistics.pxi

-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ cpdef utils.dpnp_descriptor dpnp_correlate(utils.dpnp_descriptor x1, utils.dpnp_
179179
return result
180180

181181

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

dpnp/dpnp_iface_statistics.py

+27-28
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242

4343
import numpy
44-
44+
import dpctl.tensor as dpt
4545
from dpnp.dpnp_algo import *
4646
from dpnp.dpnp_utils import *
4747
from dpnp.dpnp_array import dpnp_array
@@ -247,7 +247,7 @@ def cov(x1, y=None, rowvar=True, bias=False, ddof=None, fweights=None, aweights=
247247
Limitations
248248
-----------
249249
Input array ``m`` is supported as :obj:`dpnp.ndarray`.
250-
Dimension of input array ``m`` is limited by ``m.ndim > 2``.
250+
Dimension of input array ``m`` is limited by ``m.ndim <= 2``.
251251
Size and shape of input arrays are supported to be equal.
252252
Prameters ``y`` is supported only with default value ``None``.
253253
Prameters ``bias`` is supported only with default value ``False``.
@@ -257,7 +257,7 @@ def cov(x1, y=None, rowvar=True, bias=False, ddof=None, fweights=None, aweights=
257257
Otherwise the function will be executed sequentially on CPU.
258258
Input array data types are limited by supported DPNP :ref:`Data types`.
259259
260-
.. seealso:: :obj:`dpnp.corrcoef` normalized covariance matrix.
260+
.. see also:: :obj:`dpnp.corrcoef` normalized covariance matrix.
261261
262262
Examples
263263
--------
@@ -274,31 +274,30 @@ def cov(x1, y=None, rowvar=True, bias=False, ddof=None, fweights=None, aweights=
274274
[1.0, -1.0, -1.0, 1.0]
275275
276276
"""
277-
278-
x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False)
279-
if x1_desc:
280-
if x1_desc.ndim > 2:
281-
pass
282-
elif y is not None:
283-
pass
284-
elif bias:
285-
pass
286-
elif ddof is not None:
287-
pass
288-
elif fweights is not None:
289-
pass
290-
elif aweights is not None:
291-
pass
292-
else:
293-
if not rowvar and x1.shape[0] != 1:
294-
x1 = x1.get_array() if isinstance(x1, dpnp_array) else x1
295-
x1 = dpnp_array._create_from_usm_ndarray(x1.mT)
296-
x1 = dpnp.astype(x1, dpnp.float64) if x1_desc.dtype != dpnp.float64 else x1
297-
x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False)
298-
elif x1_desc.dtype != dpnp.float64:
299-
x1 = dpnp.astype(x1, dpnp.float64)
300-
x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False)
301-
277+
if not isinstance(x1, (dpnp_array, dpt.usm_ndarray)):
278+
pass
279+
elif x1.ndim > 2:
280+
pass
281+
elif y is not None:
282+
pass
283+
elif bias:
284+
pass
285+
elif ddof is not None:
286+
pass
287+
elif fweights is not None:
288+
pass
289+
elif aweights is not None:
290+
pass
291+
else:
292+
if not rowvar and x1.shape[0] != 1:
293+
x1 = x1.get_array() if isinstance(x1, dpnp_array) else x1
294+
x1 = dpnp_array._create_from_usm_ndarray(x1.mT)
295+
296+
if not x1.dtype in (dpnp.float32, dpnp.float64):
297+
x1 = dpnp.astype(x1, dpnp.default_float_type(sycl_queue=x1.sycl_queue))
298+
299+
x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False)
300+
if x1_desc:
302301
return dpnp_cov(x1_desc).get_pyobj()
303302

304303
return call_origin(numpy.cov, x1, y, rowvar, bias, ddof, fweights, aweights)

tests/test_statistics.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ def test_bincount_weights(self, array, weights):
116116
numpy.testing.assert_array_equal(expected, result)
117117

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

125125
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True))
126-
def test_cov_rowvar2(dtype):
126+
def test_cov_1D_rowvar(dtype):
127127
a = dpnp.array([[0, 1, 2]], dtype=dtype)
128128
b = numpy.array([[0, 1, 2]], dtype=dtype)
129129
numpy.testing.assert_array_equal(numpy.cov(b,rowvar=False), dpnp.cov(a,rowvar=False))

tests/third_party/cupy/statistics_tests/test_correlation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def generate_input(self, a_shape, y_shape, xp, dtype):
4848
return a, y
4949

5050
@testing.for_all_dtypes()
51-
@testing.numpy_cupy_allclose()
51+
@testing.numpy_cupy_allclose(type_check=False)
5252
def check(self, a_shape, y_shape=None, rowvar=True, bias=False,
5353
ddof=None, xp=None, dtype=None):
5454
a, y = self.generate_input(a_shape, y_shape, xp, dtype)

0 commit comments

Comments
 (0)