BUG: fix corner cases in complex division (were nan+nanj)#26595
Closed
skirpichev wants to merge 3 commits intonumpy:mainfrom
skirpichev:fix-complex-tdiv-26560
Closed
BUG: fix corner cases in complex division (were nan+nanj)#26595skirpichev wants to merge 3 commits intonumpy:mainfrom skirpichev:fix-complex-tdiv-26560
skirpichev wants to merge 3 commits intonumpy:mainfrom
skirpichev:fix-complex-tdiv-26560
Conversation
The numpy uses Smith's algorithm to do complex true division. In some
cases (see below) it produces (nan+nanj), but meaningful components
could be recovered. See e.g. C11 Annex G.5.2, _Cdivd()'s example.
>>> 1/complex128('(inf+infj)') # should be 0j
<stdin>:1: RuntimeWarning: invalid value encountered in scalar divide
(nan+nanj)
>>> complex128(inf, -inf)/complex128(1+0j) # should be (inf-infj)
<stdin>:1: RuntimeWarning: invalid value encountered in scalar divide
np.complex128(nan+nanj)
Closes #26560
Member
|
Since this touches the inner loops, we should benchmark to make sure any change is acceptable. This will also need a release note. |
Author
It seems I can't built numpy locally (on my old notebook:D), not sure how to do this...
Done. |
Author
In usual case (Smith's division algorithm produces meaningful output) this adds just one extra BTW, here some benchmarks on CPython. Current main, with similar patch: Without: |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The numpy uses Smith's algorithm to do complex true division. In some cases (see below) it produces (nan+nanj), but meaningful components could be recovered. See e.g. C11 Annex G.5.2, _Cdivd()'s example.
Closes #26560
FYI, related PR in CPython: python/cpython#119457