Numpy version 1.24.0.

The current behavior of `np.testing.assert_allclose` and `np.allclose` are 
still inconsistent with the docs, which specifies that `atol` and `rtol` must 
be a scalar. However, the current implementation of `np.allclose` allows 
passing in `atol` and `rtol` as an array, while `np.testing.assert_allclose` 
only raises error because of a string formatting line `header = f'Not equal to 
tolerance rtol={rtol:g}, atol={atol:g}'`. To make things less confusing, for 
BOTH `np.allclose()` and `np.testing.assert_allclose()`, we should either 
perform a check for the correct type of `atol` and `rtol`, or to actually 
support an array as `atol`.

Indeed there are real use-cases for array `atol` and `rtol`. For example for 
`atol`: let's say we want to compare two 3D vectors x and y where the first two 
axis should have absolute tolerance of 0.1 while the third axis should have 
absolute tolerance of 1, because there are more stringent requirements on x and 
y. I believe this is the use case that many of us run into, and it is quite 
natural to write

```python3
import numpy as np
x = [1, 2, 3]
y = [1.1, 2.1, 5]
np.allclose(x, y, atol=[0.1, 0.1, 1])
```

[I have posted this as a comment on an 
issue](https://github.com/numpy/numpy/issues/14320#issuecomment-1482201277)
[And there is already a proposed PR to support this 
change](https://github.com/numpy/numpy/pull/14343)
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to