@@ -2692,50 +2692,51 @@ def gradient(f, *varargs, axis=None, edge_order=1):
2692
2692
2693
2693
def interp (x , xp , fp , left = None , right = None , period = None ):
2694
2694
"""
2695
- One-dimensional linear interpolation for monotonically increasing sample points .
2695
+ One-dimensional linear interpolation.
2696
2696
2697
2697
Returns the one-dimensional piecewise linear interpolant to a function
2698
2698
with given discrete data points (`xp`, `fp`), evaluated at `x`.
2699
2699
2700
+ For full documentation refer to :obj:`numpy.interp`.
2701
+
2700
2702
Parameters
2701
2703
----------
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`.
2704
2717
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]`.
2709
2720
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]``.
2712
2722
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 ]`.
2715
2725
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]``.
2718
2727
2719
- period : None or float , optional
2728
+ period : { None, scalar, dpnp.ndarray, usm_ndarray} , optional
2720
2729
A period for the x-coordinates. This parameter allows the proper
2721
2730
interpolation of angular x-coordinates. Parameters `left` and `right`
2722
2731
are ignored if `period` is specified.
2723
2732
2733
+ Default: ``None``.
2734
+
2724
2735
Returns
2725
2736
-------
2726
- y : float or complex (corresponding to fp) or ndarray
2737
+ y : {dpnp. ndarray, usm_ndarray}
2727
2738
The interpolated values, same shape as `x`.
2728
2739
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
2739
2740
2740
2741
Warnings
2741
2742
--------
@@ -2747,6 +2748,7 @@ def interp(x, xp, fp, left=None, right=None, period=None):
2747
2748
2748
2749
A simple check for `xp` being strictly increasing is::
2749
2750
2751
+ import dpnp as np
2750
2752
np.all(np.diff(xp) > 0)
2751
2753
2752
2754
Examples
@@ -2755,40 +2757,29 @@ def interp(x, xp, fp, left=None, right=None, period=None):
2755
2757
>>> xp = np.array([1, 2, 3])
2756
2758
>>> fp = np.array([3 ,2 ,0])
2757
2759
>>> 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)
2761
2764
array([3. , 3. , 2.5 , 0.56, 0. ])
2765
+ >>> x = np.array([3.14])
2762
2766
>>> 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.])
2778
2769
2779
2770
Interpolation with periodic x-coordinates:
2780
2771
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])
2784
2775
>>> np.interp(x, xp, fp, period=360)
2785
2776
array([7.5 , 5. , 8.75, 6.25, 3. , 3.25, 3.5 , 3.75])
2786
2777
2787
2778
Complex interpolation:
2788
2779
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])
2792
2783
>>> np.interp(x, xp, fp)
2793
2784
array([0.+1.j , 1.+1.5j])
2794
2785
@@ -2802,10 +2793,7 @@ def interp(x, xp, fp, left=None, right=None, period=None):
2802
2793
raise ValueError ("fp and xp are not of the same length" )
2803
2794
if xp .size == 0 :
2804
2795
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
+
2809
2797
usm_type , exec_q = get_usm_allocations ([x , xp , fp ])
2810
2798
2811
2799
x_dtype = dpnp .common_type (x , xp )
@@ -2826,8 +2814,6 @@ def interp(x, xp, fp, left=None, right=None, period=None):
2826
2814
fp = dpnp .asarray (fp , dtype = out_dtype , order = "C" )
2827
2815
2828
2816
if period is not None :
2829
- # The handling of "period" below is modified from NumPy's
2830
-
2831
2817
if dpnp .is_supported_array_type (period ):
2832
2818
if dpu .get_execution_queue ([exec_q , period .sycl_queue ]) is None :
2833
2819
raise ValueError (
0 commit comments