-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
ENH: need matlab compatible min and max for complex numbers #8151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It's lexicographic order, similarly as in |
From http://math.stackexchange.com/questions/310931/comparing-complex-numbers#310941, I think this boils down to asking whether complex numbers can be ordered at all, with the answer being that, no, generally they cannot. So, the logical consequence would be not to allow finding a minimum at all. Indeed, this is the case in python proper:
Indeed, comparison itself is not defined in python, but defined in numpy:
Anyway, not something one can change lightly. |
For what it's worth, Matlab uses the magnitude here. Pure-python and julia raise errors. |
Yes, complex number comparison is ill defined. Lexical order is
compatible with addition, but not multiplication. Magnitude is not total
ordering.
.
But I would leave it as it is, and leave it to the user to know what
they're doing when comparing complex numbers.
|
Suggest closing (behavior appears intended, changing probably disruptive).
|
Yep, the sort order is lexicographic. |
So my follow-up question was could we have |
I don't think it would be too difficult to make such functions, but with different names than max/min. A PR would be welcome. |
Ok, could I ask that we reopen this issue so that we can keep track of it? I don't have time for such a PR now, but would be willing to do it in the near future. |
OK, I reopened with a |
I don't know if there is still interest here. But I would be interested in such a function too. Would it be called: Application note: In optics, it is sometimes useful to find the point of maximum intensity, but to propagate your field as a complex number. |
Signed ints are a bit of a problem for abs, as the most negative values are invariant. If we stick to inexact types, no problem. Maybe always return an unsigned type, but then there are unexpected promotions. Maybe just warn when problem encountered? |
For integers, maybe it should be implemented as minmax? The the check for the most negative value becomes order 1 |
Not sure we are on the same wavelength here. The problem is that that signed twos complement integers have more negative values than positive ones, so there is no way to represent the absolute value of the most negative value without changing types.
So Hmm, I suppose that wouldn't be so bad if it is documented, might even be useful as the result will always be positive. |
I get it. but max_abs could do something like
|
related: #2004 |
If I take the minimum or maximum of complex numbers, I would expect that the magnitude is used. However, I find the real component is used instead. Here is a simple example. My expectation would be max and min are reversed in this case.
The text was updated successfully, but these errors were encountered: