[Numpy-discussion] Bypassing a.item()?
rng7 at cornell.edu
Thu Apr 20 13:49:13 CDT 2006
I'm porting some code from old scipy to new scipy, and I've run into a
rather large performance problem.
The heart of the code is integrating a system of nonlinear differential
equations using odeint. The function that dominates the time to run
calculates the right hand side, given a current state x. (len(x) ~ 50.)
Abstracted, the function looks like:
output = scipy.zeros(10, scipy.Float)
a = x
b = x
output = a/b + c*sqrt(d)...
output = b-a + 2*b...
(I copy the elements of the current state to local variables to avoid
the cost of repeatedly calling x.__getitem__, and to make the resulting
equations easier to read.)
When using numpy, a and b are now array scalars and the arithmetic is
much slower, resulting in about a factor of 10 increase in runtimes from
those using Numeric.
I've tried doing: a = x.item(), which allows the arimetic be done on
pure scalars. This is a little faster, but still results in a factor of
3 increase in runtime from old scipy. I imagine the slowdown comes from
having to call __getitem__() followed by item()
1) I haven't followed the details of the array scalar discussions. Is it
anticipated that array scalar arithmetic will eventually be as fast as
arithmetic in native python types?
2) If not, is it possible to get a "pure" scalar directly from an array
in one function call?
Thanks for any help,
Ryan Gutenkunst |
Cornell LASSP | "It is not the mountain
| we conquer but ourselves."
Clark 535 / (607)227-7914 | -- Sir Edmund Hillary
AIM: JepettoRNG |
More information about the Numpy-discussion