Skip to content

Commit 9d6322d

Browse files
committed
address comments
1 parent 5328e9c commit 9d6322d

File tree

4 files changed

+36
-46
lines changed

4 files changed

+36
-46
lines changed

dpnp/dpnp_iface_mathematical.py

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ def angle(z, deg=False):
321321
See Also
322322
--------
323323
:obj:`dpnp.arctan2` : Element-wise arc tangent of `x1/x2` choosing the quadrant correctly.
324+
:obj:`dpnp.arctan` : Trigonometric inverse tangent, element-wise.
324325
:obj:`dpnp.absolute` : Calculate the absolute value element-wise.
325326
326327
Examples
@@ -335,18 +336,11 @@ def angle(z, deg=False):
335336
336337
"""
337338

338-
if not dpnp.isscalar(z):
339-
dpnp.check_supported_arrays_type(z)
340-
res = dpnp_angle(z)
341-
if deg is True:
342-
res = res * (180 / dpnp.pi)
343-
return res
344-
else:
345-
return call_origin(
346-
numpy.angle,
347-
z,
348-
deg=deg,
349-
)
339+
dpnp.check_supported_arrays_type(z)
340+
res = dpnp_angle(z)
341+
if deg is True:
342+
res = res * (180 / dpnp.pi)
343+
return res
350344

351345

352346
def around(x, /, decimals=0, out=None):
@@ -1536,21 +1530,23 @@ def gradient(x1, *varargs, **kwargs):
15361530
return call_origin(numpy.gradient, x1, *varargs, **kwargs)
15371531

15381532

1539-
def imag(x):
1533+
def imag(val):
15401534
"""
15411535
Return the imaginary part of the complex argument.
15421536
15431537
For full documentation refer to :obj:`numpy.imag`.
15441538
1539+
Parameters
1540+
----------
1541+
x : {dpnp.ndarray, usm_ndarray}
1542+
Input array.
1543+
15451544
Returns
15461545
-------
15471546
out : dpnp.ndarray
1548-
The imaginary component of the complex argument.
1549-
1550-
Limitations
1551-
-----------
1552-
Parameter `x` is only supported as either :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`.
1553-
Input array data types are limited by supported DPNP :ref:`Data types`.
1547+
The imaginary component of the complex argument. If `val` is real,
1548+
the type of `val` is used for the output. If `val` has complex
1549+
elements, the returned type is float.
15541550
15551551
See Also
15561552
--------
@@ -1574,12 +1570,8 @@ def imag(x):
15741570
15751571
"""
15761572

1577-
if dpnp.isscalar(x):
1578-
# input has to be an array
1579-
pass
1580-
else:
1581-
return dpnp_imag(x)
1582-
return call_origin(numpy.imag, x)
1573+
dpnp.check_supported_arrays_type(val)
1574+
return dpnp_imag(val)
15831575

15841576

15851577
def maximum(
@@ -2268,21 +2260,23 @@ def proj(
22682260
)
22692261

22702262

2271-
def real(x):
2263+
def real(val):
22722264
"""
22732265
Return the real part of the complex argument.
22742266
22752267
For full documentation refer to :obj:`numpy.real`.
22762268
2269+
Parameters
2270+
----------
2271+
x : {dpnp.ndarray, usm_ndarray}
2272+
Input array.
2273+
22772274
Returns
22782275
-------
22792276
out : dpnp.ndarray
2280-
The real component of the complex argument.
2281-
2282-
Limitations
2283-
-----------
2284-
Parameter `x` is only supported as either :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`.
2285-
Input array data types are limited by supported DPNP :ref:`Data types`.
2277+
The real component of the complex argument. If `val` is real,
2278+
the type of `val` is used for the output. If `val` has complex
2279+
elements, the returned type is float.
22862280
22872281
See Also
22882282
--------
@@ -2309,15 +2303,12 @@ def real(x):
23092303
array(1.)
23102304
23112305
"""
2312-
if dpnp.isscalar(x):
2313-
# input has to be an array
2314-
pass
2306+
2307+
dpnp.check_supported_arrays_type(val)
2308+
if dpnp.issubsctype(val.dtype, dpnp.complexfloating):
2309+
return dpnp_real(val)
23152310
else:
2316-
if dpnp.issubsctype(x.dtype, dpnp.complexfloating):
2317-
return dpnp_real(x)
2318-
else:
2319-
return x
2320-
return call_origin(numpy.real, x)
2311+
return val
23212312

23222313

23232314
def remainder(

dpnp/dpnp_iface_trigonometric.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,10 @@ def reciprocal(
14521452
Keyword argument `kwargs` is currently unsupported.
14531453
Otherwise the function will be executed sequentially on CPU.
14541454
1455+
See Also
1456+
--------
1457+
:obj:`dpnp.rsqrt` : Return the reciprocal square-root of an array, element-wise.
1458+
14551459
Examples
14561460
--------
14571461
>>> import dpnp as np

tests/test_umath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_umaths(test_cases):
8585
args = get_args(args_str, sh, xp=numpy)
8686
iargs = get_args(args_str, sh, xp=dpnp)
8787

88-
if umath == "reciprocal" and iargs[0].dtype in [dpnp.int32, dpnp.int64]:
88+
if umath == "reciprocal" and args[0].dtype in [numpy.int32, numpy.int64]:
8989
pytest.skip("For integer input array, numpy.reciprocal returns zero.")
9090

9191
# original

tests/third_party/cupy/math_tests/test_arithmetic.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def test_raises_with_numpy_input(self):
8383
testing.shaped_arange((2, 3), numpy, dtype=d)
8484
for d in all_types
8585
]
86-
+ [0, 0.0j, 0j, 2, 2.0, 2j, True, False]
8786
),
8887
"name": ["conj", "conjugate", "real", "imag"],
8988
}
@@ -95,7 +94,6 @@ def test_raises_with_numpy_input(self):
9594
testing.shaped_arange((2, 3), numpy, dtype=d)
9695
for d in all_types
9796
]
98-
+ [0, 0.0j, 0j, 2, 2.0, 2j, True, False]
9997
),
10098
"deg": [True, False],
10199
"name": ["angle"],
@@ -108,7 +106,6 @@ def test_raises_with_numpy_input(self):
108106
numpy.array([-3, -2, -1, 1, 2, 3], dtype=d)
109107
for d in negative_types_wo_fp16
110108
]
111-
+ [0, 0.0j, 0j, 2, 2.0, 2j, -2, -2.0, -2j, True, False]
112109
),
113110
"deg": [True, False],
114111
"name": ["angle"],
@@ -121,14 +118,12 @@ def test_raises_with_numpy_input(self):
121118
testing.shaped_arange((2, 3), numpy, dtype=d) + 1
122119
for d in all_types
123120
]
124-
+ [2, 2.0]
125121
),
126122
"name": ["reciprocal"],
127123
}
128124
)
129125
)
130126
)
131-
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
132127
class TestArithmeticUnary:
133128
@testing.numpy_cupy_allclose(atol=1e-5, type_check=has_support_aspect64())
134129
def test_unary(self, xp):

0 commit comments

Comments
 (0)