Skip to content

Draft: Define general utility function for recursive isequal and use it for parameters

Philip Bittihn requested to merge paramequality into dev

Sometimes, it is useful to be able to compare parameters for equivalence (e.g., to test reconstruction in unit tests). Doing so by == or isequal is possible for most cases right now. This only works if the hierarchy of a parameter struct, its fields, its fields' fields, etc. is composed of immutable structs. Once there is something mutable (e.g. a Dictionary) in the hierarchy, == fails to detect equality. To be able to make use of custom comparison operators for field values, one would have to define equality recursively by default. However, defining == recursively doesn't work because NaN ≠ NaN (semantically, we want to check for equivalence, not equality).

Therefore, I suggest we compare parameters using isequal, which has the right semantics for NaN. This merge request defines a helper function, so other user-defined types T appearing in parameter structs can easily implement a recursive isequal for themselves with isequal(x::T,y::T) = InPartS.recursive_isequal(x,y).

The same functionality could be pulled from StructEquality.jl, but I am not sure it's worth introducing another dependency.

Edited by Philip Bittihn

Merge request reports