On Nov 27, 2:15 pm, KvS <keesvansch...@gmail.com> wrote:
> Dear all,
>
> just a quick question/remark, today I was working (plotting etc.) with
> some quantities that involve (upper) incomplete gamma functions. Some
> operations took very long, as it turned out due to the incomplete
> gamma function evaluating very slowly for small arguments. Some
> testing showed that mpmath's version is a lot quicker (I've seen
> differences like 2~3 secs versus ~0.1 secs). Unfortunately I don't
> have SAGE on this computer so I can't post any code or exact numbers.
> Due to my setup (actually requiring SAGE function objects) I had to
> fiddle around and make several changes at several places to be able to
> use mpmath's version. I was wondering whether it might be possible &
> would be an attractive feature to modify SAGE's version in such a way
> that mpmath's version gets called when the function is called with a
> numerical argument?
>
> Many thanks, Kees

On my laptop, I get:

sage: %timeit mpmath.gammainc(2r, 3.3r)
625 loops, best of 3: 44.8 µs per loop
sage: %timeit mpmath.gammainc(2.1r, 3.3r)
625 loops, best of 3: 588 µs per loop
sage: %timeit gamma_inc(2r, 3.3r)
625 loops, best of 3: 493 µs per loop
sage: %timeit gamma_inc(2.1r, 3.3r)
625 loops, best of 3: 480 µs per loop

So the mpmath incomplete gamma function appears slightly slower for
non-integer first argument (this is probably something that can be
improved in mpmath), and significantly faster for integer first
argument. Perhaps this is what you're seeing.

The timings could also depend on the types. I guess the Sage code
spends some time converting the problem to Pari and back. For example,
the following is much slower:

sage: %timeit gamma_inc(SR(2), SR(2.3))
125 loops, best of 3: 1.76 ms per loop

There can be a similar overhead when calling mpmath functions with
Sage objects as input.

Fredrik

-- 
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