Pyrex - Numeric demo doesn't build in 0.7.2

Duncan Booth duncan at NOSPAMrcp.co.uk
Wed May 14 04:21:51 EDT 2003


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.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list