Conversation
mdhaber
marked this pull request as draft
September 27, 2026 01:37
mdhaber
force-pushed
the
silence-complex-divide-nan-warnings
branch
from
September 27, 2026 03:12
23f5561 to
9abbde9
Compare
mdhaber
commented
Sep 27, 2026
Contributor
Author
There was a problem hiding this comment.
Split the NaN input -> NaN + NaN j output into three cases:
| const @ftype@ in2r_abs = npy_fabs@c@(in2r); | ||
| const @ftype@ in2i_abs = npy_fabs@c@(in2i); | ||
| if (in2r_abs >= in2i_abs) { | ||
| if (npy_isnan(in2r) || npy_isnan(in2i)) { |
Contributor
Author
There was a problem hiding this comment.
- at least one component of the denominator is NaN
Comment on lines
+2220
to
+2223
| else if ((npy_isnan(in1r) || npy_isnan(in1i)) && | ||
| (((npy_isinf(in1r) || npy_isinf(in1i)) && | ||
| (in2r != 0 || in2i != 0)) || | ||
| (npy_isinf(in2r) && npy_isinf(in2i)))) { |
Contributor
Author
There was a problem hiding this comment.
- At least one component of the numerator is NaN and either:
- the numerator has an infinite component and the denominator is nonzero
- both denomonator components are infinite.
| if (in2r_abs == 0 && in2i_abs == 0) { | ||
| if ((npy_isnan(in1r) && | ||
| (in1i == 0 || npy_isnan(in1i))) || | ||
| (in1r == 0 && npy_isnan(in1i))) { |
Contributor
Author
There was a problem hiding this comment.
- All zero denominator, and numerator is one of:
NaN + 0j
0 + NaN j
NaN + NaN j
| assert_almost_equal(n_r[i], p_r[i], err_msg=f'Loop {i}\n') | ||
|
|
||
|
|
||
| class TestCdiv: |
Contributor
Author
There was a problem hiding this comment.
Could be more exhaustive if desired.
Comment on lines
+429
to
+431
| (1 + 1j, complex(np.nan, 1)), | ||
| (1 + 1j, complex(1, np.nan)), | ||
| (1 + 1j, complex(np.nan, np.nan)), |
Comment on lines
+432
to
+433
| (complex(np.nan, 0), 0j), | ||
| (complex(0, np.nan), 0j), |
Comment on lines
+434
to
+435
| (complex(np.nan, np.inf), 1), | ||
| (complex(np.nan, 1), complex(np.inf, np.inf)), |
This branch has not been deployed
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.
PR summary
np.dividewith complex NaN input produceinvalidwarnings. Based on the behavior of other ufuncs and other precedent (e.g. gh-12236, gh-15988, gh-32602, gh-32706), I don't think this is desired anymore. This silences the warnings with some special case handling.Additional information
We should sync up the release notes in gh-32751 once this merges.
AI Disclosure
OpenAI Codex was used to inspect the relevant implementation and tests, draft the code changes and regression tests, and prepare this AI disclosure.