Skip to content

Commit 8ecd809

Browse files
committed
Add modf implementation as an instance of DPNPUnaryTwoOutputsFunc class
1 parent ad5900e commit 8ecd809

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
@@ -61,7 +61,6 @@
6161
import dpnp
6262
import dpnp.backend.extensions.ufunc._ufunc_impl as ufi
6363

64-
from .dpnp_algo import dpnp_modf
6564
from .dpnp_algo.dpnp_elementwise_common import (
6665
DPNPI0,
6766
DPNPAngle,
@@ -81,7 +80,7 @@
8180
resolve_weak_types_2nd_arg_int,
8281
)
8382
from .dpnp_array import dpnp_array
84-
from .dpnp_utils import call_origin, get_usm_allocations
83+
from .dpnp_utils import get_usm_allocations
8584
from .dpnp_utils.dpnp_utils_linearalgebra import dpnp_cross
8685
from .dpnp_utils.dpnp_utils_reduction import dpnp_wrap_reduction_call
8786

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

33533351

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

33913427

33923428
_MULTIPLY_DOCSTRING = """

0 commit comments

Comments
 (0)