[SciPy-User] scipy interpolate.interp1d spline slowness
Jonathan Stickel
jjstickel@gmail....
Thu Dec 13 14:50:24 CST 2012
On 12/13/12 10:26 , scipy-user-request@scipy.org wrote:
> Date: Wed, 12 Dec 2012 17:25:00 -0500
> From:josef
> Subject: Re: [SciPy-User] scipy interpolate.interp1d spline slowness
> To: SciPy Users List<scipy-user@scipy.org>
>
> On Wed, Dec 12, 2012 at 5:08 PM, Wolfgang Kerzendorf
> <wkerzendorf@gmail.com> wrote:
>> >Hello Scipyers,
>> >
>> >I've just stumbled across a problem with interpolate.interp1d:
>> >-------------
>> >import numpy as np
>> >from scipy import interpolate
>> >x = arange(1000)
>> >y = y = np.random.random_integers(0, 900, 1000)
>> >
>> >%timeit interp = interpolate.interp1d(x, y, kind='cubic')
>> >1 loops, best of 3: 3.63 s per loop
>> >#the call for the interpolation is really quick afterwards (a couple ms)
>> >
>> >tck = interpolate.splrep(x, y, s=0)
>> >%timeit interpolate.splev(x_new, tck, der=0)
>> >100 loops, best of 3: 5.51 ms per loop
> It looks to me, you are timing two different things here, with
> interp1d you time the spline creation with splev you time the
> evaluation.
>
> for "cubic", interp1d uses _fitpack._bspleval so I wouldn't expect
> much difference in timing.
> But I didn't check whether there is a difference in what the wrappers are doing
>
I think this is the appropriate comparison:
In [1]: import numpy as np
In [2]: from scipy import interpolate as ipt
In [3]: x = np.arange(1000)
In [4]: y = 100*np.random.rand(1000)
In [5]: xp = x[:-1] + 0.5
In [6]: %timeit yp1 = ipt.interp1d(x,y,kind=3)(xp)
1 loops, best of 3: 5.08 s per loop
In [7]: %timeit yp2 = ipt.splev( xp, ipt.splrep(x,y,k=3) )
1000 loops, best of 3: 326 us per loop
I also don't claim to know the details of the two implementations, but I
now use splrep/splev for any cubic spline interpolation of more than a
few points.
Jonathan
More information about the SciPy-User
mailing list