Skip to content

Commit a65a1dd

Browse files
Update docstrings for def interp()
1 parent 5cda3d2 commit a65a1dd

File tree

1 file changed

+41
-55
lines changed

1 file changed

+41
-55
lines changed

dpnp/dpnp_iface_mathematical.py

Lines changed: 41 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,50 +2692,51 @@ def gradient(f, *varargs, axis=None, edge_order=1):
26922692

26932693
def interp(x, xp, fp, left=None, right=None, period=None):
26942694
"""
2695-
One-dimensional linear interpolation for monotonically increasing sample points.
2695+
One-dimensional linear interpolation.
26962696
26972697
Returns the one-dimensional piecewise linear interpolant to a function
26982698
with given discrete data points (`xp`, `fp`), evaluated at `x`.
26992699
2700+
For full documentation refer to :obj:`numpy.interp`.
2701+
27002702
Parameters
27012703
----------
2702-
x : array_like
2703-
The x-coordinates at which to evaluate the interpolated values.
2704+
x : {dpnp.ndarray, usm_ndarray}
2705+
Input 1-D array. The x-coordinates at which to evaluate
2706+
the interpolated values.
2707+
2708+
xp : {dpnp.ndarray, usm_ndarray}
2709+
Input 1-D array. The x-coordinates of the data points,
2710+
must be increasing if argument `period` is not specified.
2711+
Otherwise, `xp` is internally sorted after normalizing
2712+
the periodic boundaries with ``xp = xp % period``.
2713+
2714+
fp : {dpnp.ndarray, usm_ndarray}
2715+
Input 1-D array. The y-coordinates of the data points,
2716+
same length as `xp`.
27042717
2705-
xp : 1-D sequence of floats
2706-
The x-coordinates of the data points, must be increasing if argument
2707-
`period` is not specified. Otherwise, `xp` is internally sorted after
2708-
normalizing the periodic boundaries with ``xp = xp % period``.
2718+
left : {None, scalar, dpnp.ndarray, usm_ndarray}, optional
2719+
Value to return for `x < xp[0]`.
27092720
2710-
fp : 1-D sequence of float or complex
2711-
The y-coordinates of the data points, same length as `xp`.
2721+
Default: ``fp[0]``.
27122722
2713-
left : optional float or complex corresponding to fp
2714-
Value to return for `x < xp[0]`, default is `fp[0]`.
2723+
right : {None, scalar, dpnp.ndarray, usm_ndarray}, optional
2724+
Value to return for `x > xp[-1]`.
27152725
2716-
right : optional float or complex corresponding to fp
2717-
Value to return for `x > xp[-1]`, default is `fp[-1]`.
2726+
Default: ``fp[-1]``.
27182727
2719-
period : None or float, optional
2728+
period : {None, scalar, dpnp.ndarray, usm_ndarray}, optional
27202729
A period for the x-coordinates. This parameter allows the proper
27212730
interpolation of angular x-coordinates. Parameters `left` and `right`
27222731
are ignored if `period` is specified.
27232732
2733+
Default: ``None``.
2734+
27242735
Returns
27252736
-------
2726-
y : float or complex (corresponding to fp) or ndarray
2737+
y : {dpnp.ndarray, usm_ndarray}
27272738
The interpolated values, same shape as `x`.
27282739
2729-
Raises
2730-
------
2731-
ValueError
2732-
If `xp` and `fp` have different length
2733-
If `xp` or `fp` are not 1-D sequences
2734-
If `period == 0`
2735-
2736-
See Also
2737-
--------
2738-
scipy.interpolate
27392740
27402741
Warnings
27412742
--------
@@ -2747,6 +2748,7 @@ def interp(x, xp, fp, left=None, right=None, period=None):
27472748
27482749
A simple check for `xp` being strictly increasing is::
27492750
2751+
import dpnp as np
27502752
np.all(np.diff(xp) > 0)
27512753
27522754
Examples
@@ -2755,40 +2757,29 @@ def interp(x, xp, fp, left=None, right=None, period=None):
27552757
>>> xp = np.array([1, 2, 3])
27562758
>>> fp = np.array([3 ,2 ,0])
27572759
>>> x = np.array([2.5])
2758-
>>> np.interp(2.5, xp, fp)
2759-
1.0
2760-
>>> np.interp([0, 1, 1.5, 2.72, 3.14], xp, fp)
2760+
>>> np.interp(x, xp, fp)
2761+
array([1.])
2762+
>>> x = np.array([0, 1, 1.5, 2.72, 3.14])
2763+
>>> np.interp(x, xp, fp)
27612764
array([3. , 3. , 2.5 , 0.56, 0. ])
2765+
>>> x = np.array([3.14])
27622766
>>> UNDEF = -99.0
2763-
>>> np.interp(3.14, xp, fp, right=UNDEF)
2764-
-99.0
2765-
2766-
Plot an interpolant to the sine function:
2767-
2768-
>>> x = np.linspace(0, 2*np.pi, 10)
2769-
>>> y = np.sin(x)
2770-
>>> xvals = np.linspace(0, 2*np.pi, 50)
2771-
>>> yinterp = np.interp(xvals, x, y)
2772-
>>> import matplotlib.pyplot as plt
2773-
>>> plt.plot(x, y, 'o')
2774-
[<matplotlib.lines.Line2D object at 0x...>]
2775-
>>> plt.plot(xvals, yinterp, '-x')
2776-
[<matplotlib.lines.Line2D object at 0x...>]
2777-
>>> plt.show()
2767+
>>> np.interp(x, xp, fp, right=UNDEF)
2768+
array([-99.])
27782769
27792770
Interpolation with periodic x-coordinates:
27802771
2781-
>>> x = [-180, -170, -185, 185, -10, -5, 0, 365]
2782-
>>> xp = [190, -190, 350, -350]
2783-
>>> fp = [5, 10, 3, 4]
2772+
>>> x = np.array([-180, -170, -185, 185, -10, -5, 0, 365])
2773+
>>> xp = np.array([190, -190, 350, -350])
2774+
>>> fp = np.array([5, 10, 3, 4])
27842775
>>> np.interp(x, xp, fp, period=360)
27852776
array([7.5 , 5. , 8.75, 6.25, 3. , 3.25, 3.5 , 3.75])
27862777
27872778
Complex interpolation:
27882779
2789-
>>> x = [1.5, 4.0]
2790-
>>> xp = [2,3,5]
2791-
>>> fp = [1.0j, 0, 2+3j]
2780+
>>> x = np.array([1.5, 4.0])
2781+
>>> xp = np.array([2,3,5])
2782+
>>> fp = np.array([1.0j, 0, 2+3j])
27922783
>>> np.interp(x, xp, fp)
27932784
array([0.+1.j , 1.+1.5j])
27942785
@@ -2802,10 +2793,7 @@ def interp(x, xp, fp, left=None, right=None, period=None):
28022793
raise ValueError("fp and xp are not of the same length")
28032794
if xp.size == 0:
28042795
raise ValueError("array of sample points is empty")
2805-
if not x.flags.c_contiguous:
2806-
raise NotImplementedError(
2807-
"Non-C-contiguous x is currently not supported"
2808-
)
2796+
28092797
usm_type, exec_q = get_usm_allocations([x, xp, fp])
28102798

28112799
x_dtype = dpnp.common_type(x, xp)
@@ -2826,8 +2814,6 @@ def interp(x, xp, fp, left=None, right=None, period=None):
28262814
fp = dpnp.asarray(fp, dtype=out_dtype, order="C")
28272815

28282816
if period is not None:
2829-
# The handling of "period" below is modified from NumPy's
2830-
28312817
if dpnp.is_supported_array_type(period):
28322818
if dpu.get_execution_queue([exec_q, period.sycl_queue]) is None:
28332819
raise ValueError(

0 commit comments

Comments
 (0)