sage: %time pts=[ elliptic_ec(m) for m in
srange(0,1,0.01,include_endpoint=True)]
CPU times: user 0.35 s, sys: 0.06 s, total: 0.41 s
Wall time: 3.09 s
What's interesting about this is that Wall time is much higher, also
for you. That's starting Maxima, I think. But once you've started
Maxima up, then things go down:
sage: %time pts=[ elliptic_ec(m) for m in
srange(0,1,0.01,include_endpoint=True)]
CPU times: user 0.33 s, sys: 0.04 s, total: 0.37 s
Wall time: 0.56 s
sage: timeit("pts=[ elliptic_ec(m) for m in
srange(0,1,0.01,include_endpoint=True)]")
5 loops, best of 3: 581 ms per loop
I think that a lot of that would be overhead from using Maxima via our
interpreter as well. Taking a hint from achrzesz:
sage: timeit("pts=maxima('makelist(elliptic_ec(0.01*k),k,0,100)') ")
5 loops, best of 3: 38.9 ms per loop
Also,
sage: pts0=map(n,pts)
will only work if you haven't redefined the numerical approximation
function n. But you could do
sage: pts0=map(numerical_approx,pts) without too much trouble.
However, it seems like that reintroduces the timing problem, by
needing to turn all those Maxima elements to Sage elements one by
one. So instead, you might want to just try
sage: pts=maxima('makelist(elliptic_ec(0.01*k),k,0,100)').sage()
which should be better for you - ten times faster for me:
sage: timeit("pts=maxima('makelist(elliptic_ec(0.01*k),k,
0,100)').sage()")
5 loops, best of 3: 47.9 ms per loop
This works for your actual use case too.
sage: timeit("pts=maxima('makelist(elliptic_ec(0.01/(1+b)),b,
0,100)').sage()")
5 loops, best of 3: 47.7 ms per loop
Notice that if you do things straight in Maxima, you don't have to
define the variable. Of course, you'll have to use Maxima syntax to
use this.
Incidentally, eventually we hope to translate to Maxima much more
efficiently; several tickets which should be merged soon will go a
long ways toward doing this.
- kcrisman
On Mar 28, 8:06 am, ObsessiveMathsFreak
<[email protected]> wrote:
> The standard code to compute elliptic integrals in sage appears to be
> _very_ slow numerically. To compute the complete elliptic integral on
> 100 points in the unit interval takes about 16 seconds for me.
>
> sage: %time pts=[ elliptic_ec(m) for m in
> srange(0,1,0.01,include_endpoint=True)]
> CPU times: user 0.59 s, sys: 0.06 s, total: 0.65 s
> Wall time: 16.44 s
>
> By contrast, Octave computes these in less than 0.2 seconds on the
> same machine
>
> octave:37> tic; [k,e]=ellipke([0:0.01:1]'); toc
> Elapsed time is 0.01437 seconds.
>
> Am I doing something wrong here? I realise sage isn't a numerical
> system, but this code appears to be quite slow.
--
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