[Numpy-discussion] algorithm, optimization, or other problem?

Brian Blais bblais at bryant.edu
Thu Feb 23 09:35:11 CST 2006


Nadav Horesh wrote:
> It is slower.
> 
> I did a little study on this issue since I got into the issue of 
> algorithms that can not be easily vectorized (like this one).
> On my PC an outer loop step took initially 17.3 seconds, and some 
> optimization brought it down to ~11 seconds.  The dot product consumed 
> about 1/3 of the time. I estimate that objects creation/destruction 
> consumes most of the cpu time. It seems that this way comes nowhere near 
> cmex speed. I suspect that maybe blitz/boost may bridge the gap.
> 

yeah, I realized that pure python would be too slow, because I ran into the exact 
same problem with matlab scripting.  these time-dependent loops are really a mess 
when it comes to speed optimization.

After posting to the Pyrex list, someone pointed out that my loop variables had not 
been declared as c datatypes.  so, I had loops like:

for it from 0 <= it <= 1000:
	for i from 0 <= i <= 100:

		(stuff)

and the "it" and "i" were being treated, due to my oversight, as python variables. 
for speed, you need to have all the variables in the loop as c datatypes.  just 
putting a line in like:

cdef int it,i

increases the speed from 8 seconds per block to 0.2 seconds per block, which is 
comparable to the mex.

I learned that I have to be a bit more careful!  :)


			thanks,

				Brian Blais


-- 
-----------------

             bblais at bryant.edu
             http://web.bryant.edu/~bblais




More information about the Numpy-discussion mailing list