diff --git a/dpnp/backend/kernels/dpnp_krnl_common.cpp b/dpnp/backend/kernels/dpnp_krnl_common.cpp index 15defa1f842..7c6c0de540c 100644 --- a/dpnp/backend/kernels/dpnp_krnl_common.cpp +++ b/dpnp/backend/kernels/dpnp_krnl_common.cpp @@ -1152,9 +1152,21 @@ 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] = { - eft_DBL, (void *)dpnp_eig_ext_c}; + get_default_floating_type<>(), + (void *)dpnp_eig_ext_c< + 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] = { - eft_DBL, (void *)dpnp_eig_ext_c}; + get_default_floating_type<>(), + (void *)dpnp_eig_ext_c< + 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< + get_default_floating_type()>>}; fmap[DPNPFuncName::DPNP_FN_EIG_EXT][eft_FLT][eft_FLT] = { eft_FLT, (void *)dpnp_eig_ext_c}; fmap[DPNPFuncName::DPNP_FN_EIG_EXT][eft_DBL][eft_DBL] = { @@ -1170,9 +1182,21 @@ 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] = { - eft_DBL, (void *)dpnp_eigvals_ext_c}; + get_default_floating_type<>(), + (void *)dpnp_eigvals_ext_c< + 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] = { - eft_DBL, (void *)dpnp_eigvals_ext_c}; + get_default_floating_type<>(), + (void *)dpnp_eigvals_ext_c< + 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< + get_default_floating_type()>>}; fmap[DPNPFuncName::DPNP_FN_EIGVALS_EXT][eft_FLT][eft_FLT] = { eft_FLT, (void *)dpnp_eigvals_ext_c}; fmap[DPNPFuncName::DPNP_FN_EIGVALS_EXT][eft_DBL][eft_DBL] = { diff --git a/dpnp/backend/kernels/dpnp_krnl_linalg.cpp b/dpnp/backend/kernels/dpnp_krnl_linalg.cpp index f106a7bddc6..b83295aa894 100644 --- a/dpnp/backend/kernels/dpnp_krnl_linalg.cpp +++ b/dpnp/backend/kernels/dpnp_krnl_linalg.cpp @@ -874,16 +874,28 @@ void func_map_init_linalg_func(func_map_t &fmap) fmap[DPNPFuncName::DPNP_FN_INV][eft_LNG][eft_LNG] = { eft_DBL, (void *)dpnp_inv_default_c}; fmap[DPNPFuncName::DPNP_FN_INV][eft_FLT][eft_FLT] = { - eft_DBL, (void *)dpnp_inv_default_c}; + eft_DBL, (void *)dpnp_inv_default_c}; fmap[DPNPFuncName::DPNP_FN_INV][eft_DBL][eft_DBL] = { eft_DBL, (void *)dpnp_inv_default_c}; fmap[DPNPFuncName::DPNP_FN_INV_EXT][eft_INT][eft_INT] = { - eft_DBL, (void *)dpnp_inv_ext_c}; + get_default_floating_type<>(), + (void *)dpnp_inv_ext_c< + 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] = { - eft_DBL, (void *)dpnp_inv_ext_c}; + get_default_floating_type<>(), + (void *)dpnp_inv_ext_c< + 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< + get_default_floating_type()>>}; fmap[DPNPFuncName::DPNP_FN_INV_EXT][eft_FLT][eft_FLT] = { - eft_DBL, (void *)dpnp_inv_ext_c}; + eft_FLT, (void *)dpnp_inv_ext_c}; fmap[DPNPFuncName::DPNP_FN_INV_EXT][eft_DBL][eft_DBL] = { eft_DBL, (void *)dpnp_inv_ext_c}; @@ -1039,9 +1051,21 @@ 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] = { - eft_DBL, (void *)dpnp_qr_ext_c}; + get_default_floating_type<>(), + (void *)dpnp_qr_ext_c< + 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] = { - eft_DBL, (void *)dpnp_qr_ext_c}; + get_default_floating_type<>(), + (void *)dpnp_qr_ext_c< + 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< + get_default_floating_type()>>}; fmap[DPNPFuncName::DPNP_FN_QR_EXT][eft_FLT][eft_FLT] = { eft_FLT, (void *)dpnp_qr_ext_c}; fmap[DPNPFuncName::DPNP_FN_QR_EXT][eft_DBL][eft_DBL] = { @@ -1062,9 +1086,29 @@ void func_map_init_linalg_func(func_map_t &fmap) std::complex, double>}; fmap[DPNPFuncName::DPNP_FN_SVD_EXT][eft_INT][eft_INT] = { - eft_DBL, (void *)dpnp_svd_ext_c}; + get_default_floating_type<>(), + (void *)dpnp_svd_ext_c< + int32_t, func_type_map_t::find_type()>, + func_type_map_t::find_type()>>, + get_default_floating_type(), + (void *) + dpnp_svd_ext_c()>, + func_type_map_t::find_type< + get_default_floating_type()>>}; fmap[DPNPFuncName::DPNP_FN_SVD_EXT][eft_LNG][eft_LNG] = { - eft_DBL, (void *)dpnp_svd_ext_c}; + get_default_floating_type<>(), + (void *)dpnp_svd_ext_c< + int64_t, func_type_map_t::find_type()>, + func_type_map_t::find_type()>>, + get_default_floating_type(), + (void *) + dpnp_svd_ext_c()>, + func_type_map_t::find_type< + get_default_floating_type()>>}; fmap[DPNPFuncName::DPNP_FN_SVD_EXT][eft_FLT][eft_FLT] = { eft_FLT, (void *)dpnp_svd_ext_c}; fmap[DPNPFuncName::DPNP_FN_SVD_EXT][eft_DBL][eft_DBL] = { diff --git a/dpnp/backend/src/dpnp_fptr.hpp b/dpnp/backend/src/dpnp_fptr.hpp index 2502aba646b..446083204fc 100644 --- a/dpnp/backend/src/dpnp_fptr.hpp +++ b/dpnp/backend/src/dpnp_fptr.hpp @@ -260,6 +260,17 @@ class dpnp_less_comp } }; +/** + * A template function that determines the default floating-point type + * based on the value of the template parameter has_fp64. + */ +template +static constexpr DPNPFuncType get_default_floating_type() +{ + return has_fp64::value ? DPNPFuncType::DPNP_FT_DOUBLE + : DPNPFuncType::DPNP_FT_FLOAT; +} + /** * FPTR interface initialization functions */ diff --git a/dpnp/dpnp_algo/dpnp_algo.pxd b/dpnp/dpnp_algo/dpnp_algo.pxd index dd1cdbd09d2..b56557f75c8 100644 --- a/dpnp/dpnp_algo/dpnp_algo.pxd +++ b/dpnp/dpnp_algo/dpnp_algo.pxd @@ -336,6 +336,8 @@ cdef extern from "dpnp_iface_fptr.hpp": struct DPNPFuncData: DPNPFuncType return_type void * ptr + DPNPFuncType return_type_no_fp64 + void *ptr_no_fp64 DPNPFuncData get_dpnp_function_ptr(DPNPFuncName name, DPNPFuncType first_type, DPNPFuncType second_type) except + diff --git a/dpnp/linalg/dpnp_algo_linalg.pyx b/dpnp/linalg/dpnp_algo_linalg.pyx index 69a3efa223f..eeb9bf7f5f8 100644 --- a/dpnp/linalg/dpnp_algo_linalg.pyx +++ b/dpnp/linalg/dpnp_algo_linalg.pyx @@ -79,6 +79,16 @@ 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] @@ -194,18 +204,20 @@ cpdef tuple dpnp_eig(utils.dpnp_descriptor x1): cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(x1.dtype) cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_EIG_EXT, param1_type, param1_type) - result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type) - x1_obj = x1.get_array() + cdef (DPNPFuncType, void *) ret_type_and_func = 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] + cdef utils.dpnp_descriptor res_val = utils.create_output_descriptor((size,), - kernel_data.return_type, + return_type, None, device=x1_obj.sycl_device, usm_type=x1_obj.usm_type, sycl_queue=x1_obj.sycl_queue) cdef utils.dpnp_descriptor res_vec = utils.create_output_descriptor(x1_shape, - kernel_data.return_type, + return_type, None, device=x1_obj.sycl_device, usm_type=x1_obj.usm_type, @@ -216,7 +228,6 @@ cpdef tuple dpnp_eig(utils.dpnp_descriptor x1): cdef c_dpctl.SyclQueue q = result_sycl_queue cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - cdef custom_linalg_2in_1out_func_ptr_t func = kernel_data.ptr # call FPTR function cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, x1.get_data(), @@ -241,9 +252,13 @@ 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 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] + # ceate result array with type given by FPTR data cdef utils.dpnp_descriptor res_val = utils.create_output_descriptor((size,), - kernel_data.return_type, + return_type, None, device=input_obj.sycl_device, usm_type=input_obj.usm_type, @@ -254,7 +269,6 @@ cpdef utils.dpnp_descriptor dpnp_eigvals(utils.dpnp_descriptor input): cdef c_dpctl.SyclQueue q = result_sycl_queue cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - cdef custom_linalg_1in_1out_with_size_func_ptr_t_ func = kernel_data.ptr # call FPTR function cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, input.get_data(), @@ -277,9 +291,13 @@ 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 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] + # ceate result array with type given by FPTR data cdef utils.dpnp_descriptor result = utils.create_output_descriptor(input_shape, - kernel_data.return_type, + return_type, None, device=input_obj.sycl_device, usm_type=input_obj.usm_type, @@ -290,8 +308,6 @@ cpdef utils.dpnp_descriptor dpnp_inv(utils.dpnp_descriptor input): cdef c_dpctl.SyclQueue q = result_sycl_queue cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - cdef custom_linalg_1in_1out_func_ptr_t func = kernel_data.ptr - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, input.get_data(), result.get_data(), @@ -345,7 +361,8 @@ cpdef object dpnp_norm(object input, ord=None, axis=None): cdef long size_input = input.size cdef shape_type_c shape_input = input.shape - if input.dtype == dpnp.float32: + dev = input.get_array().sycl_device + if input.dtype == dpnp.float32 or not dev.has_aspect_fp64: res_type = dpnp.float32 else: res_type = dpnp.float64 @@ -366,7 +383,7 @@ cpdef object dpnp_norm(object input, ord=None, axis=None): input = dpnp.ravel(input, order='K') sqnorm = dpnp.dot(input, input) - ret = dpnp.sqrt(sqnorm) + ret = dpnp.sqrt([sqnorm], dtype=res_type) return dpnp.array(ret.reshape(1, *ret.shape), dtype=res_type) len_axis = 1 if axis is None else len(axis_) @@ -379,7 +396,7 @@ cpdef object dpnp_norm(object input, ord=None, axis=None): return input.dtype.type(dpnp.count_nonzero(input, axis=axis)) elif ord is None or ord == 2: s = input * input - return dpnp.sqrt(dpnp.sum(s, axis=axis)) + return dpnp.sqrt(dpnp.sum(s, axis=axis), dtype=res_type) elif isinstance(ord, str): raise ValueError(f"Invalid norm order '{ord}' for vectors") else: @@ -455,20 +472,24 @@ 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 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] + cdef utils.dpnp_descriptor res_q = utils.create_output_descriptor((size_m, min_m_n), - kernel_data.return_type, + return_type, None, device=x1_obj.sycl_device, usm_type=x1_obj.usm_type, sycl_queue=x1_obj.sycl_queue) cdef utils.dpnp_descriptor res_r = utils.create_output_descriptor((min_m_n, size_n), - kernel_data.return_type, + return_type, None, device=x1_obj.sycl_device, usm_type=x1_obj.usm_type, sycl_queue=x1_obj.sycl_queue) cdef utils.dpnp_descriptor tau = utils.create_output_descriptor((size_tau, ), - kernel_data.return_type, + return_type, None, device=x1_obj.sycl_device, usm_type=x1_obj.usm_type, @@ -479,8 +500,6 @@ cpdef tuple dpnp_qr(utils.dpnp_descriptor x1, str mode): cdef c_dpctl.SyclQueue q = result_sycl_queue cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - cdef custom_linalg_1in_3out_shape_t func = < custom_linalg_1in_3out_shape_t > kernel_data.ptr - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, x1.get_data(), res_q.get_data(), @@ -504,26 +523,26 @@ cpdef tuple dpnp_svd(utils.dpnp_descriptor x1, cpp_bool full_matrices, cpp_bool cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(x1.dtype) cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_SVD_EXT, param1_type, param1_type) - cdef DPNPFuncType type_s = DPNP_FT_DOUBLE - if x1.dtype == dpnp.float32: - type_s = DPNP_FT_FLOAT - x1_obj = x1.get_array() + cdef (DPNPFuncType, void *) ret_type_and_func = 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] + cdef utils.dpnp_descriptor res_u = utils.create_output_descriptor((size_m, size_m), - kernel_data.return_type, + return_type, None, device=x1_obj.sycl_device, usm_type=x1_obj.usm_type, sycl_queue=x1_obj.sycl_queue) cdef utils.dpnp_descriptor res_s = utils.create_output_descriptor((size_s, ), - type_s, + return_type, None, device=x1_obj.sycl_device, usm_type=x1_obj.usm_type, sycl_queue=x1_obj.sycl_queue) cdef utils.dpnp_descriptor res_vt = utils.create_output_descriptor((size_n, size_n), - kernel_data.return_type, + return_type, None, device=x1_obj.sycl_device, usm_type=x1_obj.usm_type, @@ -534,8 +553,6 @@ cpdef tuple dpnp_svd(utils.dpnp_descriptor x1, cpp_bool full_matrices, cpp_bool cdef c_dpctl.SyclQueue q = result_sycl_queue cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - cdef custom_linalg_1in_3out_shape_t func = < custom_linalg_1in_3out_shape_t > kernel_data.ptr - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, x1.get_data(), res_u.get_data(), diff --git a/dpnp/linalg/dpnp_iface_linalg.py b/dpnp/linalg/dpnp_iface_linalg.py index 0b96df5e141..3addcdc3258 100644 --- a/dpnp/linalg/dpnp_iface_linalg.py +++ b/dpnp/linalg/dpnp_iface_linalg.py @@ -97,9 +97,14 @@ def cholesky(input): pass else: if input.dtype == dpnp.int32 or input.dtype == dpnp.int64: + dev = x1_desc.get_array().sycl_device + if dev.has_aspect_fp64: + dtype = dpnp.float64 + else: + dtype = dpnp.float32 # TODO memory copy. needs to move into DPNPC input_ = dpnp.get_dpnp_descriptor( - dpnp.astype(input, dpnp.float64), + dpnp.astype(input, dtype=dtype), copy_when_nondefault_queue=False, ) else: diff --git a/tests/skipped_tests.tbl b/tests/skipped_tests.tbl index fca5fcad52a..d5eab8dc75c 100644 --- a/tests/skipped_tests.tbl +++ b/tests/skipped_tests.tbl @@ -76,22 +76,18 @@ tests/test_dparray.py::test_astype[[]-complex-int32] tests/test_dparray.py::test_astype[[]-complex-bool] tests/test_dparray.py::test_astype[[]-complex-complex] -tests/test_linalg.py::test_cond[None-[[1, 0, -1], [0, 1, 0], [1, 0, 1]]] -tests/test_linalg.py::test_cond[None-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] -tests/test_linalg.py::test_cond[1-[[1, 0, -1], [0, 1, 0], [1, 0, 1]]] -tests/test_linalg.py::test_cond[1-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] -tests/test_linalg.py::test_cond[-1-[[1, 0, -1], [0, 1, 0], [1, 0, 1]]] tests/test_linalg.py::test_cond[-1-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] -tests/test_linalg.py::test_cond[2-[[1, 0, -1], [0, 1, 0], [1, 0, 1]]] -tests/test_linalg.py::test_cond[2-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] +tests/test_linalg.py::test_cond[1-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] tests/test_linalg.py::test_cond[-2-[[1, 0, -1], [0, 1, 0], [1, 0, 1]]] +tests/test_linalg.py::test_cond[2-[[1, 0, -1], [0, 1, 0], [1, 0, 1]]] tests/test_linalg.py::test_cond[-2-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] -tests/test_linalg.py::test_cond[numpy.inf-[[1, 0, -1], [0, 1, 0], [1, 0, 1]]] -tests/test_linalg.py::test_cond[numpy.inf-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] -tests/test_linalg.py::test_cond[-numpy.inf-[[1, 0, -1], [0, 1, 0], [1, 0, 1]]] -tests/test_linalg.py::test_cond[-numpy.inf-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] +tests/test_linalg.py::test_cond[2-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] tests/test_linalg.py::test_cond["fro"-[[1, 0, -1], [0, 1, 0], [1, 0, 1]]] tests/test_linalg.py::test_cond["fro"-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] +tests/test_linalg.py::test_cond[None-[[1, 0, -1], [0, 1, 0], [1, 0, 1]]] +tests/test_linalg.py::test_cond[None-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] +tests/test_linalg.py::test_cond[-numpy.inf-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] +tests/test_linalg.py::test_cond[numpy.inf-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] tests/test_linalg.py::test_matrix_rank[None-[0, 1]-float64] tests/test_linalg.py::test_matrix_rank[None-[0, 1]-float32] @@ -116,79 +112,6 @@ tests/test_linalg.py::test_norm1[None-3-[7]] tests/test_linalg.py::test_norm1[None-3-[1, 2]] tests/test_linalg.py::test_norm1[None-3-[1, 0]] -tests/test_linalg.py::test_norm2[(0, 1)-None-[[1, 0]]] -tests/test_linalg.py::test_norm2[(0, 1)-None-[[1, 2]]] -tests/test_linalg.py::test_norm2[(0, 1)-None-[[1, 0], [3, 0]]] -tests/test_linalg.py::test_norm2[(0, 1)-None-[[1, 2], [3, 4]]] -tests/test_linalg.py::test_norm2[(0, 1)-"fro"-[[1, 0]]] -tests/test_linalg.py::test_norm2[(0, 1)-"fro"-[[1, 2]]] -tests/test_linalg.py::test_norm2[(0, 1)-"fro"-[[1, 0], [3, 0]]] -tests/test_linalg.py::test_norm2[(0, 1)-"fro"-[[1, 2], [3, 4]]] -tests/test_linalg.py::test_norm2[None-None-[[1, 2]]] -tests/test_linalg.py::test_norm2[None-None-[[1, 0], [3, 0]]] -tests/test_linalg.py::test_norm2[None-None-[[1, 2], [3, 4]]] -tests/test_linalg.py::test_norm2[None-"fro"-[[1, 2]]] -tests/test_linalg.py::test_norm2[None-"fro"-[[1, 0], [3, 0]]] -tests/test_linalg.py::test_norm2[None-"fro"-[[1, 2], [3, 4]]] - -tests/test_linalg.py::test_norm3[0-None-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[0-None-[[[1, 0], [3, 0]], [[5, 0], [7, 0]]]] -tests/test_linalg.py::test_norm3[0--2-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[0--2-[[[1, 0], [3, 0]], [[5, 0], [7, 0]]]] -tests/test_linalg.py::test_norm3[0--1-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[0--1-[[[1, 0], [3, 0]], [[5, 0], [7, 0]]]] -tests/test_linalg.py::test_norm3[0-2-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[0-2-[[[1, 0], [3, 0]], [[5, 0], [7, 0]]]] -tests/test_linalg.py::test_norm3[1-None-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[1-None-[[[1, 0], [3, 0]], [[5, 0], [7, 0]]]] -tests/test_linalg.py::test_norm3[1--2-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[1--2-[[[1, 0], [3, 0]], [[5, 0], [7, 0]]]] -tests/test_linalg.py::test_norm3[1--1-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[1--1-[[[1, 0], [3, 0]], [[5, 0], [7, 0]]]] -tests/test_linalg.py::test_norm3[1-2-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[1-2-[[[1, 0], [3, 0]], [[5, 0], [7, 0]]]] -tests/test_linalg.py::test_norm3[2-None-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[2-None-[[[1, 0], [3, 0]], [[5, 0], [7, 0]]]] -tests/test_linalg.py::test_norm3[2--2-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[2--1-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[2-2-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[(0, 1)-None-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[(0, 1)-None-[[[1, 0], [3, 0]], [[5, 0], [7, 0]]]] -tests/test_linalg.py::test_norm3[(0, 1)--2-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[(0, 1)--2-[[[1, 0], [3, 0]], [[5, 0], [7, 0]]]] -tests/test_linalg.py::test_norm3[(0, 1)-2-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[(0, 1)-2-[[[1, 0], [3, 0]], [[5, 0], [7, 0]]]] -tests/test_linalg.py::test_norm3[(0, 2)-None-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[(0, 2)-None-[[[1, 0], [3, 0]], [[5, 0], [7, 0]]]] -tests/test_linalg.py::test_norm3[(0, 2)--2-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[(0, 2)-2-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[(0, 2)-2-[[[1, 0], [3, 0]], [[5, 0], [7, 0]]]] -tests/test_linalg.py::test_norm3[(1, 2)-None-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[(1, 2)-None-[[[1, 0], [3, 0]], [[5, 0], [7, 0]]]] -tests/test_linalg.py::test_norm3[(1, 2)--2-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[(1, 2)-2-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] -tests/test_linalg.py::test_norm3[(1, 2)-2-[[[1, 0], [3, 0]], [[5, 0], [7, 0]]]] - -tests/test_linalg.py::test_qr[complete-(2,2)-float64] -tests/test_linalg.py::test_qr[complete-(3,4)-float64] -tests/test_linalg.py::test_qr[complete-(3,4)-int64] -tests/test_linalg.py::test_qr[complete-(3,4)-int32] -tests/test_linalg.py::test_qr[complete-(5,3)-float64] -tests/test_linalg.py::test_qr[complete-(5,3)-int64] -tests/test_linalg.py::test_qr[complete-(5,3)-int32] -tests/test_linalg.py::test_qr[complete-(16,16)-float64] -tests/test_linalg.py::test_qr[complete-(16,16)-int64] -tests/test_linalg.py::test_qr[complete-(16,16)-int32] -tests/test_linalg.py::test_qr[reduced-(2,2)-float64] -tests/test_linalg.py::test_qr[reduced-(3,4)-float64] -tests/test_linalg.py::test_qr[reduced-(5,3)-float64] -tests/test_linalg.py::test_qr[reduced-(16,16)-float64] - -tests/test_linalg.py::test_svd[(2,2)-float64] -tests/test_linalg.py::test_svd[(3,4)-float64] -tests/test_linalg.py::test_svd[(5,3)-float64] -tests/test_linalg.py::test_svd[(16,16)-float64] - tests/test_logic.py::test_allclose[int32] tests/test_logic.py::test_allclose[int64] tests/test_logic.py::test_allclose[float32] diff --git a/tests/test_linalg.py b/tests/test_linalg.py index 6adeabc5980..2327ca2e940 100644 --- a/tests/test_linalg.py +++ b/tests/test_linalg.py @@ -5,7 +5,7 @@ import dpnp as inp -from .helper import get_all_dtypes, get_complex_dtypes +from .helper import get_all_dtypes, get_complex_dtypes, has_support_aspect64 def vvsort(val, vec, size, xp): @@ -109,15 +109,9 @@ def test_det(array): assert_allclose(expected, result) -@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("type", get_all_dtypes(no_bool=True, no_complex=True)) @pytest.mark.parametrize("size", [2, 4, 8, 16, 300]) def test_eig_arange(type, size): - if dpctl.get_current_device_type() != dpctl.device_type.gpu: - pytest.skip( - "eig function doesn't work on CPU: https://github.com/IntelPython/dpnp/issues/1005" - ) - a = numpy.arange(size * size, dtype=type).reshape((size, size)) symm_orig = ( numpy.tril(a) @@ -145,8 +139,9 @@ def test_eig_arange(type, size): assert_array_equal(symm_orig, symm) assert_array_equal(dpnp_symm_orig, dpnp_symm) - assert dpnp_val.dtype == np_val.dtype - assert dpnp_vec.dtype == np_vec.dtype + if has_support_aspect64(): + assert dpnp_val.dtype == np_val.dtype + assert dpnp_vec.dtype == np_vec.dtype assert dpnp_val.shape == np_val.shape assert dpnp_vec.shape == np_vec.shape assert dpnp_val.usm_type == dpnp_symm.usm_type @@ -156,10 +151,13 @@ def test_eig_arange(type, size): assert_allclose(dpnp_vec, np_vec, rtol=1e-05, atol=1e-05) -@pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize("type", get_all_dtypes(no_bool=True, no_none=True)) @pytest.mark.parametrize("size", [2, 4, 8]) def test_eigh_arange(type, size): + if dpctl.get_current_device_type() != dpctl.device_type.gpu: + pytest.skip( + "eig function doesn't work on CPU: https://github.com/IntelPython/dpnp/issues/1005" + ) a = numpy.arange(size * size, dtype=type).reshape((size, size)) symm_orig = ( numpy.tril(a) @@ -202,7 +200,6 @@ def test_eigvals(type): pytest.skip( "eigvals function doesn't work on CPU: https://github.com/IntelPython/dpnp/issues/1005" ) - arrays = [[[0, 0], [0, 0]], [[1, 2], [1, 2]], [[1, 2], [3, 4]]] for array in arrays: a = numpy.array(array, dtype=type) @@ -223,7 +220,7 @@ def test_inv(type, array): ia = inp.array(a) result = inp.linalg.inv(ia) expected = numpy.linalg.inv(a) - assert_allclose(expected, result) + assert_allclose(expected, result, rtol=1e-06) @pytest.mark.parametrize( @@ -305,7 +302,7 @@ def test_norm2(array, ord, axis): ia = inp.array(a) result = inp.linalg.norm(ia, ord=ord, axis=axis) expected = numpy.linalg.norm(a, ord=ord, axis=axis) - assert_array_equal(expected, result) + assert_allclose(expected, result) @pytest.mark.usefixtures("allow_fall_back_on_numpy") @@ -335,7 +332,7 @@ def test_norm3(array, ord, axis): ia = inp.array(a) result = inp.linalg.norm(ia, ord=ord, axis=axis) expected = numpy.linalg.norm(a, ord=ord, axis=axis) - assert_array_equal(expected, result) + assert_allclose(expected, result) @pytest.mark.usefixtures("allow_fall_back_on_numpy") @@ -355,15 +352,19 @@ def test_qr(type, shape, mode): np_q, np_r = numpy.linalg.qr(a, mode) dpnp_q, dpnp_r = inp.linalg.qr(ia, mode) - assert dpnp_q.dtype == np_q.dtype - assert dpnp_r.dtype == np_r.dtype + support_aspect64 = has_support_aspect64() + + if support_aspect64: + assert dpnp_q.dtype == np_q.dtype + assert dpnp_r.dtype == np_r.dtype assert dpnp_q.shape == np_q.shape assert dpnp_r.shape == np_r.shape - if type == numpy.float32: + tol = 1e-6 + if type == inp.float32: + tol = 1e-02 + elif not support_aspect64 and type in (inp.int32, inp.int64, None): tol = 1e-02 - else: - tol = 1e-11 # check decomposition assert_allclose( @@ -402,17 +403,21 @@ def test_svd(type, shape): np_u, np_s, np_vt = numpy.linalg.svd(a) dpnp_u, dpnp_s, dpnp_vt = inp.linalg.svd(ia) - assert dpnp_u.dtype == np_u.dtype - assert dpnp_s.dtype == np_s.dtype - assert dpnp_vt.dtype == np_vt.dtype + support_aspect64 = has_support_aspect64() + + if support_aspect64: + assert dpnp_u.dtype == np_u.dtype + assert dpnp_s.dtype == np_s.dtype + assert dpnp_vt.dtype == np_vt.dtype assert dpnp_u.shape == np_u.shape assert dpnp_s.shape == np_s.shape assert dpnp_vt.shape == np_vt.shape - if type == numpy.float32: + tol = 1e-12 + if type == inp.float32: + tol = 1e-03 + elif not support_aspect64 and type in (inp.int32, inp.int64, None): tol = 1e-03 - else: - tol = 1e-12 # check decomposition dpnp_diag_s = inp.zeros(shape, dtype=dpnp_s.dtype)