Pyrex - Numeric demo doesn't build in 0.7.2

Fernando Perez fperez528 at yahoo.com
Wed May 14 13:34:10 EDT 2003


Duncan Booth wrote:

> Fernando Perez <fperez528 at yahoo.com> wrote in
> news:b9si2b$e9r$1 at peabody.colorado.edu:
> 
>>     for k from 0 <= k < N:
>>         for l from  0 <= l < N:
>>             mat[k,l] = sqrt_N_inv * \
>>                        exp(I*(alpha*(k*k-k*l+l*l) + kap_al*sin(alpha*l)))
>>     return(mat)
> 
> Whether you do this in Python or Pyrex, 'kap_al*sin(alpha*l)' doesn't
> depend on k, so you could precompute a list of N values and only have N
> calls to sin instead of N^2.
> k*k could also be move to the outer loop although the improvement may be
> negligible.
> 

Good point, thanks.  However, in this case (it's a toy example, not production
code), I'm interested in the relative timings of various approaches more than
in absolute speed, so as long as I keep the algorithm structure the same in all
my versions, it doesn't matter too much.   But you are, of course, perfectly
correct.

I'd still like to know what I'm doing wrong with the pyrex code in order to get
such a negligible improvement over python.  I looked at the generated C code,
but I quickly got a headache :)

Cheers,

f.




More information about the Python-list mailing list