[Numpy-discussion] Optimizing recursive loop

Robert Elsner mlist at re-factory.de
Sun Jul 24 18:43:46 EDT 2011


Hey Everybody,

I am approximating the derivative of nonperiodic functions on [-1,1]
using Chebyshev polynomials. The implementation is straightforward and
works well but is painfully slow. The routine wastes most of its time on
a trivial operation (see comment in the code)
Unfortunately the spectral coefficients are calculated recursively and
thus I haven't found a way to speed up the code. I am aware of list
comprehensions, the speed advantage of calling native numpy functions
etc. But no luck yet finding an alternate formulation that speeds up the
calculation. I attached a stripped down variant of the code. I am very
grateful for tips or directions where to look for a solution (well I
know writing a small C extension might be the way to go but Id love to
have speedy Python)

Note: The DCT takes almost no time compared to the statement in the loop.

Cheers
Robert


-------------- next part --------------
A non-text attachment was scrubbed...
Name: optimization.py
Type: text/x-python
Size: 1173 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110725/0736e4dd/attachment.py>


More information about the NumPy-Discussion mailing list