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

Skip to content

BUG: spurious failure in assert_allclose #23697

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
h-vetinari opened this issue May 2, 2023 · 3 comments
Closed

BUG: spurious failure in assert_allclose #23697

h-vetinari opened this issue May 2, 2023 · 3 comments
Labels

Comments

@h-vetinari
Copy link
Contributor

Describe the issue:

assert_allclose fires, even though the specified tolerances are not violated

Reproduce the code example:

import numpy as np
from numpy.testing import assert_allclose
x = np.array([1.110223e-16, 1.000000e+00, 1.000000e+00, 1.110223e-16])
y = np.array([0., 1., 1., 0.])
assert_allclose(x, y, rtol=1e-14)  # fails
assert_allclose(y, x, rtol=1e-14)  # also fails

Error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\[xxx]\.conda\envs\dev\lib\site-packages\numpy\testing\_private\utils.py", line 1592, in assert_allclose
    assert_array_compare(compare, actual, desired, err_msg=str(err_msg),
  File "C:\Users\[xxx]\.conda\envs\dev\lib\contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "C:\Users\[xxx]\.conda\envs\dev\lib\site-packages\numpy\testing\_private\utils.py", line 862, in assert_array_compare
    raise AssertionError(msg)
AssertionError:
Not equal to tolerance rtol=1e-14, atol=0

Mismatched elements: 2 / 4 (50%)
Max absolute difference: 1.110223e-16
Max relative difference: 0.
 x: array([1.110223e-16, 1.000000e+00, 1.000000e+00, 1.110223e-16])
 y: array([0., 1., 1., 0.])

Runtime information:

>>> import sys, numpy; print(numpy.__version__); print(sys.version)
1.24.3
3.10.10 | packaged by conda-forge | (main, Mar 24 2023, 20:00:38) [MSC v.1934 64 bit (AMD64)]
>>> print(numpy.show_runtime())
[{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
                      'found': ['SSSE3',
                                'SSE41',
                                'POPCNT',
                                'SSE42',
                                'AVX',
                                'F16C',
                                'FMA3',
                                'AVX2'],
                      'not_found': ['AVX512F',
                                    'AVX512CD',
                                    'AVX512_SKX',
                                    'AVX512_CLX',
                                    'AVX512_CNL',
                                    'AVX512_ICL']}}]

Context for the issue:

No response

@h-vetinari h-vetinari changed the title BUG: spurious failure in assert_allclose BUG: spurious failure in assert_allclose when element is 0 May 2, 2023
@h-vetinari
Copy link
Contributor Author

This shows up in scipy CI where TestTukey.test_basic used to pass and now fails.

@h-vetinari h-vetinari changed the title BUG: spurious failure in assert_allclose when element is 0 BUG: spurious failure in assert_allclose May 2, 2023
@h-vetinari
Copy link
Contributor Author

PS. I realize that doing something "relative" to 0 is tricky. But I guess one could take the minimum of whether a or b is the reference? While this looks fixable by adding atol=, I wanted to note the apparent regression.

@seberg
Copy link
Member

seberg commented May 2, 2023

Going to close this, I don't think it has anytihng to do with testing the behavior is correct and didn't change. This is part of the sin/cos precision change problem in gh-23399 (for which opening an issue may make sense).

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

No branches or pull requests

2 participants