[Tutor] numpy speed problems
Dave Kuhlman
dkuhlman at rexx.com
Fri Jun 9 23:33:18 CEST 2006
On Fri, Jun 09, 2006 at 11:57:32AM -0700, Bob Gailer wrote:
> Jeff Peery wrote:
> > hello, I am having some trouble with the speed of numpy. I'm crunching
> > some numbers (see the attached script) and in total I have 1,000,000
> > grid points over which I am integrating. I'm doing a bunch of adding,
> > mulitply, divide, powers, etc, but in total there are 1,000,000 points
> > to do these operations over and it really shouldn't take this long...
> > as far as I know. my last simulation took about 8+ hours.
> >
> > What might I be doing wrong in my code to cause this to be so slow?
> > big thanks!!
> I don't have time to analyze all your code but I'll point out that it is
> repeating some calculations many times. Example:
>
> x_coord[ii])**2.0
> y_coord[jj])**2.0
>
>
> are calculated every time GetPressure is called. I suggest you calculate
> these one time outside any loops and pass the result into GetPressure.
>
> Inside GetPressure:
>
> 1j*w_mn*rho
> exp(1j*k_mn*r)*dx*dy/(2.0*pi*r
>
>
> are repeatedly calculated inside the for loop. Move them out of the loop.
>
> Then look for other "loop invariants".
>
> sin(n[mode_n]*pi*(L/2.0+x_coord[i]))*sin(m[mode_m]*pi*(W/2.0+y_coord[j]))
>
> is another place to look.
>
Also, if you are serious about SciPy, NumPy, etc, be sure to visit
http://scipy.org/, *and* check into the mailing lists there.
That's not just for your benefit; if there are problems with
SciPy, the people at that list will want to know about them.
[snip]
Dave
--
Dave Kuhlman
http://www.rexx.com/~dkuhlman
More information about the Tutor
mailing list