Dear Julien,
I did not get the problem immediately but here it is:
- with numx.arange(0,1) you allocate an array of integers. The
interpolation code uses internally doubles, so you have to enforce that
they will be made float arrays (the native C double type, typically
numx.float) so use .astype(numpy.float_) or multiply them with 0.1
- you can check if pygsl had to transform the basis type of the vector
with pygsl.init.vector_transform_counter(). Call it before and after
the function in question and you will see.
- if you share code, please be aware that numpy, numarray or Numeric
could be the array package. These packages interchange quite nicely, but
that could also cost time, even if not on that scale as your example does.
- there are two modules: spline and interpolation. They both provide the
same functionality but spline makes internal copies of the vectors x and
y. This can save quite some cycles here. Given that you want to
interpolate in large arrays, it can be that this is not an option.
- spline provides the method eval_vector. If you have an vector you need
interpolation values for, this will make a huge difference. If you
need the same function for the interpolation drop me a line and I will
add it (or for eval_deriv, or eval_integ ....)
Sincerely yours
Pierre
--
+---------------------------------------------------------------------+
Pierre Schnizer <[EMAIL PROTECTED]>
Telephon : +49 6159 71 1557
Fax : +49 6159 71 2043
Address :
Pierre Schnizer / F - MT
Gesellschaft fuer Schwerionenforschung
Planckstrasse 1
64291 Darmstadt
Germany
WWW: http://www.gsi.de
Gesellschaft mit beschr<E4>nkter Haftung
Sitz der Gesellschaft: Darmstadt
Handelsregister: Amtsgericht Darmstadt, HRB 1528
Gesch<E4>ftsf<FC>hrer: Professor Dr. Horst St<F6>cker
Vorsitzende des Aufsichtsrates: Dr. Beatrix Vierkorn-Rudolph
Stellvertreter: Ministerialdirigent Dr. Rolf Bernhardt
+---------------------------------------------------------------------+
#!/usr/bin/env python
#------------------------------------------------------------------------------
# Original Author: Julien
# Author: Piere Schnizer <[EMAIL PROTECTED]>
# Date : August, 2008
#
# Illustrates how much time is required if the interpolation matrices
# have to be converted all the time.
#------------------------------------------------------------------------------
import time
import pygsl
# pygsl can be compiled
numx = pygsl._numobj
# The intepolation module. This tries to the arrays directly
import pygsl.interpolation as intp
# This module makes an internal copy and stores the data internally
#import pygsl.spline as intp
#------------------------------------------------------------------------------
time_ = time.time
t_initial = time_()
a = numx.arange(0,10000000)
b = numx.arange(10000000,20000000)
# Comment the following lines and see the difference in speed.
a = a.astype(numx.float_)
b = b.astype(numx.float_)
c = intp.linear( len(a) )
c.init(a, b)
# Pygsl tries to count if it has to make a type transformation internally
save_cnt = pygsl.init.vector_transform_counter()
t_start = time_()
print "->"
for i in range(0,50):
c.eval(50000)
print ".",
print " done"
t_final = time_()
end_cnt = pygsl.init.vector_transform_counter()
print "Total time =", t_final-t_initial
print "Time for evaluation =", t_final-t_start
print "Required %d vector type transformations" %(end_cnt - save_cnt,)
# The spline module also has a eval_vector function, That gives an obvious
# speed up..
#vec = numx.ones(50) * 50000
#t_start = time_()
#c.eval_vector(vec)
#t_final = time_()
#print "passed_time=", t_final-t_start
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
pygsl-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pygsl-discuss