#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 | Merged in: | sage-4.3.4.alpha0 |
Authors: | Fredrik Johansson | Reviewers: | Harald Schilly |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
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).
Attachments (3)
Change History (20)
Changed 13 years ago by
comment:1 Changed 13 years ago by
- Cc burcin added
comment:2 Changed 13 years ago by
Here is an 0.14 spkg
Changed 13 years ago by
comment:3 Changed 13 years ago by
Patch uploaded; let's see if it works.
Slightly updated spkg (still might make some minor changes before making it 0.14 final): http://boxen.math.washington.edu/home/fredrik/spkg/mpmath-0.14.spkg
comment:4 Changed 13 years ago by
- Status changed from new to needs_work
Hi, I applied the patch and installed your spkg. works + your tests pass.
I also tried the patch+spkg on 4.3.2.rc0 ... and it worked! all tests+your doctests pass here too! I also doctested the entire sage library, but there were some complaints.
Therefore positive review for the spkg from me, but others should test it on other platforms, too. Negative for the implications on the sage library because doctests fail on 4.3.1 and 4.3.2.rc0 /w mpmath 0.14 and above patch in
sage/libs/mpmath/utils.pyx
and /sage/functions/transcendental.py
all say:
ImportError: No module named mptypes
This exception pops up about 20 times ...
Changed 13 years ago by
comment:5 Changed 13 years ago by
Attached a fix for the ImportError.
comment:6 Changed 13 years ago by
- Status changed from needs_work to needs_review
That was easy, all tests pass ... green light from me!
I'm setting this to needs_review, and start with a positiv review from me.
comment:7 Changed 13 years ago by
- Status changed from needs_review to positive_review
comment:8 Changed 13 years ago by
- Reviewers set to schilly
comment:9 Changed 13 years ago by
- Milestone set to sage-4.3.3
comment:10 Changed 13 years ago by
Just a reminder: the spkg should be updated to the actual 0.14 release version.
comment:11 Changed 13 years ago by
Where is the new spkg? It does not seem to be here.
comment:12 Changed 12 years ago by
I don't know, there seems there was a misunderstanding. I've build a new 0.14 spkg with the actual 0.14 release.
comment:13 Changed 12 years ago by
I've tested this once again with 4.3.3 and it's still working and my positive review is still valid.
comment:14 Changed 12 years ago by
dear release manager. to get this done, merge the mpmath_cython.patch and the importfix.patch patch. after that get the updated spkg from here and that's it ;)
comment:15 Changed 12 years ago by
Harald's mpmath spkg has some changes that are not yet checked in:
[mvngu@sage mpmath-0.14]$ hg diff diff -r fa9536e74343 SPKG.txt --- a/SPKG.txt +++ b/SPKG.txt @@ -21,6 +21,9 @@ == Changelog == +=== mpmath-0.14 (Harald Schilly, Feb 20th, 2010) === + * updated to mpmath-0.14. + === mpmath-0.13 (Fredrik Johansson, August 14th, 2009) === * Updated to mpmath-0.13.
I have committed these changes in his name and uploaded the resulting spkg to
http://sage.math.washington.edu/home/mvngu/spkg/standard/mpmath/mpmath-0.14.spkg
comment:16 Changed 12 years ago by
- Merged in set to sage-4.3.4.alpha0
- Resolution set to fixed
- Reviewers changed from schilly to Harald Schilly
- Status changed from positive_review to closed
Merged in this order:
- mpmath_cython.patch
- importfix.patch
- Merged mpmath-0.14.spkg in the standard spkg repository.
comment:17 Changed 12 years ago by
Harald, Minh, thanks a lot!
contains edited sage.libs.mpmath (update: old files removed)