tpapp / TransformVariables.jl

Transformations to contrained variables from ℝⁿ.
Other
66 stars 14 forks source link

`inverse` fails for transformation with nested named tuples #93

Closed scheidan closed 2 years ago

scheidan commented 2 years ago

The inverse function fails if we have nested Named Tuples. For "normal" tuples it works well:

using TransformVariables  # v0.6.2

# transformation with nested *Named*Tuple
t1 = as((
    a = as(Real, 0, 0.1),
    b = as(
        (b1 = as(Real, 1, 5),
         b2 = as(Real, 10, 50))
    )
))

x = transform(t1, randn(dimension(t1)))
y = inverse(t1, x)              # <- fails
# ERROR: ArgumentError: length(x) == dimension(tt) must hold. Got
# length(x) => 3
# dimension(tt) => 2

# transformation with nested Tuple
t2 = as((
    a = as(Real, 0, 0.1),
    b = as(
        (as(Real, 1, 5),        # no names
         as(Real, 10, 50))
    )
))

x = transform(t2, dimension(t2))
y = inverse(t2, x)              # works :)
tpapp commented 2 years ago

Thanks, I can confirm that this is a bug. Will look into it.