-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-35431: Refactor math.comb() implementation. #13725
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
Conversation
4e778ca
to
678efbb
Compare
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.
Changes LGTM, as far as they go.
I'm not particularly happy with the current error messages: I'd expect comb(-1, 1)
to complain that n
is negative, instead of complaining that n
should be larger than k
. And the code path that leads to that error isn't obvious, either. What do you think about adding an up-front check for the sign of n
, with a corresponding error message? There would be a (very) small performance cost (a Py_SIGN
check should be cheap), but I think the improvement would be worth it.
Anyway, that's not a problem introduced by this PR, and fixing it doesn't have to happen in this PR either.
One more thought: should we be using |
I was reviewing this PR and realized the original implementation is leaking references I opened |
I checked and this PR is fixing the leak: ❯ ./python -m test test_math -R : == Tests result: SUCCESS == 1 test OK. Total duration: 26 sec 283 ms |
Codecov Report
@@ Coverage Diff @@
## master #13725 +/- ##
==========================================
+ Coverage 82.76% 82.77% +<.01%
==========================================
Files 1843 1843
Lines 559928 559938 +10
Branches 41403 41403
==========================================
+ Hits 463425 463485 +60
+ Misses 87422 87386 -36
+ Partials 9081 9067 -14
Continue to review full report at Codecov.
|
Co-Authored-By: Pablo Galindo <[email protected]>
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.
Still LGTM
* Fixed some bugs. * Added support for index-likes objects. * Improved error messages. * Cleaned up and optimized the code. * Added more tests.
int
.int
subclasses with overridden__sub__
,__lt__
, etc.MemoryError is now always raised for too largemin(k, n-k)
. Previously MemoryError or OverflowError could be raised depending on the value.https://bugs.python.org/issue35431