Skip to content

no method matching iterate(::NoLogAbsDetJacobian) #124

Open
@cscherrer

Description

This doesn't work:

julia> using ChainRules, MeasureBase, InverseFunctions

julia> f(x) = 3x + 1
f (generic function with 1 method)

julia> finv(y) = (y - 1) / 3
finv (generic function with 1 method)

julia> d = pushfwd(setinverse(f, finv), StdNormal())
PushforwardMeasure(
    InverseFunctions.FunctionWithInverse{typeof(f), typeof(finv)}(f, finv),
    StdNormal())

julia> logdensity_def(d, 0.2)
ERROR: MethodError: no method matching iterate(::NoLogAbsDetJacobian{typeof(finv), Float64})

Closest candidates are:
  iterate(::Base.EnvDict)
   @ Base env.jl:186
  iterate(::Base.EnvDict, ::Any)
   @ Base env.jl:186
  iterate(::Base.AsyncGenerator, ::Base.AsyncGeneratorState)
   @ Base asyncmap.jl:362

The problem is a line that reads

x_orig, inv_ladj = with_logabsdet_jacobian(unwrap(finv), y)

The rhs is a NoLogAbsDetJacobian{typeof(finv), Float64}, which the lhs tries to deconstruct as a pair.

It would be better to assign this a temporary variable first, so we could add a line that gives an informative error if it's not a pair. After that we could deconstruct it safely.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions