From f1ca919cd53e4a1c517a88de2c0e1d10b2e6b4be Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Fri, 21 Jul 2023 18:28:32 +0200 Subject: [PATCH 1/6] Update dpnp_median --- dpnp/backend/kernels/dpnp_krnl_statistics.cpp | 16 ++++++++++++++-- dpnp/dpnp_algo/dpnp_algo_statistics.pxi | 18 +++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/dpnp/backend/kernels/dpnp_krnl_statistics.cpp b/dpnp/backend/kernels/dpnp_krnl_statistics.cpp index 7d800d0ee26f..3e6ce24ab0c6 100644 --- a/dpnp/backend/kernels/dpnp_krnl_statistics.cpp +++ b/dpnp/backend/kernels/dpnp_krnl_statistics.cpp @@ -1330,9 +1330,21 @@ void func_map_init_statistics(func_map_t &fmap) eft_DBL, (void *)dpnp_median_default_c}; fmap[DPNPFuncName::DPNP_FN_MEDIAN_EXT][eft_INT][eft_INT] = { - eft_DBL, (void *)dpnp_median_ext_c}; + get_default_floating_type<>(), + (void *)dpnp_median_ext_c< + int32_t, func_type_map_t::find_type()>>, + get_default_floating_type(), + (void *)dpnp_median_ext_c< + int32_t, func_type_map_t::find_type< + get_default_floating_type()>>}; fmap[DPNPFuncName::DPNP_FN_MEDIAN_EXT][eft_LNG][eft_LNG] = { - eft_DBL, (void *)dpnp_median_ext_c}; + get_default_floating_type<>(), + (void *)dpnp_median_ext_c< + int64_t, func_type_map_t::find_type()>>, + get_default_floating_type(), + (void *)dpnp_median_ext_c< + int64_t, func_type_map_t::find_type< + get_default_floating_type()>>}; fmap[DPNPFuncName::DPNP_FN_MEDIAN_EXT][eft_FLT][eft_FLT] = { eft_FLT, (void *)dpnp_median_ext_c}; fmap[DPNPFuncName::DPNP_FN_MEDIAN_EXT][eft_DBL][eft_DBL] = { diff --git a/dpnp/dpnp_algo/dpnp_algo_statistics.pxi b/dpnp/dpnp_algo/dpnp_algo_statistics.pxi index 8baa93651ab3..401dbb616bc2 100644 --- a/dpnp/dpnp_algo/dpnp_algo_statistics.pxi +++ b/dpnp/dpnp_algo/dpnp_algo_statistics.pxi @@ -75,6 +75,16 @@ ctypedef c_dpctl.DPCTLSyclEventRef(*custom_statistic_1in_1out_func_ptr_t_max)(c_ const c_dpctl.DPCTLEventVectorRef) +cdef (DPNPFuncType, void *) get_ret_type_and_func(x1_obj, DPNPFuncData kernel_data): + if dpnp.issubdtype(x1_obj.dtype, dpnp.integer) and not x1_obj.sycl_device.has_aspect_fp64: + return_type = kernel_data.return_type_no_fp64 + func = kernel_data.ptr_no_fp64 + else: + return_type = kernel_data.return_type + func = kernel_data.ptr + return return_type, func + + cdef utils.dpnp_descriptor call_fptr_custom_std_var_1in_1out(DPNPFuncName fptr_name, utils.dpnp_descriptor x1, ddof): cdef shape_type_c x1_shape = x1.shape @@ -265,8 +275,12 @@ cpdef utils.dpnp_descriptor dpnp_median(utils.dpnp_descriptor array1): array1_obj = array1.get_array() + cdef (DPNPFuncType, void *) ret_type_and_func = get_ret_type_and_func(array1_obj, kernel_data) + cdef DPNPFuncType return_type = ret_type_and_func[0] + cdef custom_statistic_1in_1out_func_ptr_t func = < custom_statistic_1in_1out_func_ptr_t > ret_type_and_func[1] + cdef utils.dpnp_descriptor result = utils.create_output_descriptor((1,), - kernel_data.return_type, + return_type, None, device=array1_obj.sycl_device, usm_type=array1_obj.usm_type, @@ -277,8 +291,6 @@ cpdef utils.dpnp_descriptor dpnp_median(utils.dpnp_descriptor array1): cdef c_dpctl.SyclQueue q = result_sycl_queue cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - cdef custom_statistic_1in_1out_func_ptr_t func = kernel_data.ptr - # stub for interface support cdef shape_type_c axis cdef Py_ssize_t axis_size = 0 From 6665b9f6328c04127a8880069056dec943ed36fd Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Fri, 21 Jul 2023 20:05:28 +0200 Subject: [PATCH 2/6] Update dpnp_cov --- dpnp/dpnp_utils/dpnp_utils_statistics.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/dpnp/dpnp_utils/dpnp_utils_statistics.py b/dpnp/dpnp_utils/dpnp_utils_statistics.py index 3e8df0aa3cb2..a95eed644c8b 100644 --- a/dpnp/dpnp_utils/dpnp_utils_statistics.py +++ b/dpnp/dpnp_utils/dpnp_utils_statistics.py @@ -59,6 +59,11 @@ def _get_2dmin_array(x, dtype): It casts to another dtype, if the input array differs from requested one. """ + # dtype map for devices without double precision type support + dtype_map = { + dpnp.float64: dpnp.float32, + dpnp.complex128: dpnp.complex64, + } if x.ndim == 0: x = x.reshape((1, 1)) @@ -69,6 +74,10 @@ def _get_2dmin_array(x, dtype): x = x.T if x.dtype != dtype: + fp64 = x.sycl_device.has_aspect_fp64 + # TODO: remove when dpctl.result_type() is fixed + if not fp64: + dtype = dtype_map[dtype.type] x = dpnp.astype(x, dtype) return x From b79acb126aa6b9b82578bbde47fa669177e8ae6d Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Fri, 21 Jul 2023 20:37:31 +0200 Subject: [PATCH 3/6] Update test_statistics --- tests/test_statistics.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/tests/test_statistics.py b/tests/test_statistics.py index 38346cec90ec..4ae1c4ee0134 100644 --- a/tests/test_statistics.py +++ b/tests/test_statistics.py @@ -1,5 +1,6 @@ import numpy import pytest +from numpy.testing import assert_allclose import dpnp @@ -7,31 +8,30 @@ @pytest.mark.parametrize( - "type", - [numpy.float64, numpy.float32, numpy.int64, numpy.int32], - ids=["float64", "float32", "int64", "int32"], + "dtype", get_all_dtypes(no_none=True, no_bool=True, no_complex=True) ) @pytest.mark.parametrize("size", [2, 4, 8, 16, 3, 9, 27, 81]) -def test_median(type, size): - a = numpy.arange(size, dtype=type) +def test_median(dtype, size): + a = numpy.arange(size, dtype=dtype) ia = dpnp.array(a) np_res = numpy.median(a) dpnp_res = dpnp.median(ia) - numpy.testing.assert_allclose(dpnp_res, np_res) + assert_allclose(dpnp_res, np_res) @pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("axis", [0, 1, -1, 2, -2, (1, 2), (0, -2)]) def test_max(axis): - a = numpy.arange(768, dtype=numpy.float64).reshape((4, 4, 6, 8)) + dtype = dpnp.default_float_type() + a = numpy.arange(768, dtype=dtype).reshape((4, 4, 6, 8)) ia = dpnp.array(a) np_res = numpy.max(a, axis=axis) dpnp_res = dpnp.max(ia, axis=axis) - numpy.testing.assert_allclose(dpnp_res, np_res) + assert_allclose(dpnp_res, np_res) @pytest.mark.usefixtures("allow_fall_back_on_numpy") @@ -71,16 +71,17 @@ def test_max(axis): ], ) def test_nanvar(array): - a = numpy.array(array) + dtype = dpnp.default_float_type() + a = numpy.array(array, dtype=dtype) ia = dpnp.array(a) for ddof in range(a.ndim): expected = numpy.nanvar(a, ddof=ddof) result = dpnp.nanvar(ia, ddof=ddof) - numpy.testing.assert_array_equal(expected, result) + assert_allclose(expected, result, rtol=1e-06) expected = numpy.nanvar(a, axis=None, ddof=0) result = dpnp.nanvar(ia, axis=None, ddof=0) - numpy.testing.assert_array_equal(expected, result) + assert_allclose(expected, result, rtol=1e-06) @pytest.mark.usefixtures("allow_fall_back_on_numpy") @@ -99,7 +100,7 @@ def test_bincount_minlength(self, array, minlength): expected = numpy.bincount(np_a, minlength=minlength) result = dpnp.bincount(dpnp_a, minlength=minlength) - numpy.testing.assert_array_equal(expected, result) + assert_allclose(expected, result) @pytest.mark.parametrize( "array", [[1, 2, 2, 1, 2, 4]], ids=["[1, 2, 2, 1, 2, 4]"] @@ -115,7 +116,7 @@ def test_bincount_weights(self, array, weights): expected = numpy.bincount(np_a, weights=weights) result = dpnp.bincount(dpnp_a, weights=weights) - numpy.testing.assert_array_equal(expected, result) + assert_allclose(expected, result) @pytest.mark.parametrize( From 7c5c6c11db9220bcd3cb98cc3dc3d1bf6c7e4ece Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Mon, 24 Jul 2023 13:01:01 +0200 Subject: [PATCH 4/6] Move get_ret_type_and_func to dpnp_algo_utils --- dpnp/dpnp_algo/dpnp_algo_statistics.pxi | 12 +----------- dpnp/dpnp_utils/dpnp_algo_utils.pxd | 8 +++++++- dpnp/dpnp_utils/dpnp_algo_utils.pyx | 10 ++++++++++ dpnp/linalg/dpnp_algo_linalg.pyx | 20 +++++--------------- 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/dpnp/dpnp_algo/dpnp_algo_statistics.pxi b/dpnp/dpnp_algo/dpnp_algo_statistics.pxi index 401dbb616bc2..3ec3893c3acc 100644 --- a/dpnp/dpnp_algo/dpnp_algo_statistics.pxi +++ b/dpnp/dpnp_algo/dpnp_algo_statistics.pxi @@ -75,16 +75,6 @@ ctypedef c_dpctl.DPCTLSyclEventRef(*custom_statistic_1in_1out_func_ptr_t_max)(c_ const c_dpctl.DPCTLEventVectorRef) -cdef (DPNPFuncType, void *) get_ret_type_and_func(x1_obj, DPNPFuncData kernel_data): - if dpnp.issubdtype(x1_obj.dtype, dpnp.integer) and not x1_obj.sycl_device.has_aspect_fp64: - return_type = kernel_data.return_type_no_fp64 - func = kernel_data.ptr_no_fp64 - else: - return_type = kernel_data.return_type - func = kernel_data.ptr - return return_type, func - - cdef utils.dpnp_descriptor call_fptr_custom_std_var_1in_1out(DPNPFuncName fptr_name, utils.dpnp_descriptor x1, ddof): cdef shape_type_c x1_shape = x1.shape @@ -275,7 +265,7 @@ cpdef utils.dpnp_descriptor dpnp_median(utils.dpnp_descriptor array1): array1_obj = array1.get_array() - cdef (DPNPFuncType, void *) ret_type_and_func = get_ret_type_and_func(array1_obj, kernel_data) + cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(array1_obj, kernel_data) cdef DPNPFuncType return_type = ret_type_and_func[0] cdef custom_statistic_1in_1out_func_ptr_t func = < custom_statistic_1in_1out_func_ptr_t > ret_type_and_func[1] diff --git a/dpnp/dpnp_utils/dpnp_algo_utils.pxd b/dpnp/dpnp_utils/dpnp_algo_utils.pxd index 4a4488ca2692..7656d29bb15d 100644 --- a/dpnp/dpnp_utils/dpnp_algo_utils.pxd +++ b/dpnp/dpnp_utils/dpnp_algo_utils.pxd @@ -28,7 +28,7 @@ from libcpp cimport bool as cpp_bool from dpnp.dpnp_algo cimport shape_type_c -from dpnp.dpnp_algo.dpnp_algo cimport DPNPFuncName, DPNPFuncType +from dpnp.dpnp_algo.dpnp_algo cimport DPNPFuncData, DPNPFuncName, DPNPFuncType cpdef checker_throw_runtime_error(function_name, message) @@ -162,3 +162,9 @@ cdef tuple get_common_usm_allocation(dpnp_descriptor x1, dpnp_descriptor x2) """ Get common USM allocation in the form of (sycl_device, usm_type, sycl_queue) """ + +cdef (DPNPFuncType, void *) get_ret_type_and_func(x1_obj, DPNPFuncData kernel_data) +""" +Get the corresponding return type and function pointer based on the +capability of the allocated input array device for the integer types. +""" diff --git a/dpnp/dpnp_utils/dpnp_algo_utils.pyx b/dpnp/dpnp_utils/dpnp_algo_utils.pyx index b69bceea9e63..db052be7827a 100644 --- a/dpnp/dpnp_utils/dpnp_algo_utils.pyx +++ b/dpnp/dpnp_utils/dpnp_algo_utils.pyx @@ -663,6 +663,16 @@ cdef tuple get_common_usm_allocation(dpnp_descriptor x1, dpnp_descriptor x2): return (common_sycl_queue.sycl_device, common_usm_type, common_sycl_queue) +cdef (DPNPFuncType, void *) get_ret_type_and_func(x1_obj, DPNPFuncData kernel_data): + if dpnp.issubdtype(x1_obj.dtype, dpnp.integer) and not x1_obj.sycl_device.has_aspect_fp64: + return_type = kernel_data.return_type_no_fp64 + func = kernel_data.ptr_no_fp64 + else: + return_type = kernel_data.return_type + func = kernel_data.ptr + return return_type, func + + cdef class dpnp_descriptor: def __init__(self, obj, dpnp_descriptor orig_desc=None): """ Initialze variables """ diff --git a/dpnp/linalg/dpnp_algo_linalg.pyx b/dpnp/linalg/dpnp_algo_linalg.pyx index eeb9bf7f5f8b..e6484599c51e 100644 --- a/dpnp/linalg/dpnp_algo_linalg.pyx +++ b/dpnp/linalg/dpnp_algo_linalg.pyx @@ -79,16 +79,6 @@ ctypedef c_dpctl.DPCTLSyclEventRef(*custom_linalg_2in_1out_func_ptr_t)(c_dpctl.D const c_dpctl.DPCTLEventVectorRef) -cdef (DPNPFuncType, void *) get_ret_type_and_func(x1_obj, DPNPFuncData kernel_data): - if dpnp.issubdtype(x1_obj.dtype, dpnp.integer) and not x1_obj.sycl_device.has_aspect_fp64: - return_type = kernel_data.return_type_no_fp64 - func = kernel_data.ptr_no_fp64 - else: - return_type = kernel_data.return_type - func = kernel_data.ptr - return return_type, func - - cpdef utils.dpnp_descriptor dpnp_cholesky(utils.dpnp_descriptor input_): size_ = input_.shape[-1] @@ -206,7 +196,7 @@ cpdef tuple dpnp_eig(utils.dpnp_descriptor x1): x1_obj = x1.get_array() - cdef (DPNPFuncType, void *) ret_type_and_func = get_ret_type_and_func(x1_obj, kernel_data) + cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(x1_obj, kernel_data) cdef DPNPFuncType return_type = ret_type_and_func[0] cdef custom_linalg_2in_1out_func_ptr_t func = < custom_linalg_2in_1out_func_ptr_t > ret_type_and_func[1] @@ -252,7 +242,7 @@ cpdef utils.dpnp_descriptor dpnp_eigvals(utils.dpnp_descriptor input): input_obj = input.get_array() - cdef (DPNPFuncType, void *) ret_type_and_func = get_ret_type_and_func(input_obj, kernel_data) + cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(input_obj, kernel_data) cdef DPNPFuncType return_type = ret_type_and_func[0] cdef custom_linalg_1in_1out_with_size_func_ptr_t_ func = < custom_linalg_1in_1out_with_size_func_ptr_t_ > ret_type_and_func[1] @@ -291,7 +281,7 @@ cpdef utils.dpnp_descriptor dpnp_inv(utils.dpnp_descriptor input): input_obj = input.get_array() - cdef (DPNPFuncType, void *) ret_type_and_func = get_ret_type_and_func(input_obj, kernel_data) + cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(input_obj, kernel_data) cdef DPNPFuncType return_type = ret_type_and_func[0] cdef custom_linalg_1in_1out_func_ptr_t func = < custom_linalg_1in_1out_func_ptr_t > ret_type_and_func[1] @@ -472,7 +462,7 @@ cpdef tuple dpnp_qr(utils.dpnp_descriptor x1, str mode): x1_obj = x1.get_array() - cdef (DPNPFuncType, void *) ret_type_and_func = get_ret_type_and_func(x1_obj, kernel_data) + cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(x1_obj, kernel_data) cdef DPNPFuncType return_type = ret_type_and_func[0] cdef custom_linalg_1in_3out_shape_t func = < custom_linalg_1in_3out_shape_t > ret_type_and_func[1] @@ -525,7 +515,7 @@ cpdef tuple dpnp_svd(utils.dpnp_descriptor x1, cpp_bool full_matrices, cpp_bool x1_obj = x1.get_array() - cdef (DPNPFuncType, void *) ret_type_and_func = get_ret_type_and_func(x1_obj, kernel_data) + cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(x1_obj, kernel_data) cdef DPNPFuncType return_type = ret_type_and_func[0] cdef custom_linalg_1in_3out_shape_t func = < custom_linalg_1in_3out_shape_t > ret_type_and_func[1] From 70b38f3cc930b88747a8d28f2e97631fd27c00d5 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Mon, 24 Jul 2023 15:39:23 +0200 Subject: [PATCH 5/6] Call get_default_floating_type without <> --- dpnp/backend/kernels/dpnp_krnl_common.cpp | 16 +++++------ dpnp/backend/kernels/dpnp_krnl_linalg.cpp | 28 +++++++++---------- dpnp/backend/kernels/dpnp_krnl_statistics.cpp | 8 +++--- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/dpnp/backend/kernels/dpnp_krnl_common.cpp b/dpnp/backend/kernels/dpnp_krnl_common.cpp index 84107d293ac0..bf3102bd7cde 100644 --- a/dpnp/backend/kernels/dpnp_krnl_common.cpp +++ b/dpnp/backend/kernels/dpnp_krnl_common.cpp @@ -1167,17 +1167,17 @@ void func_map_init_linalg(func_map_t &fmap) eft_DBL, (void *)dpnp_eig_default_c}; fmap[DPNPFuncName::DPNP_FN_EIG_EXT][eft_INT][eft_INT] = { - get_default_floating_type<>(), + get_default_floating_type(), (void *)dpnp_eig_ext_c< - int32_t, func_type_map_t::find_type()>>, + int32_t, func_type_map_t::find_type>, get_default_floating_type(), (void *)dpnp_eig_ext_c< int32_t, func_type_map_t::find_type< get_default_floating_type()>>}; fmap[DPNPFuncName::DPNP_FN_EIG_EXT][eft_LNG][eft_LNG] = { - get_default_floating_type<>(), + get_default_floating_type(), (void *)dpnp_eig_ext_c< - int64_t, func_type_map_t::find_type()>>, + int64_t, func_type_map_t::find_type>, get_default_floating_type(), (void *)dpnp_eig_ext_c< int64_t, func_type_map_t::find_type< @@ -1197,17 +1197,17 @@ void func_map_init_linalg(func_map_t &fmap) eft_DBL, (void *)dpnp_eigvals_default_c}; fmap[DPNPFuncName::DPNP_FN_EIGVALS_EXT][eft_INT][eft_INT] = { - get_default_floating_type<>(), + get_default_floating_type(), (void *)dpnp_eigvals_ext_c< - int32_t, func_type_map_t::find_type()>>, + int32_t, func_type_map_t::find_type>, get_default_floating_type(), (void *)dpnp_eigvals_ext_c< int32_t, func_type_map_t::find_type< get_default_floating_type()>>}; fmap[DPNPFuncName::DPNP_FN_EIGVALS_EXT][eft_LNG][eft_LNG] = { - get_default_floating_type<>(), + get_default_floating_type(), (void *)dpnp_eigvals_ext_c< - int64_t, func_type_map_t::find_type()>>, + int64_t, func_type_map_t::find_type>, get_default_floating_type(), (void *)dpnp_eigvals_ext_c< int64_t, func_type_map_t::find_type< diff --git a/dpnp/backend/kernels/dpnp_krnl_linalg.cpp b/dpnp/backend/kernels/dpnp_krnl_linalg.cpp index b83295aa8948..8b47f38f9a41 100644 --- a/dpnp/backend/kernels/dpnp_krnl_linalg.cpp +++ b/dpnp/backend/kernels/dpnp_krnl_linalg.cpp @@ -879,17 +879,17 @@ void func_map_init_linalg_func(func_map_t &fmap) eft_DBL, (void *)dpnp_inv_default_c}; fmap[DPNPFuncName::DPNP_FN_INV_EXT][eft_INT][eft_INT] = { - get_default_floating_type<>(), + get_default_floating_type(), (void *)dpnp_inv_ext_c< - int32_t, func_type_map_t::find_type()>>, + int32_t, func_type_map_t::find_type>, get_default_floating_type(), (void *)dpnp_inv_ext_c< int32_t, func_type_map_t::find_type< get_default_floating_type()>>}; fmap[DPNPFuncName::DPNP_FN_INV_EXT][eft_LNG][eft_LNG] = { - get_default_floating_type<>(), + get_default_floating_type(), (void *)dpnp_inv_ext_c< - int64_t, func_type_map_t::find_type()>>, + int64_t, func_type_map_t::find_type>, get_default_floating_type(), (void *)dpnp_inv_ext_c< int64_t, func_type_map_t::find_type< @@ -1051,17 +1051,17 @@ void func_map_init_linalg_func(func_map_t &fmap) // eft_C128, (void*)dpnp_qr_c, std::complex>}; fmap[DPNPFuncName::DPNP_FN_QR_EXT][eft_INT][eft_INT] = { - get_default_floating_type<>(), + get_default_floating_type(), (void *)dpnp_qr_ext_c< - int32_t, func_type_map_t::find_type()>>, + int32_t, func_type_map_t::find_type>, get_default_floating_type(), (void *)dpnp_qr_ext_c< int32_t, func_type_map_t::find_type< get_default_floating_type()>>}; fmap[DPNPFuncName::DPNP_FN_QR_EXT][eft_LNG][eft_LNG] = { - get_default_floating_type<>(), + get_default_floating_type(), (void *)dpnp_qr_ext_c< - int64_t, func_type_map_t::find_type()>>, + int64_t, func_type_map_t::find_type>, get_default_floating_type(), (void *)dpnp_qr_ext_c< int64_t, func_type_map_t::find_type< @@ -1086,10 +1086,10 @@ void func_map_init_linalg_func(func_map_t &fmap) std::complex, double>}; fmap[DPNPFuncName::DPNP_FN_SVD_EXT][eft_INT][eft_INT] = { - get_default_floating_type<>(), + get_default_floating_type(), (void *)dpnp_svd_ext_c< - int32_t, func_type_map_t::find_type()>, - func_type_map_t::find_type()>>, + int32_t, func_type_map_t::find_type, + func_type_map_t::find_type>, get_default_floating_type(), (void *) dpnp_svd_ext_c()>>}; fmap[DPNPFuncName::DPNP_FN_SVD_EXT][eft_LNG][eft_LNG] = { - get_default_floating_type<>(), + get_default_floating_type(), (void *)dpnp_svd_ext_c< - int64_t, func_type_map_t::find_type()>, - func_type_map_t::find_type()>>, + int64_t, func_type_map_t::find_type, + func_type_map_t::find_type>, get_default_floating_type(), (void *) dpnp_svd_ext_c}; fmap[DPNPFuncName::DPNP_FN_MEDIAN_EXT][eft_INT][eft_INT] = { - get_default_floating_type<>(), + get_default_floating_type(), (void *)dpnp_median_ext_c< - int32_t, func_type_map_t::find_type()>>, + int32_t, func_type_map_t::find_type>, get_default_floating_type(), (void *)dpnp_median_ext_c< int32_t, func_type_map_t::find_type< get_default_floating_type()>>}; fmap[DPNPFuncName::DPNP_FN_MEDIAN_EXT][eft_LNG][eft_LNG] = { - get_default_floating_type<>(), + get_default_floating_type(), (void *)dpnp_median_ext_c< - int64_t, func_type_map_t::find_type()>>, + int64_t, func_type_map_t::find_type>, get_default_floating_type(), (void *)dpnp_median_ext_c< int64_t, func_type_map_t::find_type< From 618f2fb67f2205f6c0a91778fba5d76ddaea3b45 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Mon, 24 Jul 2023 16:14:59 +0200 Subject: [PATCH 6/6] Fix remarks --- dpnp/dpnp_utils/dpnp_utils_statistics.py | 17 +++++++---------- tests/test_statistics.py | 21 +++++++++++---------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/dpnp/dpnp_utils/dpnp_utils_statistics.py b/dpnp/dpnp_utils/dpnp_utils_statistics.py index a95eed644c8b..e8ccb1794682 100644 --- a/dpnp/dpnp_utils/dpnp_utils_statistics.py +++ b/dpnp/dpnp_utils/dpnp_utils_statistics.py @@ -59,12 +59,6 @@ def _get_2dmin_array(x, dtype): It casts to another dtype, if the input array differs from requested one. """ - # dtype map for devices without double precision type support - dtype_map = { - dpnp.float64: dpnp.float32, - dpnp.complex128: dpnp.complex64, - } - if x.ndim == 0: x = x.reshape((1, 1)) elif x.ndim == 1: @@ -74,10 +68,6 @@ def _get_2dmin_array(x, dtype): x = x.T if x.dtype != dtype: - fp64 = x.sycl_device.has_aspect_fp64 - # TODO: remove when dpctl.result_type() is fixed - if not fp64: - dtype = dtype_map[dtype.type] x = dpnp.astype(x, dtype) return x @@ -90,6 +80,13 @@ def _get_2dmin_array(x, dtype): if y is not None: dtypes.append(y.dtype) dtype = dpt.result_type(*dtypes) + # TODO: remove when dpctl.result_type() is fixed + fp64 = queue.sycl_device.has_aspect_fp64 + if not fp64: + if dtype == dpnp.float64: + dtype = dpnp.float32 + elif dtype == dpnp.complex128: + dtype = dpnp.complex64 X = _get_2dmin_array(m, dtype) if y is not None: diff --git a/tests/test_statistics.py b/tests/test_statistics.py index 4ae1c4ee0134..4020c6c21d72 100644 --- a/tests/test_statistics.py +++ b/tests/test_statistics.py @@ -23,8 +23,10 @@ def test_median(dtype, size): @pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("axis", [0, 1, -1, 2, -2, (1, 2), (0, -2)]) -def test_max(axis): - dtype = dpnp.default_float_type() +@pytest.mark.parametrize( + "dtype", get_all_dtypes(no_none=True, no_bool=True, no_complex=True) +) +def test_max(axis, dtype): a = numpy.arange(768, dtype=dtype).reshape((4, 4, 6, 8)) ia = dpnp.array(a) @@ -70,7 +72,10 @@ def test_max(axis): "[[np.nan, np.nan], [np.inf, np.nan]]", ], ) -def test_nanvar(array): +@pytest.mark.parametrize( + "dtype", get_all_dtypes(no_none=True, no_bool=True, no_complex=True) +) +def test_nanvar(array, dtype): dtype = dpnp.default_float_type() a = numpy.array(array, dtype=dtype) ia = dpnp.array(a) @@ -125,10 +130,8 @@ def test_bincount_weights(self, array, weights): 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) - ) + assert_allclose(dpnp.cov(a.T), dpnp.cov(a, rowvar=False)) + assert_allclose(numpy.cov(b, rowvar=False), dpnp.cov(a, rowvar=False)) @pytest.mark.parametrize( @@ -137,6 +140,4 @@ def test_cov_rowvar(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) - ) + assert_allclose(numpy.cov(b, rowvar=False), dpnp.cov(a, rowvar=False))