[Numpy-discussion] Quick Question about Optimization

Hoyt Koepke hoytak@gmail....
Tue May 20 14:24:26 CDT 2008


> The time has now been shaved down to ~9 seconds with this suggestion
> from the original 13-14s, with the inclusing of Eric Firing's
> suggestions.  This is without scipy.weave, which at the moment I can't
> get to work for all lines, and when I just replace one of them
> sucessfully it seems to run more slowly, I assume because it is
> converting data back and forth.

There's a nontrivial constant time cost to using scipy.weave.blitz,
but it isn't copying the data. Thus it will slow you down on smaller
arrays, but you'll notice quite a speed-up on much larger ones.  I
should have mentioned that earlier -- I assumed your arrays were
really large.

> Are there any major pitfalls to be aware of?  It sounds like if I do:
> f = a[n,:] I get a reference, but if I did something like g = a[n,:]*2
> I would get a copy.

Well, if you do f = a[n, :], you would get a view, another object that
shares the data in memory with a but is a separate object.

> If anyone has any clues on why scipy.weave is blowing
> (http://pastebin.com/m79699c04) using the code I attached, I wouldn't
> mind knowing.  Most of the times I've attempted using weave, I've been
> a little baffled about why things aren't working.  I also don't have a
> sense for whether all numpy functions should be "weavable" or if it's
> just general array operations that can be put through weave.

Sorry I didn't get back to you earlier on this -- I was a bit busy
yesterday.  It looks like weave.blitz isn't working on your second
line because you're not explicitly putting slices in some of the
dimensions,  In numpy v[0:2] works for 1,2,3,4,.... dimensions, but
for a 2d array in blitz you have to use v[0:2,:], 3d v[0:2,:,:].  It's
a bit more picky.   I think that's the problem with your second line
-- try replacing v[:] with v[0,:] and theta[1-curidx] with
theta[1-curidx, :]. (I may have missed some others.)

weave.blitz is currently limited to just array operations... it
doesn't really support the numpy functions.

Hope that helps a little....

-- Hoyt

-- 
+++++++++++++++++++++++++++++++++++
Hoyt Koepke
UBC Department of Computer Science
http://www.cs.ubc.ca/~hoytak/
hoytak@gmail.com
+++++++++++++++++++++++++++++++++++


More information about the Numpy-discussion mailing list