-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add kernel implementation of Binomial() #1921
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fingolfin
added
kind: enhancement
Label for issues suggesting enhancements; and for pull requests implementing enhancements
topic: kernel
labels
Nov 17, 2017
markuspf
reviewed
Nov 17, 2017
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why you keep the old GAP code around (commented out)?
Codecov Report
@@ Coverage Diff @@
## master #1921 +/- ##
==========================================
+ Coverage 63.71% 63.77% +0.05%
==========================================
Files 947 947
Lines 284484 284539 +55
Branches 12744 12757 +13
==========================================
+ Hits 181264 181457 +193
+ Misses 100436 100284 -152
- Partials 2784 2798 +14
|
This uses the GMP functions mpz_bin_ui and mpz_bin_uiui. The following timings for certain central binomial coefficients illustrates the speedup: gap> n:=2^14;; a:=BINOMIAL_INT(2*n,n);; time; b:=Binomial_GAP(2*n,n);; time; 0 51 gap> n:=2^16;; a:=BINOMIAL_INT(2*n,n);; time; b:=Binomial_GAP(2*n,n);; time; 2 719 gap> n:=2^18;; a:=BINOMIAL_INT(2*n,n);; time; b:=Binomial_GAP(2*n,n);; time; 8 11470 gap> n:=2^19;; a:=BINOMIAL_INT(2*n,n);; time; b:=Binomial_GAP(2*n,n);; time; 14 51386 gap> n:=2^20;; a:=BINOMIAL_INT(2*n,n);; time; b:=Binomial_GAP(2*n,n);; time; 33 190444 The main reason the C version is so much faster is that it can accumulate the result in-place, whereas GAP creates tons and tons of temporary integer objects which then need to be garbage collected. Of course some other tricks employed by GMP help, too.
fingolfin
force-pushed
the
mh/binomial
branch
from
November 17, 2017 19:36
198594d
to
f26ded4
Compare
Not really, I just forgot to remove it. Now fixed. Also tweaked the commit message a bit. |
ChrisJefferson
approved these changes
Nov 20, 2017
olexandr-konovalov
added
the
release notes: added
PRs introducing changes that have since been mentioned in the release notes
label
Jan 22, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
kind: enhancement
Label for issues suggesting enhancements; and for pull requests implementing enhancements
release notes: added
PRs introducing changes that have since been mentioned in the release notes
topic: kernel
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This example illustrates the speedup:
Note that on 32bit systems, some previously "supported" combinations (n,k) are no longer supported. But those values are effectively out of reach for the old code, too: if I extrapolate the results above in various ways, I get an estimate of about 30 days to compute the smallest binomial coefficient (for n=2^28) not supported. Granted, this is on my laptop, and your super computer might get to it quicker. But at that point you might also just use the 64 bit version of GAP, which gets the result on my laptop in less than 30 seconds: