Add design document on complex number ordering #527
Merged
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.argsort
andsort
should only accept real-valued data types. The current specification does not restrict the input data types forargsort
andsort
, but does restrictargmin
andargmax
to real-valued data types. This PR updatesargsort
andsort
to align withargmin
andargmax
, 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