You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gh-39891: Speed up binomial
As first observed in #39379, when
`n` and `k` are small sage integers, `binomial(n, k)` are much slower
than `n.binomial(k)`.
This pull request fixes it. Now `%timeit binomial(20, 10)` is only twice
slower than `%timeit 20.binomial(10)` — previously it was **30** times
slower.
There's also a minor patch where some code is skipped when all arguments
are instances of `Element`. It is certainly a more common case for the
input to be `Element` than otherwise, so we optimize for it.
Another minor patch involves storing imported modules as C global
variables instead of re-import every time.
I think using not-overriding `_method_arguments` as an indicator of
"don't call the method"
(then silently catch `TypeError` and throw it away) is rather bad
design,
but this is not in scope here.
### 📝 Checklist
<!-- Put an `x` in all the boxes that apply. -->
- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.
URL: #39891
Reported by: user202729
Reviewer(s): Travis Scrimshaw
0 commit comments