Skip to content

Commit b04e830

Browse files
committed
Add modf implementation as an instance of DPNPUnaryTwoOutputsFunc class
1 parent 92d2332 commit b04e830

File tree

1 file changed

+68
-32
lines changed

1 file changed

+68
-32
lines changed

dpnp/dpnp_iface_mathematical.py

Lines changed: 68 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
import dpnp
6363
import dpnp.backend.extensions.ufunc._ufunc_impl as ufi
6464

65-
from .dpnp_algo import dpnp_modf
6665
from .dpnp_algo.dpnp_elementwise_common import (
6766
DPNPI0,
6867
DPNPAngle,
@@ -82,7 +81,7 @@
8281
resolve_weak_types_2nd_arg_int,
8382
)
8483
from .dpnp_array import dpnp_array
85-
from .dpnp_utils import call_origin, get_usm_allocations
84+
from .dpnp_utils import get_usm_allocations
8685
from .dpnp_utils.dpnp_utils_linearalgebra import dpnp_cross
8786
from .dpnp_utils.dpnp_utils_reduction import dpnp_wrap_reduction_call
8887

@@ -2366,7 +2365,6 @@ def ediff1d(ary, to_end=None, to_begin=None):
23662365
as `x` and the expected data type.
23672366
23682367
Default: ``None``.
2369-
23702368
out : tuple of None, dpnp.ndarray, or usm_ndarray, optional
23712369
A location into which the result is stored. If provided, it must be a tuple
23722370
and have length equal to the number of outputs. Each provided array must
@@ -3352,42 +3350,80 @@ def interp(x, xp, fp, left=None, right=None, period=None):
33523350
)
33533351

33543352

3355-
def modf(x1, **kwargs):
3356-
"""
3357-
Return the fractional and integral parts of an array, element-wise.
3353+
_MODF_DOCSTRING = """
3354+
Decompose each element :math:`x_i` of the input array `x` into the fractional
3355+
and the integral parts.
33583356
3359-
For full documentation refer to :obj:`numpy.modf`.
3357+
The fractional and integral parts are negative if the given :math:`x_i` is
3358+
negative.
33603359
3361-
Limitations
3362-
-----------
3363-
Parameter `x` is supported as :obj:`dpnp.ndarray`.
3364-
Keyword argument `kwargs` is currently unsupported.
3365-
Otherwise the function will be executed sequentially on CPU.
3366-
Input array data types are limited by supported DPNP :ref:`Data types`.
3360+
Parameters
3361+
----------
3362+
x : {dpnp.ndarray, usm_ndarray}
3363+
Array of numbers to be decomposed, expected to have a real-valued
3364+
floating-point data type.
3365+
out1 : {None, dpnp.ndarray, usm_ndarray}, optional
3366+
Output array for the fractional parts to populate. Array must have the same
3367+
shape as `x` and the expected data type.
33673368
3368-
Examples
3369-
--------
3370-
>>> import dpnp as np
3371-
>>> a = np.array([1, 2])
3372-
>>> result = np.modf(a)
3373-
>>> [[x for x in y] for y in result ]
3374-
[[1.0, 2.0], [0.0, 0.0]]
3369+
Default: ``None``.
3370+
out2 : {None, dpnp.ndarray, usm_ndarray}, optional
3371+
Output array for the integral parts to populate. Array must have the same
3372+
shape as `x` and the expected data type.
33753373
3376-
"""
3374+
Default: ``None``.
3375+
out : tuple of None, dpnp.ndarray, or usm_ndarray, optional
3376+
A location into which the result is stored. If provided, it must be a tuple
3377+
and have length equal to the number of outputs. Each provided array must
3378+
have the same shape as `x` and the expected data type.
3379+
It is prohibited to pass output arrays through `out` keyword when either
3380+
`out1` or `out2` is passed.
33773381
3378-
x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False)
3379-
if x1_desc:
3380-
if dpnp.is_cuda_backend(x1_desc.get_array()): # pragma: no cover
3381-
raise NotImplementedError(
3382-
"Running on CUDA is currently not supported"
3383-
)
3382+
Default: ``(None, None)``.
3383+
order : {None, "C", "F", "A", "K"}, optional
3384+
Memory layout of the newly output array, if parameter `out` is ``None``.
33843385
3385-
if kwargs:
3386-
pass
3387-
else:
3388-
return dpnp_modf(x1_desc)
3386+
Default: ``"K"``.
3387+
3388+
Returns
3389+
-------
3390+
y1 : dpnp.ndarray
3391+
Fractional part of `x`.
3392+
y2 : dpnp.ndarray
3393+
Integral part of `x`.
3394+
3395+
Limitations
3396+
-----------
3397+
Parameters `where`, `dtype` and `subok` are supported with their default values.
3398+
Keyword argument `kwargs` is currently unsupported.
3399+
Otherwise ``NotImplementedError`` exception will be raised.
33893400
3390-
return call_origin(numpy.modf, x1, **kwargs)
3401+
See Also
3402+
--------
3403+
:obj:`dpnp.divmod` : ``divmod(x, 1)`` is an equivalent to ``modf(x)`` with the
3404+
return values switched, except it always has a positive remainder.
3405+
3406+
Notes
3407+
-----
3408+
For integer input the return values are floats.
3409+
3410+
Examples
3411+
--------
3412+
>>> import dpnp as np
3413+
>>> x = np.array([0, 3.5])
3414+
>>> np.modf(x)
3415+
(array([0. , 0.5]), array([0., 3.]))
3416+
>>> np.modf(np.array(-0.5))
3417+
(array(-0.5), array(-0.))
3418+
3419+
"""
3420+
3421+
modf = DPNPUnaryTwoOutputsFunc(
3422+
"_modf",
3423+
ufi._modf_result_type,
3424+
ufi._modf,
3425+
_MODF_DOCSTRING,
3426+
)
33913427

33923428

33933429
_MULTIPLY_DOCSTRING = """

0 commit comments

Comments
 (0)