|
130 | 130 | "round", |
131 | 131 | "sign", |
132 | 132 | "signbit", |
| 133 | + "spacing", |
133 | 134 | "subtract", |
134 | 135 | "sum", |
135 | 136 | "trapezoid", |
@@ -3749,6 +3750,62 @@ def real_if_close(a, tol=100): |
3749 | 3750 | ) |
3750 | 3751 |
|
3751 | 3752 |
|
| 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 | + |
3752 | 3809 | _SUBTRACT_DOCSTRING = """ |
3753 | 3810 | Calculates the difference between each element `x1_i` of the input |
3754 | 3811 | array `x1` and the respective element `x2_i` of the input array `x2`. |
|
0 commit comments