Skip to content

Commit 06c4aec

Browse files
committed
Add python implementation
1 parent cdce27a commit 06c4aec

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

dpnp/dpnp_iface_mathematical.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
DPNPRound,
7474
DPNPSinc,
7575
DPNPUnaryFunc,
76+
DPNPUnaryTwoOutputsFunc,
7677
acceptance_fn_gcd_lcm,
7778
acceptance_fn_negative,
7879
acceptance_fn_positive,
@@ -112,6 +113,7 @@
112113
"fmax",
113114
"fmin",
114115
"fmod",
116+
"frexp",
115117
"gcd",
116118
"gradient",
117119
"heaviside",
@@ -2342,6 +2344,77 @@ def ediff1d(ary, to_end=None, to_begin=None):
23422344
mkl_impl_fn="_fmod",
23432345
)
23442346

2347+
2348+
_FREXP_DOCSTRING = """
2349+
Decompose each element :math:`x_i` of the input array `x` into the mantissa and
2350+
the twos exponent.
2351+
2352+
For full documentation refer to :obj:`numpy.frexp`.
2353+
2354+
Parameters
2355+
----------
2356+
x : {dpnp.ndarray, usm_ndarray}
2357+
Array of numbers to be decomposed, expected to have a real-valued
2358+
floating-point data type.
2359+
out1 : {None, dpnp.ndarray, usm_ndarray}, optional
2360+
Output array for the mantissa to populate. Array must have the same shape
2361+
as `x` and the expected data type.
2362+
2363+
Default: ``None``.
2364+
out2 : {None, dpnp.ndarray, usm_ndarray}, optional
2365+
Output array for the exponent to populate. Array must have the same shape
2366+
as `x` and the expected data type.
2367+
2368+
Default: ``None``.
2369+
order : {None, "C", "F", "A", "K"}, optional
2370+
Memory layout of the newly output array, if parameter `out` is ``None``.
2371+
2372+
Default: ``"K"``.
2373+
2374+
Returns
2375+
-------
2376+
mantissa : dpnp.ndarray
2377+
Floating values between -1 and 1.
2378+
exponent : dpnp.ndarray
2379+
Integer exponents of 2.
2380+
2381+
Limitations
2382+
-----------
2383+
Parameters `where` and `subok` are supported with their default values.
2384+
Keyword argument `kwargs` is currently unsupported.
2385+
Otherwise ``NotImplementedError`` exception will be raised.
2386+
2387+
See Also
2388+
--------
2389+
:obj:`dpnp.ldexp` : Compute :math:`y = x1 * 2^{x2}`, inverse to
2390+
:obj:`dpnp.frexp`.
2391+
2392+
Notes
2393+
-----
2394+
Complex dtypes are not supported, they will raise a ``TypeError``.
2395+
2396+
Examples
2397+
--------
2398+
>>> import dpnp as np
2399+
>>> x = np.arange(9)
2400+
>>> y1, y2 = np.frexp(x)
2401+
>>> y1
2402+
array([0. , 0.5 , 0.5 , 0.75 , 0.5 , 0.625, 0.75 , 0.875, 0.5 ])
2403+
>>> y2
2404+
array([0, 1, 2, 2, 3, 3, 3, 3, 4], dtype=int32)
2405+
>>> y1 * 2**y2
2406+
array([0., 1., 2., 3., 4., 5., 6., 7., 8.])
2407+
2408+
"""
2409+
2410+
frexp = DPNPUnaryTwoOutputsFunc(
2411+
"_frexp",
2412+
ufi._frexp_result_type,
2413+
ufi._frexp,
2414+
_FREXP_DOCSTRING,
2415+
)
2416+
2417+
23452418
_GCD_DOCSTRING = r"""
23462419
Returns the greatest common divisor of :math:`\abs{x1}` and :math:`\abs{x2}`.
23472420

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ max-returns = 8
154154

155155
[tool.pylint.format]
156156
max-line-length = 80
157-
max-module-lines = 5000
157+
max-module-lines = 8000
158158

159159
[tool.pylint.imports]
160160
allow-wildcard-with-all = true

0 commit comments

Comments
 (0)