[SciPy-User] scipy interpolate.interp1d spline slowness

josef.pktd@gmai... josef.pktd@gmai...
Wed Dec 12 18:10:41 CST 2012


Can you please follow our convention and post at bottom or inline.

On Wed, Dec 12, 2012 at 6:26 PM, Wolfgang Kerzendorf
<wkerzendorf@gmail.com> wrote:
> Sorry again, i should include that interp came from: interp = interpolate.interp1d(x, y, kind='cubic')
> Cheers
>    W
> On 2012-12-12, at 6:25 PM, Wolfgang Kerzendorf <wkerzendorf@gmail.com> wrote:
>
>> Hi Josef,
>>
>> Your'e absolutely right - I just omitted the other timings as they seemed small compared to the interp1d:
>>
>> %timeit interp(x_new)
>> 100 loops, best of 3: 3.89 ms per loop

that looks faster than what you had before :

>> %timeit interpolate.splev(x_new, tck, der=0)
>> 100 loops, best of 3: 5.51 ms per loop

I don't understand the setup code for interp1d cubic, _find_smoothest
for interpolation ?
but that looks slow in your timing.

>>
>> %timeit tck = interpolate.splrep(x, y, s=0)
>> 1000 loops, best of 3: 204 us per loop
>>
>> It would be great if you look into this.

Sorry, not me, I don't have time for this.

I went recently roughly through the source for interp1d "linear", and
so the other parts just on the side.

I have never seen this extra spline code in interpolate.py
there are a lot of potentially nice options
'natural', 'second','clamped', 'endslope', 'first', 'not-a-knot',
'runout', 'parabolic'
and a lot of NotImplementedError and one more wrapper around _fitpack

It looks like a major undertaking to just find one's way around the
splines and fitpack wrapper codes.

I stick to UnivariateSplines for "cubic".

Josef

>>
>> Thanks
>>   Wolfgang
>> On 2012-12-12, at 5:25 PM, josef.pktd@gmail.com wrote:
>>
>>> 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
>>>
>>> Josef
>>>
>>>
>>>
>>>>
>>>> ------
>>>> I do understand that these are different spline interpolations (but that's as far as my knowledge goes). I was just annoyed at the person saying: Ah, you see python is slow - which it is not as shown by the second scipy command.
>>>>
>>>> Would it be possible to switch the spline interpolator used in interpolate.interp1d to the B-Splines, or to give an option to switch between different spline interpolators (maybe with a warning: slow).
>>>>
>>>> Ah - a last question: Why don't you  use the issues tab on the github page?
>>>>
>>>> Thanks in advance,
>>>>  Wolfgang
>>>> _______________________________________________
>>>> SciPy-User mailing list
>>>> SciPy-User@scipy.org
>>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>> _______________________________________________
>>> SciPy-User mailing list
>>> SciPy-User@scipy.org
>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user


More information about the SciPy-User mailing list