[Numpy-discussion] commutative allclose
Charles R Harris
charlesr.harris@gmail....
Thu Apr 10 16:49:46 CDT 2008
On Thu, Apr 10, 2008 at 1:56 PM, Tom Johnson <tjhnson@gmail.com> wrote:
> Should allclose() be commutative, so as to prevent the following:
>
> >>> x = 1.00001001
> >>> allclose(x,1), allclose(1,x)
> (False, True)
>
> There is some discussion here which provides two possible solutions:
>
>
> http://www.boost.org/doc/libs/1_35_0/libs/test/doc/components/test_tools/floating_point_comparison.html
>
> Notice, the discussion states that their solutions are not
> transitive---nevertheless, I think commutativity is a worthwhile
> improvement. Also, they mention that rtol * abs(y) can cause
> underflow issues. Thus, they implement,
>
> |x-y|/|y| <= rtol AND(OR) |x-y|/|x| <= rtol
>
> without an atol option, rather than
>
> |x-y| <= atol + rtol* |y|
>
> Naively, it seems like atol is attempting to correct this very issue.
> So do we really need atol?
I think it useful, especially when working with values that may be zero.
However, it might not be necessary in the allclose context. On the other
point, it is also possible to use the max, avg, or sum of |x| and |y|, which
will avoid the case when on of them gets too small.
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080410/fe465730/attachment.html
More information about the Numpy-discussion
mailing list