Fix of improper previous counterexample
β(x::NamedTuple{N,T}, y::NamedTuple{N2,T2}) where {N,T,N2,T2} =
length(N) === length(union(N,N2)) &&
all(k->getfield(x,k) == getfield(y,k), keys(x))
using Test
aa = (; foo=(bar=1, baz=2), qux=(quux=3, quuux=4))
bb = (; qux=(quuux=4, quux=3), foo=(baz=2, bar=1))
@test_broken aa β bb
Letβs consider
Base.isapprox(x::NamedTuple{N,T}, y::NamedTuple{N2,T2}) where {N,T,N2,T2} =
length(N) === length(union(N,N2)) &&
all(keys(x)) do k
isapprox(getfield(x,k), getfield(y,k))
end
using Test
aa = (; foo=(bar=1, baz=2), qux=(quux=3, quuux=4))
bb = (; qux=(quuux=4, quux=3), foo=(baz=2, bar=1))
@test aa β bb
# may be too much side effect
aa = (; foo=(bar=(1+1e-8), baz=2), qux=(quux=3, quuux=4))
bb = (; qux=(quuux=4, quux=3), foo=(baz=2, bar=(1+1e-9)))
@test aa β bb
This may work / or not, considering wheter if we intend to recursively compare approximatively or not
Still a badly defined semantic from base IMO . Accepting eq upon perms is orthogonal to num tolerance