On 9/8/10 1:46 PM, Simon King wrote:
Hi Kees!

On 8 Sep., 18:19, KvS<keesvansch...@gmail.com>  wrote:
...
I am thinking of ways to speed it up. Given that it is mainly a lot of
looping and a lot of elementary computations, I would guess
translating it to Cython could help a lot.

However I am afraid that doubles won't have enough precision to avoid
too much numerical noise in the end result of the algorithm. ...

"Translating to Cython" does not necessarily mean that you cdefine
*all* variables in your program. If you really have many tight loops
then you should cdefine the loop variable, such as:

def foo(x):    # here, x is numerical input
     # note that I do not say "def foo(double x)" or so!
     cdef int i
     for i from 0<=i<...: # instead of "for i in range(...)"
         <do some trivial computation with x>

Actually, for a while now, "for i in range(...)" is translated into fast C intelligently. In fact, I believe it's the recommended syntax now, instead of 0<=i<...

I believe that Cython 0.13 (just released, and making its way into Sage) does even more to optimize loops intelligently.


Note that you can get an annotated version of your code. In the
notebook, this is available via some link; I don't remember what you
need to do on the command line (try to search the manual).


I usually do something like:

sage -cython -a my-file.pyx

which creates the .html file in the current directory.

Thanks,

Jason

--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to