-
Notifications
You must be signed in to change notification settings - Fork 44
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
test_square test failure with numpy complex64 #190
Comments
Actually this failure comes up with all array libraries. It seems the test is just wrong for floating-point arithmetic. |
A related error with numpy
>>> import numpy as np
>>> np.square(np.array(1.+8.98846567e+307j))
<stdin>:1: RuntimeWarning: overflow encountered in square
(-inf+1.797693134e+308j) |
The example in the OP varies between NumPy versions: >>> import numpy as np
>>> np.square(np.asarray(16002.+16002.j, dtype=np.complex64))
(4+512128000j)
>>> np.__version__
'1.25.0.dev0+1503.g58224647e8' >>> import numpy as np
>>> np.square(np.asarray(16002.+16002.j, dtype=np.complex64))
512128000j
>>> np.__version__
'1.24.2' The spec for square doesn't say anything about how accurate the result should be, other than that the special cases should match for A big part of the problem is that the helpers are comparing the real and imaginary parts separately. For example, here array-api-tests/array_api_tests/test_operators_and_elementwise_functions.py Lines 264 to 265 in f82c7bc
For floating-point closeness, a complex number should be compared directly, for example, by using Also, for |
data-apis/array-api-tests#190 has been fixed.
I haven't investigated further other than to confirm that it does indeed do that
I don't know if this is a bug in NumPy or just an expected numerical inaccuracy that we shouldn't b testing. I suspect the latter. Note that the relative error is around 1e-8
OTOH, PyTorch does give a purely imaginary answer as expected:
The text was updated successfully, but these errors were encountered: