No, because you are passing only a relative tolerance rtol
. That means it will still probably fail if t[1] - s[1]
happens to be nearly zero.
Yes, using atol
is safer, but requires you to pick a reasonable atol
, and that depends on the problem because atol
is dimensionful.
For example, suppose your vectors represent positions of stars in the galaxy, with coordinates measured in meters. Then atol = 1e-3
(1mm) is probably a ridiculously small tolerance. On the other hand, if you are doing atomic physics with distances in meters, where the typical scale is angstroms, then atol = 1e-3
is a ridiculously large tolerance.
This is still likely to fail if any element of t
happens to be zero or nearly zero.
Note, by the way, that ≈
works perfectly well on arrays, or arrays of arrays (anything with a norm
), so using ≈
with all
is generally unnecessary (and more susceptible to scaling problems). You can just do s .+ Ref(mean(t-s)) ≈ t
(no dot on the ≈
), which is more robust although it will still be problematic if norm(t) == 0
(maybe that is less likely … but ultimately you should still be thinking about an appropriate problem-dependent atol
).