Skip to content

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

@philippdahm

Description

@philippdahm

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.

tol = 1e-12

# Check that the inner product of a vector is correct after scalar
# multiplication and vector addition.
vec_add_mult = test_vec * scale_factor + test_vec
if abs(
self.inner_product(vec_add_mult, vec_add_mult) -
vec_copy_mag_sq * (scale_factor + 1) ** 2) > tol:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions