Ticket #8159 (closed enhancement: fixed)
Updated Cython backend for mpmath
| Reported by: | fredrik.johansson | Owned by: | tbd |
|---|---|---|---|
| Priority: | major | Milestone: | sage-4.3.4 |
| Component: | performance | Keywords: | mpmath |
| Cc: | burcin | Author(s): | Fredrik Johansson |
| Report Upstream: | N/A | Reviewer(s): | Harald Schilly |
| Merged in: | sage-4.3.4.alpha0 | Work issues: |
Description
This update of sage.libs.mpmath, along with recent changes to mpmath itself and the patch in #6199, results in a 3x overall speedup of mpmath (as measured by mpmath.runtests() performance). Elementary functions, hypergeometric series, and other "low-level" transcendental functions are not affected much, but functions that do a lot of arithmetic with mpf/mpc instances (examples: lambertw, polylog, bernpoly and many others; numerical summation, numerical integration, etc) can be 3x-10x faster. A similar speedup should be attainable in the future for the "low-level" functions by implementing those in Cython as well.
This extension works if site-packages/mpmath is replaced with an svn trunk checkout. There are essentially no tests in the Cython modules themselves; testing can be done with
import mpmath; mpmath.runtests(); mpmath.doctests()
(There is a very small number of doctests that fail due to numerical noise; this is nothing to worry about.)
This is not the final version of the code to be committed (it will synchronized with the next release of mpmath), but I'm uploading it to have a safe copy and for potential early review. I have not tested this on a 32-bit system. There could be some subtle overflow or memory leak issues that aren't caught by the tests.
It's not thread-safe due to the use of global state (which is used mostly because I was lazy, but it possibly also helps performance). I don't consider this a serious bug since vanilla-Python mpmath isn't fully thread-safe either. But it should be fixed some time in the future.
I think a number of optimizations are possible, including optimizing MPF_normalize and caching MPF and mpf/mpc instances. I have also not updated the mpmath <-> Sage conversion code, which could be improved not to go via tuple values.
Sorry that it's not in the form of a patch (my current hg copy of Sage being dirty).

