[SciPy-user] interpolation speed problem

Tribulations Parallèles paratribulations at free.fr
Sun Aug 24 16:22:19 EDT 2008


Hi everybody,

I try to perform quick interpolation with Python.
So far I have compared two solutions. First, the scipy solution:

#####
import numpy as N
from scipy import interpolate
from time import time

number = 1000000

a=N.arange( 0, number, 0.1)
b=N.arange( number, 2*number, 0.1)
f = interpolate.interp1d( a, b )
t_initial = time()
for i in range(0,50):
           print "foo=%.5f" % f( 49999.5 ),
t_final = time()
print "\nTotal time =", t_final-t_initial
#####

Now, the pygsl version (the two lines "astype(numx.float_)" are very important 
for the speed, these lines have been given by Pierre from the pygsl mailing 
list):

#####
import pygsl.interpolation
from time import time
import numpy

numx = pygsl._numobj

number = 1000000

a=numpy.arange( 0, number )
b=numpy.arange( number, 2*number )
a = a.astype(numx.float_)
b = b.astype(numx.float_)

c = pygsl.interpolation.linear( len(a) )
pygsl.interpolation.linear.init( c
      , a
      , b)

t_initial = time()
for i in range(0,50):
   print "foo=%.5f" % c.eval(49999.5),
t_final = time()

print "\nTotal time =", t_final-t_initial
####

The pygsl version takes on my machine 0.0004 s
The scipy version takes 0.005 s.

Is there some means to improve the scipy version?

Thanks

Julien



More information about the SciPy-User mailing list