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] = { @@ -1465,19 +1435,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 2ec000ad573f..80c6035d7a9f 100644 --- a/dpnp/dpnp_algo/dpnp_algo.pxd +++ b/dpnp/dpnp_algo/dpnp_algo.pxd @@ -38,16 +38,12 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na DPNP_FN_ARANGE 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 @@ -76,8 +72,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 @@ -354,8 +348,6 @@ cpdef dpnp_descriptor dpnp_sort(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..bd7babbe01d0 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", @@ -155,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( @@ -231,10 +241,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 +285,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 +326,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,9 +371,9 @@ 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`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -403,10 +413,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 +454,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 +495,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,9 +543,9 @@ 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`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -576,10 +586,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,9 +633,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -667,9 +677,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -711,9 +721,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -740,6 +750,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 +800,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 +830,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,9 +1003,9 @@ 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`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -960,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: @@ -994,10 +1085,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 +1117,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 +1169,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 +1211,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,9 +1255,9 @@ 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`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1166,9 +1298,9 @@ 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`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1206,9 +1338,9 @@ 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`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1248,9 +1380,9 @@ 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`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1291,9 +1423,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -1329,8 +1461,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,9 +1495,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -1398,9 +1530,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -1432,9 +1564,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -1471,9 +1603,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -1513,9 +1645,9 @@ 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`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1553,9 +1685,9 @@ 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`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1591,10 +1723,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 +1764,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 +1805,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 +1845,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,9 +1896,9 @@ 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`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -1806,9 +1938,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -1843,10 +1975,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,9 +2014,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -1923,9 +2055,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -1964,9 +2096,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -2004,9 +2136,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -2044,9 +2176,9 @@ 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`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -2091,9 +2223,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -2134,9 +2266,9 @@ 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`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -2173,9 +2305,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -2217,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: @@ -2259,9 +2391,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -2293,9 +2425,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -2334,9 +2466,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -2375,9 +2507,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -2414,10 +2546,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 +2576,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,9 +2625,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -2497,9 +2664,9 @@ 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. - order ("C","F","A","K", optional): - Memory layout of the newly output array, if parameter `out` is `None`. + 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: @@ -2530,10 +2697,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 +2737,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 +2777,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 +2816,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,9 +2859,9 @@ 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`. + Memory layout of the newly output array, if parameter `out` is ``None``. Default: "K". Returns: dpnp.ndarray: @@ -2749,10 +2916,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 +2956,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 +2999,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 d9e0155ca118..cacab84510bc 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,13 +433,36 @@ 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. 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 @@ -451,7 +475,12 @@ 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. + + 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 -------- @@ -471,60 +500,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..5b6447831dfa 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,70 @@ 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`. + 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 + 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 +827,72 @@ 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`. + 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 + 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.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 -------- >>> 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 +1363,71 @@ 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`. + + 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 + 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. @@ -1492,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/skipped_tests.tbl b/tests/skipped_tests.tbl index 05acfa51b740..d32f1ee78c0c 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] @@ -409,7 +407,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 @@ -446,7 +443,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 77c23e454175..c5cf53b2a71c 100644 --- a/tests/skipped_tests_gpu.tbl +++ b/tests/skipped_tests_gpu.tbl @@ -504,7 +504,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 @@ -541,7 +540,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_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 43d89a27cb8e..6de86cfd915f 100644 --- a/tests/test_sycl_queue.py +++ b/tests/test_sycl_queue.py @@ -340,6 +340,7 @@ def test_meshgrid(device_x, device_y): pytest.param("arctanh", [-0.5, 0.0, 0.5]), pytest.param("argmax", [1.0, 2.0, 4.0, 7.0]), pytest.param("argmin", [1.0, 2.0, 4.0, 7.0]), + 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]), @@ -353,6 +354,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]), @@ -443,6 +445,23 @@ 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] + x = dpnp.array(X, device=device) + result = dpnp.rsqrt(x) + expected = 1 / numpy.sqrt(x.asnumpy()) + 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", [ @@ -452,15 +471,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( @@ -482,15 +495,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 7d31cb7f25aa..bc0919643bd3 100644 --- a/tests/test_usm_type.py +++ b/tests/test_usm_type.py @@ -374,6 +374,7 @@ def test_meshgrid(usm_type_x, usm_type_y): pytest.param("arctanh", [-0.5, 0.0, 0.5]), pytest.param("argmax", [1.0, 2.0, 4.0, 7.0]), pytest.param("argmin", [1.0, 2.0, 4.0, 7.0]), + 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( @@ -382,6 +383,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( @@ -402,6 +404,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( @@ -432,46 +435,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..c05432e36427 100644 --- a/tests/third_party/cupy/math_tests/test_misc.py +++ b/tests/third_party/cupy/math_tests/test_misc.py @@ -2,12 +2,13 @@ import pytest import dpnp as cupy +from tests.helper import has_support_aspect64 from tests.third_party.cupy import testing 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) @@ -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)