bpo-35431: Refactor math.comb() implementation. - #13725
Conversation
4e778ca to
678efbb
Compare
mdickinson
left a comment
There was a problem hiding this comment.
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]>
* Fixed some bugs. * Added support for index-likes objects. * Improved error messages. * Cleaned up and optimized the code. * Added more tests.
int.intsubclasses 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