Skip to content

Commit 57aaa1b

Browse files
committed
Add implemntation of dpnp.spacing
1 parent 10fe798 commit 57aaa1b

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

dpnp/dpnp_iface_mathematical.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
"round",
131131
"sign",
132132
"signbit",
133+
"spacing",
133134
"subtract",
134135
"sum",
135136
"trapezoid",
@@ -3749,6 +3750,62 @@ def real_if_close(a, tol=100):
37493750
)
37503751

37513752

3753+
_SPACING_DOCSTRING = """
3754+
Return the distance between `x` and the nearest adjacent number.
3755+
3756+
For full documentation refer to :obj:`numpy.spacing`.
3757+
3758+
Parameters
3759+
----------
3760+
x : {dpnp.ndarray, usm_ndarray}
3761+
The array of values to find the spacing of, expected to have a real-valued
3762+
data type.
3763+
out : {None, dpnp.ndarray, usm_ndarray}, optional
3764+
Output array to populate.
3765+
Array must have the correct shape and the expected data type.
3766+
Default: ``None``.
3767+
order : {"C", "F", "A", "K"}, optional
3768+
Memory layout of the newly output array, if parameter `out` is ``None``.
3769+
Default: ``"K"``.
3770+
3771+
Returns
3772+
-------
3773+
out : dpnp.ndarray
3774+
The spacing of values of `x`. The data type of the returned array is
3775+
determined by the Type Promotion Rules.
3776+
3777+
Limitations
3778+
-----------
3779+
Parameters `where` and `subok` are supported with their default values.
3780+
Keyword argument `kwargs` is currently unsupported.
3781+
Otherwise ``NotImplementedError`` exception will be raised.
3782+
3783+
Notes
3784+
-----
3785+
It can be considered as a generalization of EPS:
3786+
``sdpnp.pacing(dpnp.float64(1)) == dpnp.finfo(dpnp.float64).eps``, and there
3787+
should not be any representable number between ``x + spacing(x)`` and `x` for
3788+
any finite `x`.
3789+
3790+
Spacing of +- inf and NaN is ``NaN``.
3791+
3792+
Examples
3793+
--------
3794+
>>> import dpnp as np
3795+
>>> a = np.array(1)
3796+
>>> b = np.spacing(a)
3797+
>>> b == np.finfo(b.dtype).eps
3798+
array(True)
3799+
"""
3800+
3801+
spacing = DPNPUnaryFunc(
3802+
"fabs",
3803+
ufi._spacing_result_type,
3804+
ufi._spacing,
3805+
_SPACING_DOCSTRING,
3806+
)
3807+
3808+
37523809
_SUBTRACT_DOCSTRING = """
37533810
Calculates the difference between each element `x1_i` of the input
37543811
array `x1` and the respective element `x2_i` of the input array `x2`.

0 commit comments

Comments
 (0)