[Numpy-discussion] Optimizing recursive loop - updated example

Robert Elsner mlist at re-factory.de
Sun Jul 24 19:10:14 EDT 2011


Boiled it down a bit more to only include code that actually takes time.
First time around I found the other variant more instructive because it
shows the discrepancy between the DCT and the loop but might be
confusing. Thus here the bare minimum that correctly calculates the
coefficients of the first derivative from the coefficients of the
Chebyshev polynomials.

Cheers
Robert

On 25.07.2011 00:43, Robert Elsner wrote:
> 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
> 
> 
> 
> 
> 
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

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


More information about the NumPy-Discussion mailing list