Hi Kees!

On 8 Sep., 18:19, KvS <[email protected]> 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>

So, the type of x is not declared, only the type of the loop variable
is.
This may already provide some speedup, and you would still be able to
use high precision numerical data, rather than double.

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). In that
annotated version (that is a html file that you can look at in your
browser), you see which lines in your code are potentially time
consuming (the more yellow, the slower, as a rule of thumb). If you
have much yellow inside a loop, you should do something about it.

That's quite handy for Cython code optimisation!

Best regards,
Simon

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

Reply via email to