belson17 / modred

Modred main repository
BSD 2-Clause "Simplified" License
78 stars 38 forks source link

Sanity check using absolute error. suggest using relative error #55

Open philippdahm opened 1 year ago

philippdahm commented 1 year ago

Hey all, seems that the sanity check is using absolute error (difference in results) in checking definition of the vectorspace. When using a large-valued vector, this error is sometimes not achievable due to machine precision.

In my example, the inner products are of the order of 1e8 with a 1e-9 absolute error. This causes the check to fail with the default tolerance of 1e-12.

To me, it makes sense to turn this into a check on relative error (ratio of results) rather than absolute (difference of results) as to avoid machine precision issues.

https://github.com/belson17/modred/blob/bbe35c8ef1410999c2cc46c97d3351c23ab1be0f/modred/vectorspace.py#L156 https://github.com/belson17/modred/blob/bbe35c8ef1410999c2cc46c97d3351c23ab1be0f/modred/vectorspace.py#L202-L207