[Numpy-discussion] Question about Optimization (Inline and Pyrex)
Lou Pecora
lou_boog2000@yahoo....
Tue Apr 17 13:48:00 CDT 2007
You should probably look over your code and see if you
can eliminate loops by using the built in
vectorization of NumPy. I've found this can really
speed things up. E.g. given element by element
multiplication of two n-dimensional arrays x and y
replace,
z=zeros(n)
for i in xrange(n):
z[i]=x[i]*y[i]
with,
z=x*y # NumPy will handle this in a vector fashion
Maybe you've already done that, but I thought I'd
offer it.
--- Simon Berube <sberub@gmail.com> wrote:
> I recently made the switch from Matlab to Python and
> am very
> interested in optimizing certain routines that I
> find too slow in
> python/numpy (long loops).
>
> I have looked and learned about the different
> methods used for such
> problems such as blitz, weave and pyrex but had a
> question for more
> experienced developpers.
>
> It appears that pyrex is the fastest of the bunch
> with weave very
> close behind but at the same time pyrex requires
> entirely different
> modules while weave can be inserted almost
> painlessly into existing
> code. Is the speed gain and usefulness of pyrex
> severely limited by
> the extra maintenance required y having separate
> "fast" routines from
> the rest of the code files?
>
> I am greatly interested in finding out what more
> experienced
> developers feel about these issues given that I may
> be completely off
> track and missing on a useful tool(pyrex) thinking
> weave is better
> than it actually is and I am quite frankly afraid of
> writing routines
> in one format and realizing later that it creates
> problems that I need
> to rewrite.
>
> I have tried searching for previous similar posts
> but could not find
> any. My apologies if this is a repeat or a severly
> dumb question.
>
> Regards,
>
> Simon Berube
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
>
http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
-- Lou Pecora, my views are my own.
---------------
"I knew I was going to take the wrong train, so I left early."
--Yogi Berra
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Numpy-discussion
mailing list