Add design document on complex number ordering#527
Merged
Conversation
rgommers
approved these changes
Nov 28, 2022
rgommers
approved these changes
Dec 5, 2022
Member
rgommers
left a comment
There was a problem hiding this comment.
The main points here, as listed in the PR description, were reviewed also in a call last Thursday, and there was general approval that this is the right approach. So in it goes.
Member
|
One thing to consider is to merge the content in this PR and the page on branch cuts in a single "complex number support" page. I'll add that to the list of content refactor tasks in gh-533. |
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.
This PR
less,less_equal,greater,greater_equal,argmin,argmax,argsort,sort,min,max) documenting that inequality comparison of complex numbers is unspecified and thus implementation-dependent.argsortandsortshould only accept real-valued data types. The current specification does not restrict the input data types forargsortandsort, but does restrictargminandargmaxto real-valued data types. This PR updatesargsortandsortto align withargminandargmax, as boolean values have no natural ordering. The divergence was likely an oversight.Prior Art
In general, because complex numbers have no natural ordering, ordering APIs supporting complex numbers inevitably lead to unintuitive results, as documented on the NumPy issue tracker. The general gist there is that ordering complex numbers should be deprecated, with only specialized support (with support for customized sort order) for complex number ordering when wanting to sort a complex number array.
np.argmax: numpy.argmax() doesn't behave intuitively with complex vectors numpy/numpy#10469np.median: np.median on a complex array return incorrect value for the imaginary part numpy/numpy#12943np.quantile: BUG: Quantile function on complex numbers doesn't error numpy/numpy#22652