Hi team,
We have recently just merged TST: add dtype dependent default rtol to xp_assert_close by j-bowhay · Pull Request #20625 · scipy/scipy · GitHub to help with adding array API support. Specifically, this PR adds dtype-dependent tolerances. Quoting from the PR:
Different array libraries have different default floating dtypes and as such the default
rtol=1e-7
ofxp_assert_close
can be too stringent when using the default type. This leaves two options:
- Specify the
dtype
of the input data eg.xp.asarray(..., dtype=xp.float64)
- Specify a lower value of
rtol
The first is potentially as undesirable as it is reasonable to expect the user to be using the default type most of the time. The second is potentially undesirable as it makes the test unnecessarily less stringent for some libraries.
As for the choice of value:
Good question. It is a nice number that puts us about halfway between
sqrt(eps)
and the old1e-7
default for floats, and it was on my mind because it’s used in the definition of tolerances inoptimize._zeros.py
. And yeah, it happened to be enough so that no old tests started failing. I can add a comment that any multiple that keeps us under the old default would be OK.sqrt(eps)
can be theoretically motivated in some contexts.
If you would like to motivate a different choice of value or approach please feel free to open a PR or discuss!
Thanks,
Jake