Skip to content

Commit 12ccad5

Browse files
committed
Add dpnp.ldexp to python interface
1 parent ee89a6e commit 12ccad5

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

dpnp/dpnp_iface_mathematical.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"heaviside",
108108
"imag",
109109
"lcm",
110+
"ldexp",
110111
"maximum",
111112
"minimum",
112113
"mod",
@@ -2029,6 +2030,12 @@ def ediff1d(ary, to_end=None, to_begin=None):
20292030
out : dpnp.ndarray
20302031
The greatest common divisor of the absolute value of the inputs.
20312032
2033+
Limitations
2034+
-----------
2035+
Parameters `where` and `subok` are supported with their default values.
2036+
Keyword argument `kwargs` is currently unsupported.
2037+
Otherwise ``NotImplementedError`` exception will be raised.
2038+
20322039
See Also
20332040
--------
20342041
:obj:`dpnp.lcm` : The lowest common multiple.
@@ -2393,6 +2400,12 @@ def gradient(f, *varargs, axis=None, edge_order=1):
23932400
out : dpnp.ndarray
23942401
The lowest common multiple of the absolute value of the inputs.
23952402
2403+
Limitations
2404+
-----------
2405+
Parameters `where` and `subok` are supported with their default values.
2406+
Keyword argument `kwargs` is currently unsupported.
2407+
Otherwise ``NotImplementedError`` exception will be raised.
2408+
23962409
See Also
23972410
--------
23982411
:obj:`dpnp.gcd` : The greatest common divisor.
@@ -2415,6 +2428,67 @@ def gradient(f, *varargs, axis=None, edge_order=1):
24152428
)
24162429

24172430

2431+
_LDEXP_DOCSTRING = """
2432+
Returns x1 * 2**x2, element-wise.
2433+
2434+
The mantissas `x1` and twos exponents `x2` are used to construct floating point
2435+
numbers ``x1 * 2**x2``.
2436+
2437+
For full documentation refer to :obj:`numpy.ldexp`.
2438+
2439+
Parameters
2440+
----------
2441+
x1 : {dpnp.ndarray, usm_ndarray, scalar}
2442+
Array of multipliers.
2443+
Both inputs `x1` and `x2` can not be scalars at the same time.
2444+
x2 : {dpnp.ndarray, usm_ndarray, scalar}
2445+
Array of twos exponents.
2446+
Both inputs `x1` and `x2` can not be scalars at the same time.
2447+
out : {None, dpnp.ndarray, usm_ndarray}, optional
2448+
Output array to populate. Array must have the correct shape and
2449+
the expected data type.
2450+
Default: ``None``.
2451+
order : {"C", "F", "A", "K"}, optional
2452+
Memory layout of the newly output array, if parameter `out` is ``None``.
2453+
Default: ``"K"``.
2454+
2455+
Returns
2456+
-------
2457+
out : dpnp.ndarray
2458+
The result of ``x1 * 2**x2``.
2459+
2460+
Limitations
2461+
-----------
2462+
Parameters `where` and `subok` are supported with their default values.
2463+
Keyword argument `kwargs` is currently unsupported.
2464+
Otherwise ``NotImplementedError`` exception will be raised.
2465+
2466+
See Also
2467+
--------
2468+
:obj:`dpnp.frexp` : Return (y1, y2) from ``x = y1 * 2**y2``, inverse to `ldexp`.
2469+
2470+
Notes
2471+
-----
2472+
Complex dtypes are not supported, they will raise a TypeError.
2473+
2474+
:obj:`dpnp.ldexp` is useful as the inverse of :obj:`dpnp.frexp`, if used by
2475+
itself it is more clear to simply use the expression ``x1 * 2**x2``.
2476+
2477+
Examples
2478+
--------
2479+
>>> import dpnp as np
2480+
>>> np.ldexp(5, np.arange(4))
2481+
array([ 5., 10., 20., 40.])
2482+
"""
2483+
2484+
ldexp = DPNPBinaryFunc(
2485+
"_ldexp",
2486+
ufi._ldexp_result_type,
2487+
ufi._ldexp,
2488+
_LDEXP_DOCSTRING,
2489+
)
2490+
2491+
24182492
_MAXIMUM_DOCSTRING = """
24192493
Compares two input arrays `x1` and `x2` and returns a new array containing the
24202494
element-wise maxima.

0 commit comments

Comments
 (0)