Skip to content

Commit b401ae9

Browse files
vtavanaantonwolfy
andauthored
implement dpnp.reciprocal and dpnp.angle (#1650)
* implement dpnp.reciprocal and dpnp.angle * fix docstring * skip umath test for reciprocal * address comments * add a note for reciprocal * Update dpnp/dpnp_iface_trigonometric.py Co-authored-by: Anton <[email protected]> * fix docstring * update retunrs for angle and reciprocal update out keyword implementation for angle and reciprocal to make it consistent with implementation of other functions * Updated TestReciprocal to be compliant with the latest available dpctl in internal CI --------- Co-authored-by: Anton <[email protected]> Co-authored-by: Anton Volkov <[email protected]>
1 parent 8935acf commit b401ae9

24 files changed

+415
-151
lines changed

dpnp/backend/include/dpnp_iface_fptr.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,6 @@ enum class DPNPFuncName : size_t
231231
parameters */
232232
DPNP_FN_REMAINDER, /**< Used in numpy.remainder() impl */
233233
DPNP_FN_RECIP, /**< Used in numpy.recip() impl */
234-
DPNP_FN_RECIP_EXT, /**< Used in numpy.recip() impl, requires extra
235-
parameters */
236234
DPNP_FN_REPEAT, /**< Used in numpy.repeat() impl */
237235
DPNP_FN_RIGHT_SHIFT, /**< Used in numpy.right_shift() impl */
238236
DPNP_FN_RNG_BETA, /**< Used in numpy.random.beta() impl */

dpnp/backend/kernels/dpnp_krnl_elemwise.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -934,15 +934,6 @@ static void func_map_init_elemwise_1arg_1type(func_map_t &fmap)
934934
fmap[DPNPFuncName::DPNP_FN_RECIP][eft_DBL][eft_DBL] = {
935935
eft_DBL, (void *)dpnp_recip_c_default<double>};
936936

937-
fmap[DPNPFuncName::DPNP_FN_RECIP_EXT][eft_INT][eft_INT] = {
938-
eft_INT, (void *)dpnp_recip_c_ext<int32_t>};
939-
fmap[DPNPFuncName::DPNP_FN_RECIP_EXT][eft_LNG][eft_LNG] = {
940-
eft_LNG, (void *)dpnp_recip_c_ext<int64_t>};
941-
fmap[DPNPFuncName::DPNP_FN_RECIP_EXT][eft_FLT][eft_FLT] = {
942-
eft_FLT, (void *)dpnp_recip_c_ext<float>};
943-
fmap[DPNPFuncName::DPNP_FN_RECIP_EXT][eft_DBL][eft_DBL] = {
944-
eft_DBL, (void *)dpnp_recip_c_ext<double>};
945-
946937
fmap[DPNPFuncName::DPNP_FN_SIGN][eft_INT][eft_INT] = {
947938
eft_INT, (void *)dpnp_sign_c_default<int32_t>};
948939
fmap[DPNPFuncName::DPNP_FN_SIGN][eft_LNG][eft_LNG] = {

dpnp/dpnp_algo/dpnp_algo.pxd

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
104104
DPNP_FN_QR_EXT
105105
DPNP_FN_RADIANS
106106
DPNP_FN_RADIANS_EXT
107-
DPNP_FN_RECIP
108-
DPNP_FN_RECIP_EXT
109107
DPNP_FN_RNG_BETA
110108
DPNP_FN_RNG_BETA_EXT
111109
DPNP_FN_RNG_BINOMIAL
@@ -322,4 +320,3 @@ Trigonometric functions
322320
"""
323321
cpdef dpnp_descriptor dpnp_degrees(dpnp_descriptor array1)
324322
cpdef dpnp_descriptor dpnp_radians(dpnp_descriptor array1)
325-
cpdef dpnp_descriptor dpnp_recip(dpnp_descriptor array1)

dpnp/dpnp_algo/dpnp_algo_trigonometric.pxi

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ and the rest of the library
3838
__all__ += [
3939
'dpnp_degrees',
4040
'dpnp_radians',
41-
'dpnp_recip',
4241
'dpnp_unwrap'
4342
]
4443

@@ -47,10 +46,6 @@ cpdef utils.dpnp_descriptor dpnp_degrees(utils.dpnp_descriptor x1):
4746
return call_fptr_1in_1out_strides(DPNP_FN_DEGREES_EXT, x1)
4847

4948

50-
cpdef utils.dpnp_descriptor dpnp_recip(utils.dpnp_descriptor x1):
51-
return call_fptr_1in_1out_strides(DPNP_FN_RECIP_EXT, x1)
52-
53-
5449
cpdef utils.dpnp_descriptor dpnp_radians(utils.dpnp_descriptor x1):
5550
return call_fptr_1in_1out_strides(DPNP_FN_RADIANS_EXT, x1)
5651

dpnp/dpnp_algo/dpnp_elementwise_common.py

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"dpnp_acos",
3939
"dpnp_acosh",
4040
"dpnp_add",
41+
"dpnp_angle",
4142
"dpnp_asin",
4243
"dpnp_asinh",
4344
"dpnp_atan",
@@ -88,6 +89,7 @@
8889
"dpnp_power",
8990
"dpnp_proj",
9091
"dpnp_real",
92+
"dpnp_reciprocal",
9193
"dpnp_remainder",
9294
"dpnp_right_shift",
9395
"dpnp_round",
@@ -189,6 +191,7 @@ def _make_unary_func(
189191
):
190192
impl_fn = dpt_unary_fn.get_implementation_function()
191193
type_resolver_fn = dpt_unary_fn.get_type_result_resolver_function()
194+
acceptance_fn = dpt_unary_fn.get_type_promotion_path_acceptance_function()
192195

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

204207
func = dpt_unary_fn.__class__(
205-
name, type_resolver_fn, _call_func, fn_docstring
208+
name, type_resolver_fn, _call_func, fn_docstring, acceptance_fn
206209
)
207210
return func
208211

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

413416

417+
_angle_docstring = """
418+
angle(x, out=None, order="K")
419+
420+
Computes the phase angle (also called the argument) of each element `x_i` for
421+
input array `x`.
422+
423+
Args:
424+
x (dpnp.ndarray):
425+
Input array, expected to have a complex-valued floating-point data type.
426+
out ({None, dpnp.ndarray}, optional):
427+
Output array to populate.
428+
Array must have the correct shape and the expected data type.
429+
order ("C", "F", "A", "K", optional):
430+
Memory layout of the newly output array, if parameter `out` is ``None``.
431+
Default: "K".
432+
Returns:
433+
dpnp.ndarray:
434+
An array containing the element-wise phase angles.
435+
The returned array has a floating-point data type determined
436+
by the Type Promotion Rules.
437+
"""
438+
439+
angle_func = _make_unary_func("angle", dpt.angle, _angle_docstring)
440+
441+
442+
def dpnp_angle(x, out=None, order="K"):
443+
"""Invokes angle() from dpctl.tensor implementation for angle() function."""
444+
445+
# dpctl.tensor only works with usm_ndarray
446+
x1_usm = dpnp.get_usm_ndarray(x)
447+
out_usm = None if out is None else dpnp.get_usm_ndarray(out)
448+
449+
res_usm = angle_func(x1_usm, out=out_usm, order=order)
450+
return _get_result(res_usm, out=out)
451+
452+
414453
_asin_docstring = """
415454
asin(x, out=None, order='K')
416455
@@ -2459,6 +2498,43 @@ def dpnp_real(x, out=None, order="K"):
24592498
return _get_result(res_usm, out=out)
24602499

24612500

2501+
_reciprocal_docstring = """
2502+
reciprocal(x, out=None, order="K")
2503+
2504+
Computes the reciprocal of each element `x_i` for input array `x`.
2505+
2506+
Args:
2507+
x (dpnp.ndarray):
2508+
Input array, expected to have a real-valued floating-point data type.
2509+
out ({None, dpnp.ndarray}, optional):
2510+
Output array to populate.
2511+
Array must have the correct shape and the expected data type.
2512+
order ("C", "F", "A", "K", optional):
2513+
Memory layout of the newly output array, if parameter `out` is ``None``.
2514+
Default: "K".
2515+
Returns:
2516+
dpnp.ndarray:
2517+
An array containing the element-wise reciprocals.
2518+
The returned array has a floating-point data type determined
2519+
by the Type Promotion Rules.
2520+
"""
2521+
2522+
reciprocal_func = _make_unary_func(
2523+
"reciprocal", dpt.reciprocal, _reciprocal_docstring
2524+
)
2525+
2526+
2527+
def dpnp_reciprocal(x, out=None, order="K"):
2528+
"""Invokes reciprocal() from dpctl.tensor implementation for reciprocal() function."""
2529+
2530+
# dpctl.tensor only works with usm_ndarray
2531+
x1_usm = dpnp.get_usm_ndarray(x)
2532+
out_usm = None if out is None else dpnp.get_usm_ndarray(out)
2533+
2534+
res_usm = reciprocal_func(x1_usm, out=out_usm, order=order)
2535+
return _get_result(res_usm, out=out)
2536+
2537+
24622538
_remainder_docstring = """
24632539
remainder(x1, x2, out=None, order='K')
24642540

dpnp/dpnp_iface_arraycreation.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ def empty_like(
788788
789789
Limitations
790790
-----------
791-
Parameter `x1` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray`
791+
Parameter `x1` is supported as :class:`dpnp.dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`
792792
Parameter `order` is supported with values ``"C"`` or ``"F"``.
793793
Parameter `subok` is supported only with default value ``False``.
794794
Otherwise the function will be executed sequentially on CPU.
@@ -1050,7 +1050,7 @@ def full_like(
10501050
10511051
Limitations
10521052
-----------
1053-
Parameter `x1` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray`
1053+
Parameter `x1` is supported as :class:`dpnp.dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`
10541054
Parameter `order` is supported only with values ``"C"`` and ``"F"``.
10551055
Parameter `subok` is supported only with default value ``False``.
10561056
Otherwise the function will be executed sequentially on CPU.
@@ -1396,7 +1396,7 @@ def meshgrid(*xi, copy=True, sparse=False, indexing="xy"):
13961396
13971397
Limitations
13981398
-----------
1399-
Each array instance from `xi` is supported as either :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray`.
1399+
Each array instance from `xi` is supported as either :class:`dpnp.dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`.
14001400
Parameter `copy` is supported only with default value ``True``.
14011401
Parameter `sparse` is supported only with default value ``False``.
14021402
Otherwise the function will be executed sequentially on CPU.
@@ -1653,7 +1653,7 @@ def ones_like(
16531653
16541654
Limitations
16551655
-----------
1656-
Parameter `x1` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray`
1656+
Parameter `x1` is supported as :class:`dpnp.dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`
16571657
Parameter `order` is supported with values ``"C"`` or ``"F"``.
16581658
Parameter `subok` is supported only with default value ``False``.
16591659
Otherwise the function will be executed sequentially on CPU.
@@ -1823,7 +1823,7 @@ def tril(x1, /, *, k=0):
18231823
18241824
Limitations
18251825
-----------
1826-
Parameter `x1` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray` with two or more dimensions.
1826+
Parameter `x1` is supported as :class:`dpnp.dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray` with two or more dimensions.
18271827
Parameter `k` is supported only of integer data type.
18281828
Otherwise the function will be executed sequentially on CPU.
18291829
@@ -1867,7 +1867,7 @@ def triu(x1, /, *, k=0):
18671867
18681868
Limitations
18691869
-----------
1870-
Parameter `x1` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray` with two or more dimensions.
1870+
Parameter `x1` is supported as :class:`dpnp.dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray` with two or more dimensions.
18711871
Parameter `k` is supported only of integer data type.
18721872
Otherwise the function will be executed sequentially on CPU.
18731873
@@ -2055,7 +2055,7 @@ def zeros_like(
20552055
20562056
Limitations
20572057
-----------
2058-
Parameter `x1` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray`
2058+
Parameter `x1` is supported as :class:`dpnp.dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`
20592059
Parameter `order` is supported with values ``"C"`` or ``"F"``.
20602060
Parameter `subok` is supported only with default value ``False``.
20612061
Otherwise the function will be executed sequentially on CPU.

dpnp/dpnp_iface_bitwise.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# cython: language_level=3
2-
# distutils: language = c++
31
# -*- coding: utf-8 -*-
42
# *****************************************************************************
53
# Copyright (c) 2016-2024, Intel Corporation

dpnp/dpnp_iface_manipulation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ def ravel(a, order="C"):
11741174
11751175
Parameters
11761176
----------
1177-
x : {dpnp_array, usm_ndarray}
1177+
x : {dpnp.ndarray, usm_ndarray}
11781178
Input array. The elements in `a` are read in the order specified by order,
11791179
and packed as a 1-D array.
11801180
order : {'C', 'F'}, optional
@@ -1187,7 +1187,7 @@ def ravel(a, order="C"):
11871187
11881188
Returns
11891189
-------
1190-
out : dpnp_array
1190+
out : dpnp.ndarray
11911191
A contiguous 1-D array of the same subtype as `a`, with shape (a.size,).
11921192
11931193
See Also
@@ -1220,7 +1220,7 @@ def repeat(a, repeats, axis=None):
12201220
12211221
Parameters
12221222
----------
1223-
x : {dpnp_array, usm_ndarray}
1223+
x : {dpnp.ndarray, usm_ndarray}
12241224
Input array.
12251225
repeat : int or array of int
12261226
The number of repetitions for each element. `repeats` is broadcasted to fit
@@ -1231,7 +1231,7 @@ def repeat(a, repeats, axis=None):
12311231
12321232
Returns
12331233
-------
1234-
out : dpnp_array
1234+
out : dpnp.ndarray
12351235
Output array which has the same shape as `a`, except along the given axis.
12361236
12371237
See Also

0 commit comments

Comments
 (0)