Skip to content

implement dpnp.reciprocal and dpnp.angle #1650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions dpnp/backend/include/dpnp_iface_fptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ enum class DPNPFuncName : size_t
parameters */
DPNP_FN_REMAINDER, /**< Used in numpy.remainder() impl */
DPNP_FN_RECIP, /**< Used in numpy.recip() impl */
DPNP_FN_RECIP_EXT, /**< Used in numpy.recip() impl, requires extra
parameters */
DPNP_FN_REPEAT, /**< Used in numpy.repeat() impl */
DPNP_FN_RIGHT_SHIFT, /**< Used in numpy.right_shift() impl */
DPNP_FN_RNG_BETA, /**< Used in numpy.random.beta() impl */
Expand Down
9 changes: 0 additions & 9 deletions dpnp/backend/kernels/dpnp_krnl_elemwise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,15 +934,6 @@ static void func_map_init_elemwise_1arg_1type(func_map_t &fmap)
fmap[DPNPFuncName::DPNP_FN_RECIP][eft_DBL][eft_DBL] = {
eft_DBL, (void *)dpnp_recip_c_default<double>};

fmap[DPNPFuncName::DPNP_FN_RECIP_EXT][eft_INT][eft_INT] = {
eft_INT, (void *)dpnp_recip_c_ext<int32_t>};
fmap[DPNPFuncName::DPNP_FN_RECIP_EXT][eft_LNG][eft_LNG] = {
eft_LNG, (void *)dpnp_recip_c_ext<int64_t>};
fmap[DPNPFuncName::DPNP_FN_RECIP_EXT][eft_FLT][eft_FLT] = {
eft_FLT, (void *)dpnp_recip_c_ext<float>};
fmap[DPNPFuncName::DPNP_FN_RECIP_EXT][eft_DBL][eft_DBL] = {
eft_DBL, (void *)dpnp_recip_c_ext<double>};

fmap[DPNPFuncName::DPNP_FN_SIGN][eft_INT][eft_INT] = {
eft_INT, (void *)dpnp_sign_c_default<int32_t>};
fmap[DPNPFuncName::DPNP_FN_SIGN][eft_LNG][eft_LNG] = {
Expand Down
3 changes: 0 additions & 3 deletions dpnp/dpnp_algo/dpnp_algo.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
DPNP_FN_QR_EXT
DPNP_FN_RADIANS
DPNP_FN_RADIANS_EXT
DPNP_FN_RECIP
DPNP_FN_RECIP_EXT
DPNP_FN_RNG_BETA
DPNP_FN_RNG_BETA_EXT
DPNP_FN_RNG_BINOMIAL
Expand Down Expand Up @@ -322,4 +320,3 @@ Trigonometric functions
"""
cpdef dpnp_descriptor dpnp_degrees(dpnp_descriptor array1)
cpdef dpnp_descriptor dpnp_radians(dpnp_descriptor array1)
cpdef dpnp_descriptor dpnp_recip(dpnp_descriptor array1)
5 changes: 0 additions & 5 deletions dpnp/dpnp_algo/dpnp_algo_trigonometric.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ and the rest of the library
__all__ += [
'dpnp_degrees',
'dpnp_radians',
'dpnp_recip',
'dpnp_unwrap'
]

Expand All @@ -47,10 +46,6 @@ 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_recip(utils.dpnp_descriptor x1):
return call_fptr_1in_1out_strides(DPNP_FN_RECIP_EXT, x1)


cpdef utils.dpnp_descriptor dpnp_radians(utils.dpnp_descriptor x1):
return call_fptr_1in_1out_strides(DPNP_FN_RADIANS_EXT, x1)

Expand Down
78 changes: 77 additions & 1 deletion dpnp/dpnp_algo/dpnp_elementwise_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"dpnp_acos",
"dpnp_acosh",
"dpnp_add",
"dpnp_angle",
"dpnp_asin",
"dpnp_asinh",
"dpnp_atan",
Expand Down Expand Up @@ -88,6 +89,7 @@
"dpnp_power",
"dpnp_proj",
"dpnp_real",
"dpnp_reciprocal",
"dpnp_remainder",
"dpnp_right_shift",
"dpnp_round",
Expand Down Expand Up @@ -189,6 +191,7 @@ def _make_unary_func(
):
impl_fn = dpt_unary_fn.get_implementation_function()
type_resolver_fn = dpt_unary_fn.get_type_result_resolver_function()
acceptance_fn = dpt_unary_fn.get_type_promotion_path_acceptance_function()

def _call_func(src, dst, sycl_queue, depends=None):
"""A callback to register in UnaryElementwiseFunc class of dpctl.tensor"""
Expand All @@ -202,7 +205,7 @@ def _call_func(src, dst, sycl_queue, depends=None):
return impl_fn(src, dst, sycl_queue, depends)

func = dpt_unary_fn.__class__(
name, type_resolver_fn, _call_func, fn_docstring
name, type_resolver_fn, _call_func, fn_docstring, acceptance_fn
)
return func

Expand Down Expand Up @@ -411,6 +414,42 @@ def dpnp_add(x1, x2, out=None, order="K"):
return _get_result(res_usm, out=out)


_angle_docstring = """
angle(x, out=None, order="K")

Computes the phase angle (also called the argument) of each element `x_i` for
input array `x`.

Args:
x (dpnp.ndarray):
Input array, expected to have a complex-valued 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 phase angles.
The returned array has a floating-point data type determined
by the Type Promotion Rules.
"""

angle_func = _make_unary_func("angle", dpt.angle, _angle_docstring)


def dpnp_angle(x, out=None, order="K"):
"""Invokes angle() from dpctl.tensor implementation for angle() 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 = angle_func(x1_usm, out=out_usm, order=order)
return _get_result(res_usm, out=out)


_asin_docstring = """
asin(x, out=None, order='K')

Expand Down Expand Up @@ -2459,6 +2498,43 @@ def dpnp_real(x, out=None, order="K"):
return _get_result(res_usm, out=out)


_reciprocal_docstring = """
reciprocal(x, out=None, order="K")

Computes the reciprocal of each element `x_i` for input array `x`.

Args:
x (dpnp.ndarray):
Input array, expected to have a real-valued 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 reciprocals.
The returned array has a floating-point data type determined
by the Type Promotion Rules.
"""

reciprocal_func = _make_unary_func(
"reciprocal", dpt.reciprocal, _reciprocal_docstring
)


def dpnp_reciprocal(x, out=None, order="K"):
"""Invokes reciprocal() from dpctl.tensor implementation for reciprocal() 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 = reciprocal_func(x1_usm, out=out_usm, order=order)
return _get_result(res_usm, out=out)


_remainder_docstring = """
remainder(x1, x2, out=None, order='K')

Expand Down
14 changes: 7 additions & 7 deletions dpnp/dpnp_iface_arraycreation.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ def empty_like(

Limitations
-----------
Parameter `x1` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray`
Parameter `x1` is supported as :class:`dpnp.dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`
Parameter `order` is supported with values ``"C"`` or ``"F"``.
Parameter `subok` is supported only with default value ``False``.
Otherwise the function will be executed sequentially on CPU.
Expand Down Expand Up @@ -1050,7 +1050,7 @@ def full_like(

Limitations
-----------
Parameter `x1` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray`
Parameter `x1` is supported as :class:`dpnp.dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`
Parameter `order` is supported only with values ``"C"`` and ``"F"``.
Parameter `subok` is supported only with default value ``False``.
Otherwise the function will be executed sequentially on CPU.
Expand Down Expand Up @@ -1396,7 +1396,7 @@ def meshgrid(*xi, copy=True, sparse=False, indexing="xy"):

Limitations
-----------
Each array instance from `xi` is supported as either :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray`.
Each array instance from `xi` is supported as either :class:`dpnp.dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`.
Parameter `copy` is supported only with default value ``True``.
Parameter `sparse` is supported only with default value ``False``.
Otherwise the function will be executed sequentially on CPU.
Expand Down Expand Up @@ -1653,7 +1653,7 @@ def ones_like(

Limitations
-----------
Parameter `x1` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray`
Parameter `x1` is supported as :class:`dpnp.dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`
Parameter `order` is supported with values ``"C"`` or ``"F"``.
Parameter `subok` is supported only with default value ``False``.
Otherwise the function will be executed sequentially on CPU.
Expand Down Expand Up @@ -1823,7 +1823,7 @@ def tril(x1, /, *, k=0):

Limitations
-----------
Parameter `x1` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray` with two or more dimensions.
Parameter `x1` is supported as :class:`dpnp.dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray` with two or more dimensions.
Parameter `k` is supported only of integer data type.
Otherwise the function will be executed sequentially on CPU.

Expand Down Expand Up @@ -1867,7 +1867,7 @@ def triu(x1, /, *, k=0):

Limitations
-----------
Parameter `x1` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray` with two or more dimensions.
Parameter `x1` is supported as :class:`dpnp.dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray` with two or more dimensions.
Parameter `k` is supported only of integer data type.
Otherwise the function will be executed sequentially on CPU.

Expand Down Expand Up @@ -2055,7 +2055,7 @@ def zeros_like(

Limitations
-----------
Parameter `x1` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray`
Parameter `x1` is supported as :class:`dpnp.dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`
Parameter `order` is supported with values ``"C"`` or ``"F"``.
Parameter `subok` is supported only with default value ``False``.
Otherwise the function will be executed sequentially on CPU.
Expand Down
2 changes: 0 additions & 2 deletions dpnp/dpnp_iface_bitwise.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# cython: language_level=3
# distutils: language = c++
# -*- coding: utf-8 -*-
# *****************************************************************************
# Copyright (c) 2016-2024, Intel Corporation
Expand Down
8 changes: 4 additions & 4 deletions dpnp/dpnp_iface_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ def ravel(a, order="C"):

Parameters
----------
x : {dpnp_array, usm_ndarray}
x : {dpnp.ndarray, usm_ndarray}
Input array. The elements in `a` are read in the order specified by order,
and packed as a 1-D array.
order : {'C', 'F'}, optional
Expand All @@ -1187,7 +1187,7 @@ def ravel(a, order="C"):

Returns
-------
out : dpnp_array
out : dpnp.ndarray
A contiguous 1-D array of the same subtype as `a`, with shape (a.size,).

See Also
Expand Down Expand Up @@ -1220,7 +1220,7 @@ def repeat(a, repeats, axis=None):

Parameters
----------
x : {dpnp_array, usm_ndarray}
x : {dpnp.ndarray, usm_ndarray}
Input array.
repeat : int or array of int
The number of repetitions for each element. `repeats` is broadcasted to fit
Expand All @@ -1231,7 +1231,7 @@ def repeat(a, repeats, axis=None):

Returns
-------
out : dpnp_array
out : dpnp.ndarray
Output array which has the same shape as `a`, except along the given axis.

See Also
Expand Down
Loading