Skip to content

Draft: Fix floating point error domain inequality bug

Lukas Platz requested to merge fix_domain_equality_bug into NIFTy_7

As it turns out, in Python 1. / i * i is not exactly one for many integers, for example 49. In the range of 1-10000, this is true for 1178 ints. When creating an RGSpace d with the shape (i,), d == d.get_default_codomain().get_default_codomain() is not necessarily true, because of potentially unequal distances values.

This is problematic since harmonic transform operators constructed with domain=d.get_default_domain() without giving an explicit target will for many values of i have a target unequal from d.

To alleviate this, this patch modiefies the domain.__eq__() function to compare __hash__() return values instead of manually comparing domain values and modiefies the domain.__hash__() function to round the distances entries to 15 decimals prior to hashing.

If using the hash in the comparison is unfavorable because of its performance impact, __eq__() could be restored to is previous state and the distance rounding be implemented in it, too.

@mtr: what do you think about this patch? Is there an obviously better solution?

Edited by Lukas Platz

Merge request reports