-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Comparison ops for Complex Tensors #36444
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
this is the most compelling argument for me |
We need to develop kernels that
@n-west had some really good ideas about making min/max different from clamp for complex numbers. Clamp
clamp(c, c_min, c_max) = complex(clamp(c.real, c_min.real, c_max.real),
clamp(c.imag, c_min.imag, c_max.imag))
Min/MaxFor Now: No default complex comparison. Nothing would currently benefit from hw acceleration.
|
This problem seems similar to how nans are compared in floating point, i.e. there are some reasonable choices but no perfect definition. @rgommers (or others who are familiar with NumPy) -- I wonder why NumPy decided to make the different choices here different functions as opposed to an optional argument, i.e. why define both amax and nanmax instead of |
It seems like we have consensus on disabling complex comparison ops (and the ops which logically rely on them) for now. @dylanbespalko Your idea for a complex clamp is interesting, but maybe we can find a new name for it? |
The proposed API from @dylanbespalko would work great for my applications! I like the idea of naming the complex clamp something else just to 100% prevent people from thinking np.clip and torch.clamp would do that same thing even though they are named differently (because for other datatypes they are the same operation AFAIK). No very clear operator name comes to mind though |
NumPy added |
Uh oh!
There was an error while loading. Please reload this page.
This issue is intended to roll-up several conversations about how PyTorch should compare complex values and how functions that logically rely on comparisons, like min, max, sort, and clamp, should work when given complex inputs. See #36374, which discussed complex min and max, and #33568, which discussed complex clamp. The challenge of comparing complex numbers is not limited to PyTorch, either, see numpy/numpy#15630 for NumPy's discussion of complex clip.
Comparing complex numbers is challenging because the complex numbers aren't part of any ordered field. In NumPy, they're typically compared lexicographically: comparing the real part and only comparing the imaginary part if the real parts are equal. C++ and Python, on the other hand, do not support comparison ops on complex numbers.
Let's use this issue to enumerate complex comparison options as well as their pros and cons.
The current options are:
cc. @rgommers @dylanbespalko @ezyang @mruberry
cc @ezyang @anjali411 @dylanbespalko
The text was updated successfully, but these errors were encountered: