From 8a7ff3e0b6e6e7704a8e5e45672e596218ec9397 Mon Sep 17 00:00:00 2001 From: Vahid Tavanashad Date: Tue, 24 Oct 2023 17:33:30 -0500 Subject: [PATCH 1/3] implement dpnp.cbrt, dpnp.exp2, dpnp.copysign, dpnp.rsqrt --- dpnp/backend/extensions/vm/cbrt.hpp | 79 +++ dpnp/backend/extensions/vm/exp2.hpp | 79 +++ dpnp/backend/extensions/vm/types_matrix.hpp | 30 + dpnp/backend/extensions/vm/vm_py.cpp | 60 ++ dpnp/backend/include/dpnp_iface_fptr.hpp | 16 +- dpnp/backend/kernels/dpnp_krnl_elemwise.cpp | 43 -- dpnp/dpnp_algo/dpnp_algo.pxd | 8 - dpnp/dpnp_algo/dpnp_algo_mathematical.pxi | 9 - dpnp/dpnp_algo/dpnp_algo_trigonometric.pxi | 10 - dpnp/dpnp_algo/dpnp_elementwise_common.py | 515 ++++++++++++------ dpnp/dpnp_iface_mathematical.py | 79 +-- dpnp/dpnp_iface_trigonometric.py | 153 +++++- tests/skipped_tests.tbl | 4 - tests/skipped_tests_gpu.tbl | 2 - tests/skipped_tests_gpu_no_fp64.tbl | 8 - tests/test_sycl_queue.py | 41 +- tests/test_umath.py | 210 +++++++ tests/test_usm_type.py | 44 +- .../third_party/cupy/math_tests/test_misc.py | 3 +- 19 files changed, 990 insertions(+), 403 deletions(-) create mode 100644 dpnp/backend/extensions/vm/cbrt.hpp create mode 100644 dpnp/backend/extensions/vm/exp2.hpp diff --git a/dpnp/backend/extensions/vm/cbrt.hpp b/dpnp/backend/extensions/vm/cbrt.hpp new file mode 100644 index 000000000000..83a44335bcc2 --- /dev/null +++ b/dpnp/backend/extensions/vm/cbrt.hpp @@ -0,0 +1,79 @@ +//***************************************************************************** +// Copyright (c) 2023, Intel Corporation +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// - Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// - Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +// THE POSSIBILITY OF SUCH DAMAGE. +//***************************************************************************** + +#pragma once + +#include + +#include "common.hpp" +#include "types_matrix.hpp" + +namespace dpnp +{ +namespace backend +{ +namespace ext +{ +namespace vm +{ +template +sycl::event cbrt_contig_impl(sycl::queue exec_q, + const std::int64_t n, + const char *in_a, + char *out_y, + const std::vector &depends) +{ + type_utils::validate_type_for_device(exec_q); + + const T *a = reinterpret_cast(in_a); + using resTy = typename types::CbrtOutputType::value_type; + resTy *y = reinterpret_cast(out_y); + + return mkl_vm::cbrt(exec_q, + n, // number of elements to be calculated + a, // pointer `a` containing input vector of size n + y, // pointer `y` to the output vector of size n + depends); +} + +template +struct CbrtContigFactory +{ + fnT get() + { + if constexpr (std::is_same_v< + typename types::CbrtOutputType::value_type, void>) + { + return nullptr; + } + else { + return cbrt_contig_impl; + } + } +}; +} // namespace vm +} // namespace ext +} // namespace backend +} // namespace dpnp diff --git a/dpnp/backend/extensions/vm/exp2.hpp b/dpnp/backend/extensions/vm/exp2.hpp new file mode 100644 index 000000000000..8f80d0c1d50f --- /dev/null +++ b/dpnp/backend/extensions/vm/exp2.hpp @@ -0,0 +1,79 @@ +//***************************************************************************** +// Copyright (c) 2023, Intel Corporation +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// - Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// - Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +// THE POSSIBILITY OF SUCH DAMAGE. +//***************************************************************************** + +#pragma once + +#include + +#include "common.hpp" +#include "types_matrix.hpp" + +namespace dpnp +{ +namespace backend +{ +namespace ext +{ +namespace vm +{ +template +sycl::event exp2_contig_impl(sycl::queue exec_q, + const std::int64_t n, + const char *in_a, + char *out_y, + const std::vector &depends) +{ + type_utils::validate_type_for_device(exec_q); + + const T *a = reinterpret_cast(in_a); + using resTy = typename types::Exp2OutputType::value_type; + resTy *y = reinterpret_cast(out_y); + + return mkl_vm::exp2(exec_q, + n, // number of elements to be calculated + a, // pointer `a` containing input vector of size n + y, // pointer `y` to the output vector of size n + depends); +} + +template +struct Exp2ContigFactory +{ + fnT get() + { + if constexpr (std::is_same_v< + typename types::Exp2OutputType::value_type, void>) + { + return nullptr; + } + else { + return exp2_contig_impl; + } + } +}; +} // namespace vm +} // namespace ext +} // namespace backend +} // namespace dpnp diff --git a/dpnp/backend/extensions/vm/types_matrix.hpp b/dpnp/backend/extensions/vm/types_matrix.hpp index 03328f92fb35..0ddc61884e1c 100644 --- a/dpnp/backend/extensions/vm/types_matrix.hpp +++ b/dpnp/backend/extensions/vm/types_matrix.hpp @@ -202,6 +202,21 @@ struct AtanhOutputType dpctl_td_ns::DefaultResultEntry>::result_type; }; +/** + * @brief A factory to define pairs of supported types for which + * MKL VM library provides support in oneapi::mkl::vm::cbrt function. + * + * @tparam T Type of input vector `a` and of result vector `y`. + */ +template +struct CbrtOutputType +{ + using value_type = typename std::disjunction< + dpctl_td_ns::TypeMapResultEntry, + dpctl_td_ns::TypeMapResultEntry, + dpctl_td_ns::DefaultResultEntry>::result_type; +}; + /** * @brief A factory to define pairs of supported types for which * MKL VM library provides support in oneapi::mkl::vm::ceil function. @@ -308,6 +323,21 @@ struct ExpOutputType dpctl_td_ns::DefaultResultEntry>::result_type; }; +/** + * @brief A factory to define pairs of supported types for which + * MKL VM library provides support in oneapi::mkl::vm::exp2 function. + * + * @tparam T Type of input vector `a` and of result vector `y`. + */ +template +struct Exp2OutputType +{ + using value_type = typename std::disjunction< + dpctl_td_ns::TypeMapResultEntry, + dpctl_td_ns::TypeMapResultEntry, + dpctl_td_ns::DefaultResultEntry>::result_type; +}; + /** * @brief A factory to define pairs of supported types for which * MKL VM library provides support in oneapi::mkl::vm::expm1 function. diff --git a/dpnp/backend/extensions/vm/vm_py.cpp b/dpnp/backend/extensions/vm/vm_py.cpp index a7dfce88a7a0..09416b00918b 100644 --- a/dpnp/backend/extensions/vm/vm_py.cpp +++ b/dpnp/backend/extensions/vm/vm_py.cpp @@ -39,6 +39,7 @@ #include "atan.hpp" #include "atan2.hpp" #include "atanh.hpp" +#include "cbrt.hpp" #include "ceil.hpp" #include "common.hpp" #include "conj.hpp" @@ -46,6 +47,7 @@ #include "cosh.hpp" #include "div.hpp" #include "exp.hpp" +#include "exp2.hpp" #include "expm1.hpp" #include "floor.hpp" #include "hypot.hpp" @@ -81,12 +83,14 @@ static unary_impl_fn_ptr_t asinh_dispatch_vector[dpctl_td_ns::num_types]; static unary_impl_fn_ptr_t atan_dispatch_vector[dpctl_td_ns::num_types]; static binary_impl_fn_ptr_t atan2_dispatch_vector[dpctl_td_ns::num_types]; static unary_impl_fn_ptr_t atanh_dispatch_vector[dpctl_td_ns::num_types]; +static unary_impl_fn_ptr_t cbrt_dispatch_vector[dpctl_td_ns::num_types]; static unary_impl_fn_ptr_t ceil_dispatch_vector[dpctl_td_ns::num_types]; static unary_impl_fn_ptr_t conj_dispatch_vector[dpctl_td_ns::num_types]; static unary_impl_fn_ptr_t cos_dispatch_vector[dpctl_td_ns::num_types]; static unary_impl_fn_ptr_t cosh_dispatch_vector[dpctl_td_ns::num_types]; static binary_impl_fn_ptr_t div_dispatch_vector[dpctl_td_ns::num_types]; static unary_impl_fn_ptr_t exp_dispatch_vector[dpctl_td_ns::num_types]; +static unary_impl_fn_ptr_t exp2_dispatch_vector[dpctl_td_ns::num_types]; static unary_impl_fn_ptr_t expm1_dispatch_vector[dpctl_td_ns::num_types]; static unary_impl_fn_ptr_t floor_dispatch_vector[dpctl_td_ns::num_types]; static binary_impl_fn_ptr_t hypot_dispatch_vector[dpctl_td_ns::num_types]; @@ -366,6 +370,34 @@ PYBIND11_MODULE(_vm_impl, m) py::arg("sycl_queue"), py::arg("src"), py::arg("dst")); } + // UnaryUfunc: ==== Cbrt(x) ==== + { + vm_ext::init_ufunc_dispatch_vector( + cbrt_dispatch_vector); + + auto cbrt_pyapi = [&](sycl::queue exec_q, arrayT src, arrayT dst, + const event_vecT &depends = {}) { + return vm_ext::unary_ufunc(exec_q, src, dst, depends, + cbrt_dispatch_vector); + }; + m.def("_cbrt", cbrt_pyapi, + "Call `cbrt` function from OneMKL VM library to compute " + "the element-wise cube root of vector elements", + py::arg("sycl_queue"), py::arg("src"), py::arg("dst"), + py::arg("depends") = py::list()); + + auto cbrt_need_to_call_pyapi = [&](sycl::queue exec_q, arrayT src, + arrayT dst) { + return vm_ext::need_to_call_unary_ufunc(exec_q, src, dst, + cbrt_dispatch_vector); + }; + m.def("_mkl_cbrt_to_call", cbrt_need_to_call_pyapi, + "Check input arguments to answer if `cbrt` function from " + "OneMKL VM library can be used", + py::arg("sycl_queue"), py::arg("src"), py::arg("dst")); + } + // UnaryUfunc: ==== Ceil(x) ==== { vm_ext::init_ufunc_dispatch_vector( + exp2_dispatch_vector); + + auto exp2_pyapi = [&](sycl::queue exec_q, arrayT src, arrayT dst, + const event_vecT &depends = {}) { + return vm_ext::unary_ufunc(exec_q, src, dst, depends, + exp2_dispatch_vector); + }; + m.def("_exp2", exp2_pyapi, + "Call `exp2` function from OneMKL VM library to compute " + "the element-wise base-2 exponential of vector elements", + py::arg("sycl_queue"), py::arg("src"), py::arg("dst"), + py::arg("depends") = py::list()); + + auto exp2_need_to_call_pyapi = [&](sycl::queue exec_q, arrayT src, + arrayT dst) { + return vm_ext::need_to_call_unary_ufunc(exec_q, src, dst, + exp2_dispatch_vector); + }; + m.def("_mkl_exp2_to_call", exp2_need_to_call_pyapi, + "Check input arguments to answer if `exp2` function from " + "OneMKL VM library can be used", + py::arg("sycl_queue"), py::arg("src"), py::arg("dst")); + } + // UnaryUfunc: ==== expm1(x) ==== { vm_ext::init_ufunc_dispatch_vector}; - fmap[DPNPFuncName::DPNP_FN_CBRT_EXT][eft_INT][eft_INT] = { - eft_DBL, (void *)dpnp_cbrt_c_ext}; - fmap[DPNPFuncName::DPNP_FN_CBRT_EXT][eft_LNG][eft_LNG] = { - eft_DBL, (void *)dpnp_cbrt_c_ext}; - fmap[DPNPFuncName::DPNP_FN_CBRT_EXT][eft_FLT][eft_FLT] = { - eft_FLT, (void *)dpnp_cbrt_c_ext}; - fmap[DPNPFuncName::DPNP_FN_CBRT_EXT][eft_DBL][eft_DBL] = { - eft_DBL, (void *)dpnp_cbrt_c_ext}; - fmap[DPNPFuncName::DPNP_FN_CEIL][eft_INT][eft_INT] = { eft_DBL, (void *)dpnp_ceil_c_default}; fmap[DPNPFuncName::DPNP_FN_CEIL][eft_LNG][eft_LNG] = { @@ -438,27 +429,6 @@ static void func_map_init_elemwise_1arg_2type(func_map_t &fmap) fmap[DPNPFuncName::DPNP_FN_EXP2][eft_DBL][eft_DBL] = { eft_DBL, (void *)dpnp_exp2_c_default}; - fmap[DPNPFuncName::DPNP_FN_EXP2_EXT][eft_INT][eft_INT] = { - get_default_floating_type(), - (void *)dpnp_exp2_c_ext< - int32_t, func_type_map_t::find_type>, - get_default_floating_type(), - (void *)dpnp_exp2_c_ext< - int32_t, func_type_map_t::find_type< - get_default_floating_type()>>}; - fmap[DPNPFuncName::DPNP_FN_EXP2_EXT][eft_LNG][eft_LNG] = { - get_default_floating_type(), - (void *)dpnp_exp2_c_ext< - int64_t, func_type_map_t::find_type>, - get_default_floating_type(), - (void *)dpnp_exp2_c_ext< - int64_t, func_type_map_t::find_type< - get_default_floating_type()>>}; - fmap[DPNPFuncName::DPNP_FN_EXP2_EXT][eft_FLT][eft_FLT] = { - eft_FLT, (void *)dpnp_exp2_c_ext}; - fmap[DPNPFuncName::DPNP_FN_EXP2_EXT][eft_DBL][eft_DBL] = { - eft_DBL, (void *)dpnp_exp2_c_ext}; - fmap[DPNPFuncName::DPNP_FN_EXP][eft_INT][eft_INT] = { eft_DBL, (void *)dpnp_exp_c_default}; fmap[DPNPFuncName::DPNP_FN_EXP][eft_LNG][eft_LNG] = { @@ -1478,19 +1448,6 @@ static void func_map_elemwise_2arg_3type_core(func_map_t &fmap) template static void func_map_elemwise_2arg_3type_short_core(func_map_t &fmap) { - ((fmap[DPNPFuncName::DPNP_FN_COPYSIGN_EXT][FT1][FTs] = - {get_floating_res_type(), - (void *)dpnp_copysign_c_ext< - func_type_map_t::find_type()>, - func_type_map_t::find_type, - func_type_map_t::find_type>, - get_floating_res_type(), - (void *)dpnp_copysign_c_ext< - func_type_map_t::find_type< - get_floating_res_type()>, - func_type_map_t::find_type, - func_type_map_t::find_type>}), - ...); ((fmap[DPNPFuncName::DPNP_FN_FMOD_EXT][FT1][FTs] = {get_floating_res_type(), (void *) diff --git a/dpnp/dpnp_algo/dpnp_algo.pxd b/dpnp/dpnp_algo/dpnp_algo.pxd index c2e4747fbdb7..55b0ed6cee94 100644 --- a/dpnp/dpnp_algo/dpnp_algo.pxd +++ b/dpnp/dpnp_algo/dpnp_algo.pxd @@ -42,16 +42,12 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na DPNP_FN_ARGMIN_EXT DPNP_FN_ARGSORT DPNP_FN_ARGSORT_EXT - DPNP_FN_CBRT - DPNP_FN_CBRT_EXT DPNP_FN_CHOLESKY DPNP_FN_CHOLESKY_EXT DPNP_FN_CHOOSE DPNP_FN_CHOOSE_EXT DPNP_FN_COPY DPNP_FN_COPY_EXT - DPNP_FN_COPYSIGN - DPNP_FN_COPYSIGN_EXT DPNP_FN_CORRELATE DPNP_FN_CORRELATE_EXT DPNP_FN_CROSS @@ -82,8 +78,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na DPNP_FN_ERF_EXT DPNP_FN_EYE DPNP_FN_EYE_EXT - DPNP_FN_EXP2 - DPNP_FN_EXP2_EXT DPNP_FN_FABS DPNP_FN_FABS_EXT DPNP_FN_FFT_FFT @@ -380,8 +374,6 @@ cpdef dpnp_descriptor dpnp_argmin(dpnp_descriptor array1) """ Trigonometric functions """ -cpdef dpnp_descriptor dpnp_cbrt(dpnp_descriptor array1) cpdef dpnp_descriptor dpnp_degrees(dpnp_descriptor array1) -cpdef dpnp_descriptor dpnp_exp2(dpnp_descriptor array1) cpdef dpnp_descriptor dpnp_radians(dpnp_descriptor array1) cpdef dpnp_descriptor dpnp_recip(dpnp_descriptor array1) diff --git a/dpnp/dpnp_algo/dpnp_algo_mathematical.pxi b/dpnp/dpnp_algo/dpnp_algo_mathematical.pxi index f9828229b53a..431892f10217 100644 --- a/dpnp/dpnp_algo/dpnp_algo_mathematical.pxi +++ b/dpnp/dpnp_algo/dpnp_algo_mathematical.pxi @@ -36,7 +36,6 @@ and the rest of the library # NO IMPORTs here. All imports must be placed into main "dpnp_algo.pyx" file __all__ += [ - "dpnp_copysign", "dpnp_cross", "dpnp_cumprod", "dpnp_cumsum", @@ -64,14 +63,6 @@ ctypedef c_dpctl.DPCTLSyclEventRef(*ftpr_custom_trapz_2in_1out_with_2size_t)(c_d const c_dpctl.DPCTLEventVectorRef) -cpdef utils.dpnp_descriptor dpnp_copysign(utils.dpnp_descriptor x1_obj, - utils.dpnp_descriptor x2_obj, - object dtype=None, - utils.dpnp_descriptor out=None, - object where=True): - return call_fptr_2in_1out_strides(DPNP_FN_COPYSIGN_EXT, x1_obj, x2_obj, dtype, out, where) - - cpdef utils.dpnp_descriptor dpnp_cross(utils.dpnp_descriptor x1_obj, utils.dpnp_descriptor x2_obj, object dtype=None, diff --git a/dpnp/dpnp_algo/dpnp_algo_trigonometric.pxi b/dpnp/dpnp_algo/dpnp_algo_trigonometric.pxi index 099aa9ba7abd..41a29b275577 100644 --- a/dpnp/dpnp_algo/dpnp_algo_trigonometric.pxi +++ b/dpnp/dpnp_algo/dpnp_algo_trigonometric.pxi @@ -36,27 +36,17 @@ and the rest of the library # NO IMPORTs here. All imports must be placed into main "dpnp_algo.pyx" file __all__ += [ - 'dpnp_cbrt', 'dpnp_degrees', - 'dpnp_exp2', 'dpnp_radians', 'dpnp_recip', 'dpnp_unwrap' ] -cpdef utils.dpnp_descriptor dpnp_cbrt(utils.dpnp_descriptor x1): - return call_fptr_1in_1out_strides(DPNP_FN_CBRT_EXT, x1) - - cpdef utils.dpnp_descriptor dpnp_degrees(utils.dpnp_descriptor x1): return call_fptr_1in_1out_strides(DPNP_FN_DEGREES_EXT, x1) -cpdef utils.dpnp_descriptor dpnp_exp2(utils.dpnp_descriptor x1): - return call_fptr_1in_1out_strides(DPNP_FN_EXP2_EXT, x1) - - cpdef utils.dpnp_descriptor dpnp_recip(utils.dpnp_descriptor x1): return call_fptr_1in_1out_strides(DPNP_FN_RECIP_EXT, x1) diff --git a/dpnp/dpnp_algo/dpnp_elementwise_common.py b/dpnp/dpnp_algo/dpnp_elementwise_common.py index 315b266c8032..fd3f3e9cf3df 100644 --- a/dpnp/dpnp_algo/dpnp_elementwise_common.py +++ b/dpnp/dpnp_algo/dpnp_elementwise_common.py @@ -46,13 +46,16 @@ "dpnp_bitwise_and", "dpnp_bitwise_or", "dpnp_bitwise_xor", + "dpnp_cbrt", "dpnp_ceil", "dpnp_conj", + "dpnp_copysign", "dpnp_cos", "dpnp_cosh", "dpnp_divide", "dpnp_equal", "dpnp_exp", + "dpnp_exp2", "dpnp_expm1", "dpnp_floor", "dpnp_floor_divide", @@ -88,6 +91,7 @@ "dpnp_remainder", "dpnp_right_shift", "dpnp_round", + "dpnp_rsqrt", "dpnp_sign", "dpnp_signbit", "dpnp_sin", @@ -231,10 +235,10 @@ def _call_func(src1, src2, dst, sycl_queue, depends=None): x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -275,10 +279,10 @@ def dpnp_abs(x, out=None, order="K"): x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -316,10 +320,10 @@ def dpnp_acos(x, out=None, order="K"): x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -361,7 +365,7 @@ def dpnp_acosh(x, out=None, order="K"): Second input array, also expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -403,10 +407,10 @@ def dpnp_add(x1, x2, out=None, order="K"): x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -444,10 +448,10 @@ def dpnp_asin(x, out=None, order="K"): x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type.. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -485,10 +489,10 @@ def dpnp_asinh(x, out=None, order="K"): x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type.. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -533,7 +537,7 @@ def dpnp_atan(x, out=None, order="K"): floating-point data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -576,10 +580,10 @@ def dpnp_atan2(x1, x2, out=None, order="K"): x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -623,7 +627,7 @@ def dpnp_atanh(x, out=None, order="K"): type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -667,7 +671,7 @@ def dpnp_bitwise_and(x1, x2, out=None, order="K"): type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -711,7 +715,7 @@ def dpnp_bitwise_or(x1, x2, out=None, order="K"): type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -740,6 +744,46 @@ def dpnp_bitwise_xor(x1, x2, out=None, order="K"): return dpnp_array._create_from_usm_ndarray(res_usm) +_cbrt_docstring = """ +cbrt(x, out=None, order='K') + +Returns the cbrting for each element `x_i` for input array `x`. +The cbrt of the scalar `x` is the smallest integer `i`, such that `i >= x`. + +Args: + x (dpnp.ndarray): + Input array, expected to have a real-valued data type. + out ({None, dpnp.ndarray}, optional): + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. + Default: "K". +Return: + dpnp.ndarray: + An array containing the element-wise cbrting of input array. + The returned array has the same data type as `x`. +""" + +cbrt_func = _make_unary_func( + "cbrt", dpt.cbrt, _cbrt_docstring, vmi._mkl_cbrt_to_call, vmi._cbrt +) + + +def dpnp_cbrt(x, out=None, order="K"): + """ + Invokes cbrt() function from pybind11 extension of OneMKL VM if possible. + + Otherwise fully relies on dpctl.tensor implementation for cbrt() function. + """ + # dpctl.tensor only works with usm_ndarray + x1_usm = dpnp.get_usm_ndarray(x) + out_usm = None if out is None else dpnp.get_usm_ndarray(out) + + res_usm = cbrt_func(x1_usm, out=out_usm, order=order) + return dpnp_array._create_from_usm_ndarray(res_usm) + + _ceil_docstring = """ ceil(x, out=None, order='K') @@ -750,10 +794,10 @@ def dpnp_bitwise_xor(x1, x2, out=None, order="K"): x (dpnp.ndarray): Input array, expected to have a real-valued data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -780,122 +824,163 @@ def dpnp_ceil(x, out=None, order="K"): return dpnp_array._create_from_usm_ndarray(res_usm) -_cos_docstring = """ -cos(x, out=None, order='K') +_conj_docstring = """ +conj(x, out=None, order='K') -Computes cosine for each element `x_i` for input array `x`. +Computes conjugate for each element `x_i` for input array `x`. Args: x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: - An array containing the element-wise cosine. The data type - of the returned array is determined by the Type Promotion Rules. + An array containing the element-wise conjugate. + The returned array has the same data type as `x`. """ -cos_func = _make_unary_func( - "cos", dpt.cos, _cos_docstring, vmi._mkl_cos_to_call, vmi._cos +conj_func = _make_unary_func( + "conj", dpt.conj, _conj_docstring, vmi._mkl_conj_to_call, vmi._conj ) -def dpnp_cos(x, out=None, order="K"): +def dpnp_conj(x, out=None, order="K"): """ - Invokes cos() function from pybind11 extension of OneMKL VM if possible. - - Otherwise fully relies on dpctl.tensor implementation for cos() function. + Invokes conj() function from pybind11 extension of OneMKL VM if possible. + Otherwise fully relies on dpctl.tensor implementation for conj() function. """ # dpctl.tensor only works with usm_ndarray x1_usm = dpnp.get_usm_ndarray(x) out_usm = None if out is None else dpnp.get_usm_ndarray(out) - res_usm = cos_func(x1_usm, out=out_usm, order=order) + res_usm = conj_func(x1_usm, out=out_usm, order=order) return dpnp_array._create_from_usm_ndarray(res_usm) -_cosh_docstring = """ -cosh(x, out=None, order='K') +_copysign_docstring = """ +copysign(x1, x2, out=None, order='K') -Computes hyperbolic cosine for each element `x_i` for input array `x`. +Composes a floating-point value with the magnitude of `x1_i` and the sign of +`x2_i` for each element of input arrays `x1` and `x2`. + +Args: + x1 (dpnp.ndarray): + First input array, expected to have a real floating-point data type. + x2 (dpnp.ndarray): + Second input array, also expected to have a real floating-point data + type. + out ({None, dpnp.ndarray}, optional): + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. + Default: "K". +Returns: + dpnp.ndarray: + An array containing the element-wise results. The data type + of the returned array is determined by the Type Promotion Rules. +""" + +copysign_func = _make_binary_func("copysign", dpt.copysign, _copysign_docstring) + + +def dpnp_copysign(x1, x2, out=None, order="K"): + """Invokes copysign() from dpctl.tensor implementation for copysign() function.""" + + # dpctl.tensor only works with usm_ndarray or scalar + x1_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x1) + x2_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x2) + out_usm = None if out is None else dpnp.get_usm_ndarray(out) + + res_usm = copysign_func( + x1_usm_or_scalar, x2_usm_or_scalar, out=out_usm, order=order + ) + return dpnp_array._create_from_usm_ndarray(res_usm) + + +_cos_docstring = """ +cos(x, out=None, order='K') + +Computes cosine for each element `x_i` for input array `x`. Args: x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: - An array containing the element-wise hyperbolic cosine. The data type + An array containing the element-wise cosine. The data type of the returned array is determined by the Type Promotion Rules. """ -cosh_func = _make_unary_func( - "cosh", dpt.cosh, _cosh_docstring, vmi._mkl_cosh_to_call, vmi._cosh +cos_func = _make_unary_func( + "cos", dpt.cos, _cos_docstring, vmi._mkl_cos_to_call, vmi._cos ) -def dpnp_cosh(x, out=None, order="K"): +def dpnp_cos(x, out=None, order="K"): """ - Invokes cosh() function from pybind11 extension of OneMKL VM if possible. + Invokes cos() function from pybind11 extension of OneMKL VM if possible. - Otherwise fully relies on dpctl.tensor implementation for cosh() function. + Otherwise fully relies on dpctl.tensor implementation for cos() function. """ # dpctl.tensor only works with usm_ndarray x1_usm = dpnp.get_usm_ndarray(x) out_usm = None if out is None else dpnp.get_usm_ndarray(out) - res_usm = cosh_func(x1_usm, out=out_usm, order=order) + res_usm = cos_func(x1_usm, out=out_usm, order=order) return dpnp_array._create_from_usm_ndarray(res_usm) -_conj_docstring = """ -conj(x, out=None, order='K') +_cosh_docstring = """ +cosh(x, out=None, order='K') -Computes conjugate for each element `x_i` for input array `x`. +Computes hyperbolic cosine for each element `x_i` for input array `x`. Args: x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: - An array containing the element-wise conjugate. - The returned array has the same data type as `x`. + An array containing the element-wise hyperbolic cosine. The data type + of the returned array is determined by the Type Promotion Rules. """ -conj_func = _make_unary_func( - "conj", dpt.conj, _conj_docstring, vmi._mkl_conj_to_call, vmi._conj +cosh_func = _make_unary_func( + "cosh", dpt.cosh, _cosh_docstring, vmi._mkl_cosh_to_call, vmi._cosh ) -def dpnp_conj(x, out=None, order="K"): +def dpnp_cosh(x, out=None, order="K"): """ - Invokes conj() function from pybind11 extension of OneMKL VM if possible. + Invokes cosh() function from pybind11 extension of OneMKL VM if possible. + + Otherwise fully relies on dpctl.tensor implementation for cosh() function. - Otherwise fully relies on dpctl.tensor implementation for conj() function. """ # dpctl.tensor only works with usm_ndarray x1_usm = dpnp.get_usm_ndarray(x) out_usm = None if out is None else dpnp.get_usm_ndarray(out) - res_usm = conj_func(x1_usm, out=out_usm, order=order) + res_usm = cosh_func(x1_usm, out=out_usm, order=order) return dpnp_array._create_from_usm_ndarray(res_usm) @@ -912,7 +997,7 @@ def dpnp_conj(x, out=None, order="K"): Second input array, also expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -994,10 +1079,10 @@ def dpnp_equal(x1, x2, out=None, order="K"): x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -1026,6 +1111,47 @@ def dpnp_exp(x, out=None, order="K"): return dpnp_array._create_from_usm_ndarray(res_usm) +_exp2_docstring = """ +exp2(x, out=None, order='K') + +Computes the base-2 exponential for each element `x_i` for input array `x`. + +Args: + x (dpnp.ndarray): + Input array, expected to have a floating-point data type. + out ({None, dpnp.ndarray}, optional): + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. + Default: "K". +Return: + dpnp.ndarray: + An array containing the element-wise base-2 exponentials. + The data type of the returned array is determined by + the Type Promotion Rules. +""" + +exp2_func = _make_unary_func( + "exp2", dpt.exp2, _exp2_docstring, vmi._mkl_exp2_to_call, vmi._exp2 +) + + +def dpnp_exp2(x, out=None, order="K"): + """ + Invokes exp2() function from pybind11 extension of OneMKL VM if possible. + + Otherwise fully relies on dpctl.tensor implementation for exp2() function. + """ + + # dpctl.tensor only works with usm_ndarray + x1_usm = dpnp.get_usm_ndarray(x) + out_usm = None if out is None else dpnp.get_usm_ndarray(out) + + res_usm = exp2_func(x1_usm, out=out_usm, order=order) + return dpnp_array._create_from_usm_ndarray(res_usm) + + _expm1_docstring = """ expm1(x, out=None, order='K') @@ -1037,10 +1163,10 @@ def dpnp_exp(x, out=None, order="K"): x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -1079,10 +1205,10 @@ def dpnp_expm1(x, out=None, order="K"): x (dpnp.ndarray): Input array, expected to have a real-valued data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -1123,7 +1249,7 @@ def dpnp_floor(x, out=None, order="K"): Second input array, also expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -1166,7 +1292,7 @@ def dpnp_floor_divide(x1, x2, out=None, order="K"): Second input array, also expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -1206,7 +1332,7 @@ def dpnp_greater(x1, x2, out=None, order="K"): Second input array, also expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -1248,7 +1374,7 @@ def dpnp_greater_equal(x1, x2, out=None, order="K"): Second input array, also expected to have a real-valued data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -1291,7 +1417,7 @@ def dpnp_hypot(x1, x2, out=None, order="K"): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -1329,8 +1455,8 @@ def dpnp_imag(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -1363,7 +1489,7 @@ def dpnp_invert(x, out=None, order="K"): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -1398,7 +1524,7 @@ def dpnp_isfinite(x, out=None, order="K"): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -1432,7 +1558,7 @@ def dpnp_isinf(x, out=None, order="K"): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -1471,7 +1597,7 @@ def dpnp_isnan(x, out=None, order="K"): Each element must be greater than or equal to 0. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -1513,7 +1639,7 @@ def dpnp_left_shift(x1, x2, out=None, order="K"): Second input array, also expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -1553,7 +1679,7 @@ def dpnp_less(x1, x2, out=None, order="K"): Second input array, also expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -1591,10 +1717,10 @@ def dpnp_less_equal(x1, x2, out=None, order="K"): x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -1632,10 +1758,10 @@ def dpnp_log(x, out=None, order="K"): x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -1673,10 +1799,10 @@ def dpnp_log10(x, out=None, order="K"): x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -1713,10 +1839,10 @@ def dpnp_log1p(x, out=None, order="K"): x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -1764,7 +1890,7 @@ def dpnp_log2(x, out=None, order="K"): floating-point data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -1806,7 +1932,7 @@ def dpnp_logaddexp(x1, x2, out=None, order="K"): Second input array. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -1843,10 +1969,10 @@ def dpnp_logical_and(x1, x2, out=None, order="K"): x (dpnp.ndarray): Input array. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -1882,7 +2008,7 @@ def dpnp_logical_not(x, out=None, order="K"): Second input array. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -1923,7 +2049,7 @@ def dpnp_logical_or(x1, x2, out=None, order="K"): Second input array. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -1964,7 +2090,7 @@ def dpnp_logical_xor(x1, x2, out=None, order="K"): Second input array, also expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -2004,7 +2130,7 @@ def dpnp_maximum(x1, x2, out=None, order="K"): Second input array, also expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -2044,7 +2170,7 @@ def dpnp_minimum(x1, x2, out=None, order="K"): Second input array, also expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -2091,7 +2217,7 @@ def dpnp_multiply(x1, x2, out=None, order="K"): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -2134,7 +2260,7 @@ def dpnp_negative(x, out=None, order="K"): Second input array, also expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -2173,7 +2299,7 @@ def dpnp_not_equal(x1, x2, out=None, order="K"): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -2259,7 +2385,7 @@ def dpnp_power(x1, x2, out=None, order="K"): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -2293,7 +2419,7 @@ def dpnp_proj(x, out=None, order="K"): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -2334,7 +2460,7 @@ def dpnp_real(x, out=None, order="K"): Second input array, also expected to have a real-valued data type. out ({None, usm_ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -2375,7 +2501,7 @@ def dpnp_remainder(x1, x2, out=None, order="K"): Each element must be greater than or equal to 0. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -2414,10 +2540,10 @@ def dpnp_right_shift(x1, x2, out=None, order="K"): x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -2444,6 +2570,41 @@ def dpnp_round(x, out=None, order="K"): return dpnp_array._create_from_usm_ndarray(res_usm) +_rsqrt_docstring = """ +rsqrt(x, out=None, order="K") + +Computes the reciprocal square-root for each element `x_i` for input array `x`. + +Args: + x (dpnp.ndarray): + Input array, expected to have a real floating-point data type. + out ({None, dpnp.ndarray}, optional): + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. + Default: "K". +Returns: + dpnp.ndarray: + An array containing the element-wise reciprocal square-root. + The data type of the returned array is determined by + the Type Promotion Rules. +""" + +rsqrt_func = _make_unary_func("rsqrt", dpt.rsqrt, _rsqrt_docstring) + + +def dpnp_rsqrt(x, out=None, order="K"): + """Invokes rsqrt() from dpctl.tensor implementation for rsqrt() function.""" + + # dpctl.tensor only works with usm_ndarray + x1_usm = dpnp.get_usm_ndarray(x) + out_usm = None if out is None else dpnp.get_usm_ndarray(out) + + res_usm = rsqrt_func(x1_usm, out=out_usm, order=order) + return dpnp_array._create_from_usm_ndarray(res_usm) + + _sign_docstring = """ sign(x, out=None, order="K") @@ -2458,7 +2619,7 @@ def dpnp_round(x, out=None, order="K"): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -2497,7 +2658,7 @@ def dpnp_sign(x, out=None, order="K"): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -2530,10 +2691,10 @@ def dpnp_signbit(x, out=None, order="K"): x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -2570,10 +2731,10 @@ def dpnp_sin(x, out=None, order="K"): x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -2610,10 +2771,10 @@ def dpnp_sinh(x, out=None, order="K"): x (dpnp.ndarray): Input array. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -2649,10 +2810,10 @@ def dpnp_sqrt(x, out=None, order="K"): x (dpnp.ndarray): Input array. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -2692,7 +2853,7 @@ def dpnp_square(x, out=None, order="K"): Second input array, also expected to have numeric data type. out ({None, dpnp.ndarray}, optional): Output array to populate. - Array have the correct shape and the expected data type. + Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". @@ -2749,10 +2910,10 @@ def dpnp_subtract(x1, x2, out=None, order="K"): x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -2789,10 +2950,10 @@ def dpnp_tan(x, out=None, order="K"): x (dpnp.ndarray): Input array, expected to have numeric data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: @@ -2832,10 +2993,10 @@ def dpnp_tanh(x, out=None, order="K"): x (dpnp.ndarray): Input array, expected to have a real-valued data type. out ({None, dpnp.ndarray}, optional): - Output array to populate. Array must have the correct - shape and the expected data type. - order ("C","F","A","K", optional): memory layout of the new - output array, if parameter `out` is `None`. + Output array to populate. + Array must have the correct shape and the expected data type. + order ("C","F","A","K", optional): + Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: dpnp.ndarray: diff --git a/dpnp/dpnp_iface_mathematical.py b/dpnp/dpnp_iface_mathematical.py index 330179c2ca44..f023a14fa251 100644 --- a/dpnp/dpnp_iface_mathematical.py +++ b/dpnp/dpnp_iface_mathematical.py @@ -55,6 +55,7 @@ dpnp_add, dpnp_ceil, dpnp_conj, + dpnp_copysign, dpnp_divide, dpnp_floor, dpnp_floor_divide, @@ -432,7 +433,16 @@ def convolve(a, v, mode="full"): def copysign( - x1, x2, /, out=None, *, where=True, dtype=None, subok=True, **kwargs + x1, + x2, + /, + out=None, + *, + where=True, + order="K", + dtype=None, + subok=True, + **kwargs, ): """ Change the sign of `x1` to that of `x2`, element-wise. @@ -451,7 +461,7 @@ def copysign( Parameters `where`, `dtype` and `subok` are supported with their default values. Keyword argument `kwargs` is currently unsupported. Otherwise the function will be executed sequentially on CPU. - Input array data types are limited by supported DPNP :ref:`Data types`. + Input array data types are limited by supported real data types. Examples -------- @@ -471,60 +481,17 @@ def copysign( """ - if kwargs: - pass - elif where is not True: - pass - elif dtype is not None: - pass - elif subok is not True: - pass - elif dpnp.isscalar(x1) and dpnp.isscalar(x2): - # at least either x1 or x2 has to be an array - pass - else: - # get USM type and queue to copy scalar from the host memory into a USM allocation - usm_type, queue = ( - get_usm_allocations([x1, x2]) - if dpnp.isscalar(x1) or dpnp.isscalar(x2) - else (None, None) - ) - - x1_desc = dpnp.get_dpnp_descriptor( - x1, - copy_when_strides=False, - copy_when_nondefault_queue=False, - alloc_usm_type=usm_type, - alloc_queue=queue, - ) - x2_desc = dpnp.get_dpnp_descriptor( - x2, - copy_when_strides=False, - copy_when_nondefault_queue=False, - alloc_usm_type=usm_type, - alloc_queue=queue, - ) - if x1_desc and x2_desc: - if out is not None: - if not dpnp.is_supported_array_type(out): - raise TypeError( - "return array must be of supported array type" - ) - out_desc = ( - dpnp.get_dpnp_descriptor( - out, copy_when_nondefault_queue=False - ) - or None - ) - else: - out_desc = None - - return dpnp_copysign( - x1_desc, x2_desc, dtype=dtype, out=out_desc, where=where - ).get_pyobj() - - return call_origin( - numpy.copysign, x1, x2, dtype=dtype, out=out, where=where, **kwargs + return check_nd_call_func( + numpy.copysign, + dpnp_copysign, + x1, + x2, + out=out, + where=where, + order=order, + dtype=dtype, + subok=subok, + **kwargs, ) diff --git a/dpnp/dpnp_iface_trigonometric.py b/dpnp/dpnp_iface_trigonometric.py index 608639f0030e..5c614475ef00 100644 --- a/dpnp/dpnp_iface_trigonometric.py +++ b/dpnp/dpnp_iface_trigonometric.py @@ -55,9 +55,11 @@ dpnp_atan, dpnp_atan2, dpnp_atanh, + dpnp_cbrt, dpnp_cos, dpnp_cosh, dpnp_exp, + dpnp_exp2, dpnp_expm1, dpnp_hypot, dpnp_log, @@ -65,6 +67,7 @@ dpnp_log2, dpnp_log10, dpnp_logaddexp, + dpnp_rsqrt, dpnp_sin, dpnp_sinh, dpnp_sqrt, @@ -98,6 +101,7 @@ "rad2deg", "radians", "reciprocal", + "rsqrt", "sin", "sinh", "sqrt", @@ -532,34 +536,59 @@ def arctanh( ) -def cbrt(x1): +def cbrt( + x, + /, + out=None, + *, + order="K", + where=True, + dtype=None, + subok=True, + **kwargs, +): """ Return the cube-root of an array, element-wise. For full documentation refer to :obj:`numpy.cbrt`. + Returns + ------- + out : dpnp.ndarray + The cube-root of each element in `x`. + Limitations ----------- - Input array is supported as :class:`dpnp.ndarray`. - Input array data types are limited by supported DPNP :ref:`Data types`. + Parameter `x` is only supported as either :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`. + Parameters `where`, `dtype` and `subok` are supported with their default values. + Keyword argument `kwargs` is currently unsupported. + Otherwise the function will be executed sequentially on CPU. + Input array data types are limited by real-valued data types. + + See Also + -------- + :obj:`dpnp.sqrt` : Return the positive square-root of an array, element-wise. Examples -------- >>> import dpnp as np >>> x = np.array([1, 8, 27]) - >>> out = np.cbrt(x) - >>> [i for i in out] - [1.0, 2.0, 3.0] + >>> np.cbrt(x) + array([1., 2., 3.]) """ - x1_desc = dpnp.get_dpnp_descriptor( - x1, copy_when_strides=False, copy_when_nondefault_queue=False + return check_nd_call_func( + numpy.cbrt, + dpnp_cbrt, + x, + out=out, + where=where, + order=order, + dtype=dtype, + subok=subok, + **kwargs, ) - if x1_desc: - return dpnp_cbrt(x1_desc).get_pyobj() - - return call_origin(numpy.cbrt, x1, **kwargs) def cos( @@ -787,39 +816,59 @@ def exp( ) -def exp2(x1): +def exp2( + x, + /, + out=None, + *, + order="K", + where=True, + dtype=None, + subok=True, + **kwargs, +): """ Calculate `2**p` for all `p` in the input array. For full documentation refer to :obj:`numpy.exp2`. + Returns + ------- + out : dpnp.ndarray + Element-wise 2 to the power `x`. + Limitations ----------- - Input array is supported as :obj:`dpnp.ndarray`. + Parameter `x` is only supported as either :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`. + Parameters `where`, `dtype` and `subok` are supported with their default values. + Keyword argument `kwargs` is currently unsupported. + 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.power` : First array elements raised to powers from - second array, element-wise. + :obj:`dpnp.power` : First array elements raised to powers from second array, element-wise. Examples -------- >>> import dpnp as np >>> x = np.arange(3.) - >>> out = np.exp2(x) - >>> [i for i in out] - [1.0, 2.0, 4.0] + >>> np.exp2(x) + array([1., 2., 4.]) """ - x1_desc = dpnp.get_dpnp_descriptor( - x1, copy_when_strides=False, copy_when_nondefault_queue=False + return check_nd_call_func( + numpy.exp2, + dpnp_exp2, + x, + out=out, + where=where, + order=order, + dtype=dtype, + subok=subok, + **kwargs, ) - if x1_desc: - return dpnp_exp2(x1_desc).get_pyobj() - - return call_origin(numpy.exp2, x1) def expm1( @@ -1290,6 +1339,60 @@ def reciprocal(x1, **kwargs): return call_origin(numpy.reciprocal, x1, **kwargs) +def rsqrt( + x, + /, + out=None, + *, + order="K", + where=True, + dtype=None, + subok=True, + **kwargs, +): + """ + Computes the reciprocal square-root for each element `x_i` for input array `x`. + + Returns + ------- + out : dpnp.ndarray + The reciprocal square-root, element-wise. + + Limitations + ----------- + Parameter `x` is only supported as either :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`. + Parameters `where`, `dtype` and `subok` are supported with their default values. + Keyword argument `kwargs` is currently unsupported. + Otherwise the function will be executed sequentially on CPU. + Input array data types are limited by real-valued data types. + + See Also + -------- + :obj:`dpnp.sqrt` : Return the positive square-root of an array, element-wise. + :obj:`dpnp.reciprocal` : Return the reciprocal of an array, element-wise. + + Examples + -------- + >>> import dpnp as np + >>> x = np.array([1,8,27]) + >>> np.rsqrt(x) + array([1. , 0.35355338, 0.19245009]) + + """ + + return check_nd_call_func( + None, + dpnp_rsqrt, + x, + out=out, + where=where, + order=order, + dtype=dtype, + subok=subok, + **kwargs, + ) + + def rad2deg(x1): """ Convert angles from radians to degrees. diff --git a/tests/skipped_tests.tbl b/tests/skipped_tests.tbl index e61f7497d97d..91dc0135c86a 100644 --- a/tests/skipped_tests.tbl +++ b/tests/skipped_tests.tbl @@ -73,9 +73,7 @@ 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_strides.py::test_strides_1arg[(10,)-None-cbrt] tests/test_strides.py::test_strides_1arg[(10,)-None-degrees] -tests/test_strides.py::test_strides_1arg[(10,)-None-exp2] tests/test_strides.py::test_strides_1arg[(10,)-None-fabs] tests/test_strides.py::test_strides_1arg[(10,)-None-radians] tests/test_strides.py::test_strides_erf[(10,)-None] @@ -435,7 +433,6 @@ tests/third_party/cupy/math_tests/test_arithmetic.py::TestArithmeticRaisesWithNu tests/third_party/cupy/math_tests/test_explog.py::TestExplog::test_logaddexp2 tests/third_party/cupy/math_tests/test_explog.py::TestExplog::test_logaddexp2_infinities -tests/third_party/cupy/math_tests/test_floating.py::TestFloating::test_copysign_float tests/third_party/cupy/math_tests/test_floating.py::TestFloating::test_frexp tests/third_party/cupy/math_tests/test_floating.py::TestFloating::test_ldexp tests/third_party/cupy/math_tests/test_floating.py::TestFloating::test_nextafter_combination @@ -472,7 +469,6 @@ tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_external_clip1 tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_external_clip2 tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_external_clip3 tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_clip2 -tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_cbrt tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_fabs tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_fabs_negative tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_nan_to_num_scalar_nan diff --git a/tests/skipped_tests_gpu.tbl b/tests/skipped_tests_gpu.tbl index a8d198b77334..391e312f7b5c 100644 --- a/tests/skipped_tests_gpu.tbl +++ b/tests/skipped_tests_gpu.tbl @@ -530,7 +530,6 @@ tests/third_party/cupy/math_tests/test_arithmetic.py::TestArithmeticRaisesWithNu tests/third_party/cupy/math_tests/test_explog.py::TestExplog::test_logaddexp2 tests/third_party/cupy/math_tests/test_explog.py::TestExplog::test_logaddexp2_infinities -tests/third_party/cupy/math_tests/test_floating.py::TestFloating::test_copysign_float tests/third_party/cupy/math_tests/test_floating.py::TestFloating::test_frexp tests/third_party/cupy/math_tests/test_floating.py::TestFloating::test_ldexp tests/third_party/cupy/math_tests/test_floating.py::TestFloating::test_nextafter_combination @@ -567,7 +566,6 @@ tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_external_clip1 tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_external_clip2 tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_external_clip3 tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_clip2 -tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_cbrt tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_fabs tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_fabs_negative tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_nan_to_num_scalar_nan diff --git a/tests/skipped_tests_gpu_no_fp64.tbl b/tests/skipped_tests_gpu_no_fp64.tbl index 8d197a8d28cf..0e043ee7452b 100644 --- a/tests/skipped_tests_gpu_no_fp64.tbl +++ b/tests/skipped_tests_gpu_no_fp64.tbl @@ -15,26 +15,18 @@ tests/test_mathematical.py::TestGradient::test_gradient_y1_dx[3.5-array0] tests/test_mathematical.py::TestGradient::test_gradient_y1_dx[3.5-array1] tests/test_mathematical.py::TestGradient::test_gradient_y1_dx[3.5-array2] -tests/test_strides.py::test_strides_1arg[(10,)-int32-cbrt] tests/test_strides.py::test_strides_1arg[(10,)-int32-degrees] -tests/test_strides.py::test_strides_1arg[(10,)-int32-exp2] tests/test_strides.py::test_strides_1arg[(10,)-int32-fabs] tests/test_strides.py::test_strides_1arg[(10,)-int32-radians] -tests/test_strides.py::test_strides_1arg[(10,)-int64-cbrt] tests/test_strides.py::test_strides_1arg[(10,)-int64-degrees] -tests/test_strides.py::test_strides_1arg[(10,)-int64-exp2] tests/test_strides.py::test_strides_1arg[(10,)-int64-fabs] tests/test_strides.py::test_strides_1arg[(10,)-int64-radians] -tests/test_strides.py::test_strides_1arg[(10,)-None-cbrt] tests/test_strides.py::test_strides_1arg[(10,)-None-degrees] -tests/test_strides.py::test_strides_1arg[(10,)-None-exp2] tests/test_strides.py::test_strides_1arg[(10,)-None-fabs] tests/test_strides.py::test_strides_1arg[(10,)-None-radians] tests/test_umath.py::test_umaths[('floor_divide', 'ff')] -tests/test_umath.py::TestSqrt::test_sqrt_complex[complex64] - tests/third_party/cupy/linalg_tests/test_eigenvalue.py::TestEigenvalue_param_0_{UPLO='U'}::test_eigh_batched tests/third_party/cupy/linalg_tests/test_eigenvalue.py::TestEigenvalue_param_1_{UPLO='L'}::test_eigh_batched diff --git a/tests/test_sycl_queue.py b/tests/test_sycl_queue.py index 2a4a814b6f74..45dfc96518ad 100644 --- a/tests/test_sycl_queue.py +++ b/tests/test_sycl_queue.py @@ -262,6 +262,7 @@ def test_meshgrid(device_x, device_y): pytest.param("arcsinh", [-5.0, -3.5, 0.0, 3.5, 5.0]), pytest.param("arctan", [-1.0, 0.0, 1.0]), pytest.param("arctanh", [-0.5, 0.0, 0.5]), + pytest.param("cbrt", [1.0, 8.0, 27.0]), 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]), @@ -275,6 +276,7 @@ def test_meshgrid(device_x, device_y): pytest.param("diff", [1.0, 2.0, 4.0, 7.0, 0.0]), pytest.param("ediff1d", [1.0, 2.0, 4.0, 7.0, 0.0]), pytest.param("exp", [1.0, 2.0, 4.0, 7.0]), + pytest.param("exp2", [0.0, 1.0, 2.0]), pytest.param("expm1", [1.0e-10, 1.0, 2.0, 4.0, 7.0]), pytest.param("fabs", [-1.2, 1.2]), pytest.param("floor", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]), @@ -364,6 +366,25 @@ def test_proj(device): assert_sycl_queue_equal(result_queue, expected_queue) +@pytest.mark.parametrize( + "device", + valid_devices, + ids=[device.filter_string for device in valid_devices], +) +def test_rsqrt(device): + X = [1.0, 8.0, 27.0] + Y = [1.0, 0.35355338, 0.19245009] + + x = dpnp.array(X, device=device) + result = dpnp.rsqrt(x) + expected = dpnp.array(Y) + assert_allclose(result, expected) + + expected_queue = x.get_array().sycl_queue + result_queue = result.get_array().sycl_queue + assert_sycl_queue_equal(result_queue, expected_queue) + + @pytest.mark.parametrize( "func,data1,data2", [ @@ -373,15 +394,9 @@ def test_proj(device): [0.0, 1.0, 2.0, 0.0, 1.0, 2.0, 0.0, 1.0, 2.0], ), pytest.param( - "allclose", - [1.0, dpnp.inf, -dpnp.inf], - [1.0, dpnp.inf, -dpnp.inf], - ), - pytest.param( - "arctan2", - [[-1, +1, +1, -1]], - [[-1, -1, +1, +1]], + "allclose", [1.0, dpnp.inf, -dpnp.inf], [1.0, dpnp.inf, -dpnp.inf] ), + 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("cross", [1.0, 2.0, 3.0], [4.0, 5.0, 6.0]), pytest.param( @@ -403,15 +418,9 @@ def test_proj(device): [2.0, 2.0, 2.0, 2.0, 2.0, 2.0], ), pytest.param( - "hypot", - [[1.0, 2.0, 3.0, 4.0]], - [[-1.0, -2.0, -4.0, -5.0]], - ), - pytest.param( - "logaddexp", - [[-1, 2, 5, 9]], - [[4, -3, 2, -8]], + "hypot", [[1.0, 2.0, 3.0, 4.0]], [[-1.0, -2.0, -4.0, -5.0]] ), + pytest.param("logaddexp", [[-1, 2, 5, 9]], [[4, -3, 2, -8]]), pytest.param( "matmul", [[1.0, 0.0], [0.0, 1.0]], [[4.0, 1.0], [1.0, 2.0]] ), diff --git a/tests/test_umath.py b/tests/test_umath.py index 2b0db66ec0d7..35955c935bcb 100644 --- a/tests/test_umath.py +++ b/tests/test_umath.py @@ -577,6 +577,167 @@ def test_invalid_shape(self, shape, dtype): dpnp.exp(dp_array, out=dp_out) +class TestExp2: + @pytest.mark.parametrize( + "dtype", get_all_dtypes(no_bool=True, no_complex=True) + ) + def test_exp2(self, dtype): + np_array = numpy.arange(7, dtype=dtype) + np_out = numpy.empty(7, dtype=numpy.float64) + + # DPNP + dp_out_dtype = dpnp.float32 + if has_support_aspect64() and dtype != dpnp.float32: + dp_out_dtype = dpnp.float64 + + dp_array = dpnp.array(np_array, dtype=dp_out_dtype) + dp_out = dpnp.array(np_out, dtype=dp_out_dtype) + result = dpnp.exp2(dp_array, out=dp_out) + + # original + expected = numpy.exp2(np_array, out=np_out) + + tol = dpnp.finfo(dtype=result.dtype).resolution + assert_allclose(expected, result.asnumpy(), rtol=tol) + + @pytest.mark.parametrize("dtype", get_complex_dtypes()) + def test_exp2_complex(self, dtype): + x1 = numpy.linspace(0, 8, num=10) + x2 = numpy.linspace(0, 6, num=10) + Xnp = x1 + 1j * x2 + np_array = numpy.asarray(Xnp, dtype=dtype) + np_out = numpy.empty(10, dtype=numpy.complex128) + + # DPNP + dp_out_dtype = dpnp.complex64 + if has_support_aspect64() and dtype != dpnp.complex64: + dp_out_dtype = dpnp.complex128 + + dp_array = dpnp.array(np_array, dtype=dp_out_dtype) + dp_out = dpnp.array(np_out, dtype=dp_out_dtype) + result = dpnp.exp2(dp_array, out=dp_out) + + # original + expected = numpy.exp2(np_array, out=np_out) + + tol = dpnp.finfo(dtype=result.dtype).resolution + assert_allclose(expected, result.asnumpy(), rtol=tol) + + @pytest.mark.parametrize( + "dtype", get_all_dtypes(no_complex=True, no_none=True)[:-1] + ) + def test_invalid_dtype(self, dtype): + dpnp_dtype = get_all_dtypes(no_complex=True, no_none=True)[-1] + dp_array = dpnp.arange(10, dtype=dpnp_dtype) + dp_out = dpnp.empty(10, dtype=dtype) + + with pytest.raises(TypeError): + dpnp.exp2(dp_array, out=dp_out) + + @pytest.mark.parametrize("dtype", get_float_dtypes()) + @pytest.mark.parametrize( + "shape", [(0,), (15,), (2, 2)], ids=["(0,)", "(15, )", "(2,2)"] + ) + def test_invalid_shape(self, shape, dtype): + dp_array = dpnp.arange(10, dtype=dtype) + dp_out = dpnp.empty(shape, dtype=dtype) + + with pytest.raises(ValueError): + dpnp.exp2(dp_array, out=dp_out) + + +class TestCbrt: + @pytest.mark.parametrize( + "dtype", get_all_dtypes(no_bool=True, no_complex=True) + ) + def test_cbrt(self, dtype): + np_array = numpy.arange(7, dtype=dtype) + np_out = numpy.empty(7, dtype=numpy.float64) + + # DPNP + dp_out_dtype = dpnp.float32 + if has_support_aspect64() and dtype != dpnp.float32: + dp_out_dtype = dpnp.float64 + + dp_array = dpnp.array(np_array, dtype=dp_out_dtype) + dp_out = dpnp.array(np_out, dtype=dp_out_dtype) + result = dpnp.cbrt(dp_array, out=dp_out) + + # original + expected = numpy.cbrt(np_array, out=np_out) + + tol = dpnp.finfo(dtype=result.dtype).resolution + assert_allclose(expected, result.asnumpy(), rtol=tol) + + @pytest.mark.parametrize( + "dtype", get_all_dtypes(no_complex=True, no_none=True)[:-1] + ) + def test_invalid_dtype(self, dtype): + dpnp_dtype = get_all_dtypes(no_complex=True, no_none=True)[-1] + dp_array = dpnp.arange(10, dtype=dpnp_dtype) + dp_out = dpnp.empty(10, dtype=dtype) + + with pytest.raises(TypeError): + dpnp.cbrt(dp_array, out=dp_out) + + @pytest.mark.parametrize("dtype", get_float_dtypes()) + @pytest.mark.parametrize( + "shape", [(0,), (15,), (2, 2)], ids=["(0,)", "(15, )", "(2,2)"] + ) + def test_invalid_shape(self, shape, dtype): + dp_array = dpnp.arange(10, dtype=dtype) + dp_out = dpnp.empty(shape, dtype=dtype) + + with pytest.raises(ValueError): + dpnp.cbrt(dp_array, out=dp_out) + + +class TestRsqrt: + @pytest.mark.parametrize( + "dtype", get_all_dtypes(no_bool=True, no_complex=True) + ) + def test_rsqrt(self, dtype): + np_array = numpy.arange(1, 10, dtype=dtype) + np_out = numpy.empty(9, dtype=numpy.float64) + + # DPNP + dp_out_dtype = dpnp.float32 + if has_support_aspect64() and dtype != dpnp.float32: + dp_out_dtype = dpnp.float64 + + dp_array = dpnp.array(np_array, dtype=dp_out_dtype) + dp_out = dpnp.array(np_out, dtype=dp_out_dtype) + result = dpnp.rsqrt(dp_array, out=dp_out) + + # original + expected = numpy.reciprocal(numpy.sqrt(np_array), out=np_out) + + tol = dpnp.finfo(dtype=result.dtype).resolution + assert_allclose(expected, result.asnumpy(), rtol=tol) + + @pytest.mark.parametrize( + "dtype", get_all_dtypes(no_complex=True, no_none=True)[:-1] + ) + def test_invalid_dtype(self, dtype): + dpnp_dtype = get_all_dtypes(no_complex=True, no_none=True)[-1] + dp_array = dpnp.arange(10, dtype=dpnp_dtype) + dp_out = dpnp.empty(10, dtype=dtype) + + with pytest.raises(TypeError): + dpnp.rsqrt(dp_array, out=dp_out) + + @pytest.mark.parametrize("dtype", get_float_dtypes()) + @pytest.mark.parametrize( + "shape", [(0,), (15,), (2, 2)], ids=["(0,)", "(15, )", "(2,2)"] + ) + def test_invalid_shape(self, shape, dtype): + dp_array = dpnp.arange(10, dtype=dtype) + dp_out = dpnp.empty(shape, dtype=dtype) + + with pytest.raises(ValueError): + dpnp.rsqrt(dp_array, out=dp_out) + + class TestArccos: @pytest.mark.parametrize("dtype", get_float_dtypes()) @pytest.mark.usefixtures("suppress_invalid_numpy_warnings") @@ -917,6 +1078,55 @@ def test_invalid_shape(self, shape, dtype): dpnp.arctan2(dp_array, dp_array, out=dp_out) +class TestCopySign: + @pytest.mark.parametrize("dtype", get_float_dtypes()) + def test_copysign(self, dtype): + array_data = numpy.arange(10) + out = numpy.empty(10, dtype=dtype) + + # DPNP + dp_array = dpnp.array(array_data, dtype=dtype) + dp_out = dpnp.array(out, dtype=dtype) + result = dpnp.copysign(dp_array, -dp_array, out=dp_out) + + # original + np_array = numpy.array(array_data, dtype=dtype) + expected = numpy.copysign(np_array, -np_array, out=out) + + assert_allclose(expected, result) + + @pytest.mark.parametrize( + "dtype", get_all_dtypes(no_bool=True, no_complex=True, no_none=True) + ) + def test_out_dtypes(self, dtype): + if has_support_aspect64() and dtype != numpy.float32: + dtype_out = numpy.float64 + else: + dtype_out = numpy.float32 + size = 2 if dtype == dpnp.bool else 10 + + np_array = numpy.arange(size, dtype=dtype) + np_out = numpy.empty(size, dtype=dtype_out) + expected = numpy.copysign(np_array, -np_array, out=np_out) + + dp_array = dpnp.arange(size, dtype=dtype) + dp_out = dpnp.empty(size, dtype=dtype_out) + result = dpnp.copysign(dp_array, -dp_array, out=dp_out) + + assert_allclose(expected, result) + + @pytest.mark.parametrize("dtype", get_float_dtypes()) + @pytest.mark.parametrize( + "shape", [(0,), (15,), (2, 2)], ids=["(0,)", "(15, )", "(2,2)"] + ) + def test_invalid_shape(self, shape, dtype): + dp_array = dpnp.arange(10, dtype=dtype) + dp_out = dpnp.empty(shape, dtype=dtype) + + with pytest.raises(ValueError): + dpnp.copysign(dp_array, dp_array, out=dp_out) + + class TestSqrt: @pytest.mark.parametrize( "dtype", get_all_dtypes(no_bool=True, no_complex=True) diff --git a/tests/test_usm_type.py b/tests/test_usm_type.py index 99a39acae887..1fe1382a69cc 100644 --- a/tests/test_usm_type.py +++ b/tests/test_usm_type.py @@ -350,6 +350,7 @@ def test_meshgrid(usm_type_x, usm_type_y): pytest.param("arcsinh", [-5.0, -3.5, 0.0, 3.5, 5.0]), pytest.param("arctan", [-1.0, 0.0, 1.0]), pytest.param("arctanh", [-0.5, 0.0, 0.5]), + 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( @@ -358,6 +359,7 @@ def test_meshgrid(usm_type_x, usm_type_y): pytest.param("cosh", [-5.0, -3.5, 0.0, 3.5, 5.0]), pytest.param("count_nonzero", [0, 1, 7, 0]), pytest.param("exp", [1.0, 2.0, 4.0, 7.0]), + pytest.param("exp2", [0.0, 1.0, 2.0]), pytest.param("expm1", [1.0e-10, 1.0, 2.0, 4.0, 7.0]), pytest.param("floor", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]), pytest.param( @@ -377,6 +379,7 @@ def test_meshgrid(usm_type_x, usm_type_y): pytest.param( "real", [complex(1.0, 2.0), complex(3.0, 4.0), complex(5.0, 6.0)] ), + pytest.param("rsqrt", [1, 8, 27]), pytest.param("sign", [-5.0, 0.0, 4.5]), pytest.param("signbit", [-5.0, 0.0, 4.5]), pytest.param( @@ -407,46 +410,21 @@ def test_1in_1out(func, data, usm_type): [[1.2, -0.0], [-7, 2.34567]], [[1.2, 0.0], [-7, 2.34567]], ), - pytest.param( - "arctan2", - [[-1, +1, +1, -1]], - [[-1, -1, +1, +1]], - ), + 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( "dot", [[0.0, 1.0, 2.0], [3.0, 4.0, 5.0]], [[4.0, 4.0], [4.0, 4.0], [4.0, 4.0]], ), + pytest.param("fmax", [[0.0, 1.0, 2.0]], [[3.0, 4.0, 5.0]]), + pytest.param("fmin", [[0.0, 1.0, 2.0]], [[3.0, 4.0, 5.0]]), pytest.param( - "fmax", - [[0.0, 1.0, 2.0]], - [[3.0, 4.0, 5.0]], - ), - pytest.param( - "fmin", - [[0.0, 1.0, 2.0]], - [[3.0, 4.0, 5.0]], - ), - pytest.param( - "hypot", - [[1.0, 2.0, 3.0, 4.0]], - [[-1.0, -2.0, -4.0, -5.0]], - ), - pytest.param( - "logaddexp", - [[-1, 2, 5, 9]], - [[4, -3, 2, -8]], - ), - pytest.param( - "maximum", - [[0.0, 1.0, 2.0]], - [[3.0, 4.0, 5.0]], - ), - pytest.param( - "minimum", - [[0.0, 1.0, 2.0]], - [[3.0, 4.0, 5.0]], + "hypot", [[1.0, 2.0, 3.0, 4.0]], [[-1.0, -2.0, -4.0, -5.0]] ), + pytest.param("logaddexp", [[-1, 2, 5, 9]], [[4, -3, 2, -8]]), + pytest.param("maximum", [[0.0, 1.0, 2.0]], [[3.0, 4.0, 5.0]]), + pytest.param("minimum", [[0.0, 1.0, 2.0]], [[3.0, 4.0, 5.0]]), ], ) @pytest.mark.parametrize("usm_type_x", list_of_usm_types, ids=list_of_usm_types) diff --git a/tests/third_party/cupy/math_tests/test_misc.py b/tests/third_party/cupy/math_tests/test_misc.py index f8e0a32f6426..543f3d11cbcb 100644 --- a/tests/third_party/cupy/math_tests/test_misc.py +++ b/tests/third_party/cupy/math_tests/test_misc.py @@ -2,6 +2,7 @@ import pytest import dpnp as cupy +from tests.helper import has_support_aspect64 from tests.third_party.cupy import testing @@ -164,7 +165,7 @@ def test_sqrt(self): self.check_unary("sqrt") @testing.for_all_dtypes(no_complex=True) - @testing.numpy_cupy_allclose(atol=1e-5) + @testing.numpy_cupy_allclose(atol=1e-5, type_check=has_support_aspect64()) def test_cbrt(self, xp, dtype): a = testing.shaped_arange((2, 3, 4), xp, dtype) return xp.cbrt(a) From 9a913e1dd1aa15db6f230774ff9a59b15bd3c3e3 Mon Sep 17 00:00:00 2001 From: Vahid Tavanashad Date: Wed, 15 Nov 2023 10:43:22 -0600 Subject: [PATCH 2/3] address comments --- dpnp/dpnp_algo/dpnp_elementwise_common.py | 106 +++++++++++----------- dpnp/dpnp_iface_mathematical.py | 14 +++ dpnp/dpnp_iface_trigonometric.py | 35 ++++++- 3 files changed, 101 insertions(+), 54 deletions(-) diff --git a/dpnp/dpnp_algo/dpnp_elementwise_common.py b/dpnp/dpnp_algo/dpnp_elementwise_common.py index fd3f3e9cf3df..64a7d97ba04c 100644 --- a/dpnp/dpnp_algo/dpnp_elementwise_common.py +++ b/dpnp/dpnp_algo/dpnp_elementwise_common.py @@ -237,7 +237,7 @@ def _call_func(src1, src2, dst, sycl_queue, depends=None): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -281,7 +281,7 @@ def dpnp_abs(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -322,7 +322,7 @@ def dpnp_acos(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -409,7 +409,7 @@ def dpnp_add(x1, x2, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -450,7 +450,7 @@ def dpnp_asin(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type.. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -491,7 +491,7 @@ def dpnp_asinh(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type.. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -582,7 +582,7 @@ def dpnp_atan2(x1, x2, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -628,7 +628,7 @@ def dpnp_atanh(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -672,7 +672,7 @@ def dpnp_bitwise_and(x1, x2, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -716,7 +716,7 @@ def dpnp_bitwise_or(x1, x2, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -756,7 +756,7 @@ def dpnp_bitwise_xor(x1, x2, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -796,7 +796,7 @@ def dpnp_cbrt(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -835,7 +835,7 @@ def dpnp_ceil(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -878,7 +878,7 @@ def dpnp_conj(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -915,7 +915,7 @@ def dpnp_copysign(x1, x2, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -955,7 +955,7 @@ def dpnp_cos(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -1081,7 +1081,7 @@ def dpnp_equal(x1, x2, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -1122,7 +1122,7 @@ def dpnp_exp(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -1165,7 +1165,7 @@ def dpnp_exp2(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -1207,7 +1207,7 @@ def dpnp_expm1(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -1418,7 +1418,7 @@ def dpnp_hypot(x1, x2, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -1455,7 +1455,7 @@ def dpnp_imag(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -1490,7 +1490,7 @@ def dpnp_invert(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -1525,7 +1525,7 @@ def dpnp_isfinite(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -1559,7 +1559,7 @@ def dpnp_isinf(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -1598,7 +1598,7 @@ def dpnp_isnan(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -1719,7 +1719,7 @@ def dpnp_less_equal(x1, x2, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -1760,7 +1760,7 @@ def dpnp_log(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -1801,7 +1801,7 @@ def dpnp_log10(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -1841,7 +1841,7 @@ def dpnp_log1p(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -1933,7 +1933,7 @@ def dpnp_logaddexp(x1, x2, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -1971,7 +1971,7 @@ def dpnp_logical_and(x1, x2, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -2009,7 +2009,7 @@ def dpnp_logical_not(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -2050,7 +2050,7 @@ def dpnp_logical_or(x1, x2, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -2091,7 +2091,7 @@ def dpnp_logical_xor(x1, x2, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -2131,7 +2131,7 @@ def dpnp_maximum(x1, x2, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -2218,7 +2218,7 @@ def dpnp_multiply(x1, x2, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -2300,7 +2300,7 @@ def dpnp_not_equal(x1, x2, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -2386,7 +2386,7 @@ def dpnp_power(x1, x2, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -2420,7 +2420,7 @@ def dpnp_proj(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -2461,7 +2461,7 @@ def dpnp_real(x, out=None, order="K"): out ({None, usm_ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -2502,7 +2502,7 @@ def dpnp_remainder(x1, x2, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -2542,7 +2542,7 @@ def dpnp_right_shift(x1, x2, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -2581,7 +2581,7 @@ def dpnp_round(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -2620,7 +2620,7 @@ def dpnp_rsqrt(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -2659,7 +2659,7 @@ def dpnp_sign(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Returns: @@ -2693,7 +2693,7 @@ def dpnp_signbit(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -2733,7 +2733,7 @@ def dpnp_sin(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -2773,7 +2773,7 @@ def dpnp_sinh(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -2812,7 +2812,7 @@ def dpnp_sqrt(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -2912,7 +2912,7 @@ def dpnp_subtract(x1, x2, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -2952,7 +2952,7 @@ def dpnp_tan(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: @@ -2995,7 +2995,7 @@ def dpnp_tanh(x, out=None, order="K"): out ({None, dpnp.ndarray}, optional): Output array to populate. Array must have the correct shape and the expected data type. - order ("C","F","A","K", optional): + order ("C", "F", "A", "K", optional): Memory layout of the newly output array, if parameter `out` is `None`. Default: "K". Return: diff --git a/dpnp/dpnp_iface_mathematical.py b/dpnp/dpnp_iface_mathematical.py index f023a14fa251..c0f559939a4f 100644 --- a/dpnp/dpnp_iface_mathematical.py +++ b/dpnp/dpnp_iface_mathematical.py @@ -449,6 +449,20 @@ def copysign( For full documentation refer to :obj:`numpy.copysign`. + Parameters + ---------- + x1 : {dpnp.ndarray, usm_ndarray} + First input array, expected to have a real floating-point data type. + x2 : {dpnp.ndarray, usm_ndarray} + Second input array, also expected to have a real floating-point data + type. + out : ({None, dpnp.ndarray, usm_ndarray}, optional): + Output array to populate. + Array must have the correct shape and the expected data type. + order : ({'C', 'F', 'A', 'K'}, optional): + Memory layout of the newly output array, if parameter `out` is `None`. + Default: "K". + Returns ------- out : dpnp.ndarray diff --git a/dpnp/dpnp_iface_trigonometric.py b/dpnp/dpnp_iface_trigonometric.py index 5c614475ef00..7c62bf1ecf17 100644 --- a/dpnp/dpnp_iface_trigonometric.py +++ b/dpnp/dpnp_iface_trigonometric.py @@ -552,6 +552,17 @@ def cbrt( For full documentation refer to :obj:`numpy.cbrt`. + Parameters + ---------- + x : {dpnp.ndarray, usm_ndarray} + Input array, expected to have a real-valued data type. + out : ({None, dpnp.ndarray, usm_ndarray}, optional): + Output array to populate. + Array must have the correct shape and the expected data type. + order : ({'C', 'F', 'A', 'K'}, optional): + Memory layout of the newly output array, if parameter `out` is `None`. + Default: "K". + Returns ------- out : dpnp.ndarray @@ -832,6 +843,17 @@ def exp2( For full documentation refer to :obj:`numpy.exp2`. + Parameters + ---------- + x : {dpnp.ndarray, usm_ndarray} + Input array, expected to have a floating-point data type. + out : ({None, dpnp.ndarray, usm_ndarray}, optional): + Output array to populate. + Array must have the correct shape and the expected data type. + order : ({'C', 'F', 'A', 'K'}, optional): + Memory layout of the newly output array, if parameter `out` is `None`. + Default: "K". + Returns ------- out : dpnp.ndarray @@ -1353,6 +1375,17 @@ def rsqrt( """ Computes the reciprocal square-root for each element `x_i` for input array `x`. + Parameters + ---------- + x : {dpnp.ndarray, usm_ndarray} + Input array, expected to have a real floating-point data type. + out : ({None, dpnp.ndarray, usm_ndarray}, optional): + Output array to populate. + Array must have the correct shape and the expected data type. + order : ({'C', 'F', 'A', 'K'}, optional): + Memory layout of the newly output array, if parameter `out` is `None`. + Default: "K" + Returns ------- out : dpnp.ndarray @@ -1374,7 +1407,7 @@ def rsqrt( Examples -------- >>> import dpnp as np - >>> x = np.array([1,8,27]) + >>> x = np.array([1, 8, 27]) >>> np.rsqrt(x) array([1. , 0.35355338, 0.19245009]) From 50f1db0ad1310bfbc730d6b187cb591a926f55a9 Mon Sep 17 00:00:00 2001 From: Vahid Tavanashad Date: Thu, 23 Nov 2023 09:15:47 -0600 Subject: [PATCH 3/3] address comments - 2nd round --- dpnp/dpnp_algo/dpnp_elementwise_common.py | 162 +++++++++--------- dpnp/dpnp_iface_mathematical.py | 5 + dpnp/dpnp_iface_trigonometric.py | 7 + tests/test_strides.py | 14 ++ tests/test_sycl_queue.py | 4 +- .../third_party/cupy/math_tests/test_misc.py | 2 +- 6 files changed, 112 insertions(+), 82 deletions(-) diff --git a/dpnp/dpnp_algo/dpnp_elementwise_common.py b/dpnp/dpnp_algo/dpnp_elementwise_common.py index 64a7d97ba04c..bd7babbe01d0 100644 --- a/dpnp/dpnp_algo/dpnp_elementwise_common.py +++ b/dpnp/dpnp_algo/dpnp_elementwise_common.py @@ -159,16 +159,22 @@ def check_nd_call_func( ) ) return dpnp_func(*x_args, out=out, order=order) - return call_origin( - origin_func, - *x_args, - out=out, - where=where, - order=order, - dtype=dtype, - subok=subok, - **kwargs, - ) + if origin_func is not None: + return call_origin( + origin_func, + *x_args, + out=out, + where=where, + order=order, + dtype=dtype, + subok=subok, + **kwargs, + ) + else: + raise NotImplementedError( + f"Requested function={dpnp_func.__name__} with args={x_args} and kwargs={kwargs} " + "isn't currently supported." + ) def _make_unary_func( @@ -238,7 +244,7 @@ def _call_func(src1, src2, dst, sycl_queue, depends=None): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -282,7 +288,7 @@ def dpnp_abs(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -323,7 +329,7 @@ def dpnp_acos(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -367,7 +373,7 @@ def dpnp_acosh(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -410,7 +416,7 @@ def dpnp_add(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -451,7 +457,7 @@ def dpnp_asin(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type.. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -492,7 +498,7 @@ def dpnp_asinh(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type.. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -539,7 +545,7 @@ def dpnp_atan(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -583,7 +589,7 @@ def dpnp_atan2(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -629,7 +635,7 @@ def dpnp_atanh(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -673,7 +679,7 @@ def dpnp_bitwise_and(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -717,7 +723,7 @@ def dpnp_bitwise_or(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -757,7 +763,7 @@ def dpnp_bitwise_xor(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -797,7 +803,7 @@ def dpnp_cbrt(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -836,7 +842,7 @@ def dpnp_ceil(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -879,7 +885,7 @@ def dpnp_conj(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -916,7 +922,7 @@ def dpnp_copysign(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -956,7 +962,7 @@ def dpnp_cos(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -999,7 +1005,7 @@ def dpnp_cosh(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1045,7 +1051,7 @@ def dpnp_divide(x1, x2, out=None, order="K"): Output array to populate. Array have the correct shape and the expected data type. order ("C","F","A","K", None, optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1082,7 +1088,7 @@ def dpnp_equal(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -1123,7 +1129,7 @@ def dpnp_exp(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -1166,7 +1172,7 @@ def dpnp_exp2(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -1208,7 +1214,7 @@ def dpnp_expm1(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -1251,7 +1257,7 @@ def dpnp_floor(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1294,7 +1300,7 @@ def dpnp_floor_divide(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1334,7 +1340,7 @@ def dpnp_greater(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1376,7 +1382,7 @@ def dpnp_greater_equal(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1419,7 +1425,7 @@ def dpnp_hypot(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1456,7 +1462,7 @@ def dpnp_imag(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -1491,7 +1497,7 @@ def dpnp_invert(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1526,7 +1532,7 @@ def dpnp_isfinite(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1560,7 +1566,7 @@ def dpnp_isinf(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1599,7 +1605,7 @@ def dpnp_isnan(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1641,7 +1647,7 @@ def dpnp_left_shift(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1681,7 +1687,7 @@ def dpnp_less(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1720,7 +1726,7 @@ def dpnp_less_equal(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -1761,7 +1767,7 @@ def dpnp_log(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -1802,7 +1808,7 @@ def dpnp_log10(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -1842,7 +1848,7 @@ def dpnp_log1p(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -1892,7 +1898,7 @@ def dpnp_log2(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1934,7 +1940,7 @@ def dpnp_logaddexp(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1972,7 +1978,7 @@ def dpnp_logical_and(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -2010,7 +2016,7 @@ def dpnp_logical_not(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -2051,7 +2057,7 @@ def dpnp_logical_or(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -2092,7 +2098,7 @@ def dpnp_logical_xor(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -2132,7 +2138,7 @@ def dpnp_maximum(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -2172,7 +2178,7 @@ def dpnp_minimum(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -2219,7 +2225,7 @@ def dpnp_multiply(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -2262,7 +2268,7 @@ def dpnp_negative(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -2301,7 +2307,7 @@ def dpnp_not_equal(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -2343,7 +2349,7 @@ def dpnp_positive(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): - Output array, if parameter `out` is `None`. + Output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -2387,7 +2393,7 @@ def dpnp_power(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -2421,7 +2427,7 @@ def dpnp_proj(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -2462,7 +2468,7 @@ def dpnp_real(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -2503,7 +2509,7 @@ def dpnp_remainder(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -2543,7 +2549,7 @@ def dpnp_right_shift(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -2582,7 +2588,7 @@ def dpnp_round(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -2621,7 +2627,7 @@ def dpnp_rsqrt(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -2660,7 +2666,7 @@ def dpnp_sign(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -2694,7 +2700,7 @@ def dpnp_signbit(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -2734,7 +2740,7 @@ def dpnp_sin(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -2774,7 +2780,7 @@ def dpnp_sinh(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -2813,7 +2819,7 @@ def dpnp_sqrt(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -2855,7 +2861,7 @@ def dpnp_square(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C","F","A","K", None, optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -2913,7 +2919,7 @@ def dpnp_subtract(x1, x2, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -2953,7 +2959,7 @@ def dpnp_tan(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: @@ -2996,7 +3002,7 @@ def dpnp_tanh(x, out=None, order="K"): Output array to populate. Array must have the correct shape and the expected data type. order ("C", "F", "A", "K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Return: dpnp.ndarray: diff --git a/dpnp/dpnp_iface_mathematical.py b/dpnp/dpnp_iface_mathematical.py index c0f559939a4f..ebe87c9ba2a0 100644 --- a/dpnp/dpnp_iface_mathematical.py +++ b/dpnp/dpnp_iface_mathematical.py @@ -477,6 +477,11 @@ def copysign( Otherwise the function will be executed sequentially on CPU. Input array data types are limited by supported real data types. + See Also + -------- + :obj:`dpnp.negative` : Return the numerical negative of each element of `x`. + :obj:`dpnp.positive` : Return the numerical positive of each element of `x`. + Examples -------- >>> import dpnp as np diff --git a/dpnp/dpnp_iface_trigonometric.py b/dpnp/dpnp_iface_trigonometric.py index 7c62bf1ecf17..5b6447831dfa 100644 --- a/dpnp/dpnp_iface_trigonometric.py +++ b/dpnp/dpnp_iface_trigonometric.py @@ -869,6 +869,8 @@ def exp2( See Also -------- + :obj:`dpnp.exp` : Calculate exponential for all elements in the array. + :obj:`dpnp.expm1` : ``exp(x) - 1``, the inverse of :obj:`dpnp.log1p`. :obj:`dpnp.power` : First array elements raised to powers from second array, element-wise. Examples @@ -1628,6 +1630,11 @@ def sqrt( 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.cbrt` : Return the cube-root of an array, element-wise. + :obj:`dpnp.rsqrt` : Return the reciprocal square-root of an array, element-wise. + Examples -------- >>> import dpnp as np diff --git a/tests/test_strides.py b/tests/test_strides.py index 098ff53f1e0b..071c92a8a35c 100644 --- a/tests/test_strides.py +++ b/tests/test_strides.py @@ -98,6 +98,20 @@ def test_strides_1arg(func_name, dtype, shape): assert_allclose(result, expected, rtol=1e-06) +@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True)) +def test_strides_rsqrt(dtype): + a = numpy.arange(1, 11, dtype=dtype) + b = a[::2] + + dpa = dpnp.arange(1, 11, dtype=dtype) + dpb = dpa[::2] + + result = dpnp.rsqrt(dpb) + expected = 1 / numpy.sqrt(b) + + assert_allclose(result, expected, rtol=1e-06) + + @pytest.mark.parametrize( "func_name", [ diff --git a/tests/test_sycl_queue.py b/tests/test_sycl_queue.py index 45dfc96518ad..9d0eaf255817 100644 --- a/tests/test_sycl_queue.py +++ b/tests/test_sycl_queue.py @@ -373,11 +373,9 @@ def test_proj(device): ) def test_rsqrt(device): X = [1.0, 8.0, 27.0] - Y = [1.0, 0.35355338, 0.19245009] - x = dpnp.array(X, device=device) result = dpnp.rsqrt(x) - expected = dpnp.array(Y) + expected = 1 / numpy.sqrt(x.asnumpy()) assert_allclose(result, expected) expected_queue = x.get_array().sycl_queue diff --git a/tests/third_party/cupy/math_tests/test_misc.py b/tests/third_party/cupy/math_tests/test_misc.py index 543f3d11cbcb..c05432e36427 100644 --- a/tests/third_party/cupy/math_tests/test_misc.py +++ b/tests/third_party/cupy/math_tests/test_misc.py @@ -8,7 +8,7 @@ class TestMisc: @testing.for_all_dtypes() - @testing.numpy_cupy_allclose(atol=1e-5, type_check=False) + @testing.numpy_cupy_allclose(atol=1e-5, type_check=has_support_aspect64()) def check_unary(self, name, xp, dtype, no_bool=False): if no_bool and numpy.dtype(dtype).char == "?": return numpy.int_(0)