Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Comparison of numpy.complex64 should throw a type error, as in the bare python complex number type #19168

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

Closed
bcrowell opened this issue Jun 4, 2021 · 2 comments

Comments

@bcrowell
Copy link

bcrowell commented Jun 4, 2021

Reproducing code example:

$ python3 -c 'print(1.0<1.0+1.0j)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: '<' not supported between instances of 'float' and 'complex'
$ python3 -c 'import numpy; print(1.0<numpy.complex64(1.0+1.0j))'
True
$ python3 -c 'import numpy; print(1.0<numpy.complex64(1.0-1.0j))'
False

NumPy/Python version information:

1.17.4 3.8.5 (default, May 27 2021, 13:30:53)
[GCC 9.3.0]

The bare python implementation throws an error, as it should. The behavior of the numpy.complex64 class shows behavior that is inconsistent with that, doesn't make sense mathematically, and doesn't seem to be documented anywhere. It appears to be doing a lexicographic comparison of real and imaginary parts. It should throw a type error instead. Since the present behavior does not seem to be defined anywhere, nobody should be depending on the undefined behavior, and fixing it should not cause problems.

@mattip
Copy link
Member

mattip commented Jun 7, 2021

Duplicate of #15981

@mattip mattip marked this as a duplicate of #15981 Jun 7, 2021
@seberg
Copy link
Member

seberg commented Mar 18, 2022

Going to close, as it is marked as duplicate. Thanks for the report!

@seberg seberg closed this as completed Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants