MAINT: silence invalid warning for np.log(complex(np.nan, np.nan)) and such - #32706
Merged
Merged
Conversation
jorenham
reviewed
Sep 20, 2026
mdhaber
commented
Sep 20, 2026
seberg
reviewed
Sep 20, 2026
invalid warning for np.log(complex(np.nan, np.nan)) and suchinvalid warning for np.log(complex(np.nan, np.nan)) and such
Co-authored-by: Joren Hammudoglu <[email protected]>
Contributor
Author
|
Thanks @seberg, looks like that did the trick. |
Member
|
Yap. In the past that didn't quite always do the trick. I think because SSE3.something didn't have quiet comparisons or so. I think that is now below our default baseline and times passed, so happy to give it a shot and see... |
This was referenced Sep 21, 2026
Riaz1729
pushed a commit
to Riaz1729/numpy
that referenced
this pull request
Sep 23, 2026
…` and such (numpy#32706) Co-authored-by: Joren Hammudoglu <[email protected]>
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
On (at least?) some platforms, including my Windows machine, complex logarithms with NaN input and NaN output produce
invalidwarnings (RuntimeWarning: invalid value encountered in log)Based on the behavior of other elementary functions (e.g.
np.sin) and other precedent (e.g. gh-12236, gh-15988, gh-32602), I don't think this is desired anymore. This PR eliminates the inadvertent warning by using floating point exception-quiet comparison implementations from the C standard library.Additional information
I encountered this while developing SciPy. I thought it would be better to fix the source rather than leaving the
np.errstatein the code indefinitely.This does not adjust the cases in which there is an infinite non-NaN component. Those produce
np.complex128(inf+nanj). In most cases, this is prescribed by the array API, but it seems a little less clear-cut whether the warning is desirable.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.