Skip to content

unflatten doesn't tell you if there are too many parameters #987

@penelopeysm

Description

@penelopeysm

For such an important function which is used extensively across DynamicPPL and Turing, there is a surprising lack of safety in that extra parameters in the supplied vector are just silently dropped:

julia> using DynamicPPL, Distributions

julia> @model f() = x ~ Normal()
f (generic function with 2 methods)

julia> v = VarInfo(f())
VarInfo{@NamedTuple{x::DynamicPPL.Metadata{Dict{VarName{:x, typeof(identity)}, Int64}, Vector{Normal{Float64}}, Vector{VarName{:x, typeof(identity)}}, Vector{Float64}}}, Float64}((x = DynamicPPL.Metadata{Dict{VarName{:x, typeof(identity)}, Int64}, Vector{Normal{Float64}}, Vector{VarName{:x, typeof(identity)}}, Vector{Float64}}(Dict(x => 1), [x], UnitRange{Int64}[1:1], [-0.6762290805408931], Normal{Float64}[Normal{Float64}=0.0, σ=1.0)], [0], Dict{String, BitVector}("del" => [0], "trans" => [0])),), Base.RefValue{Float64}(-1.1475814178892636), Base.RefValue{Int64}(0))

julia> DynamicPPL.unflatten(v, [0.0, 1.0, 2.0])
VarInfo{@NamedTuple{x::DynamicPPL.Metadata{Dict{VarName{:x, typeof(identity)}, Int64}, Vector{Normal{Float64}}, Vector{VarName{:x, typeof(identity)}}, Vector{Float64}}}, Float64}((x = DynamicPPL.Metadata{Dict{VarName{:x, typeof(identity)}, Int64}, Vector{Normal{Float64}}, Vector{VarName{:x, typeof(identity)}}, Vector{Float64}}(Dict(x => 1), [x], UnitRange{Int64}[1:1], [0.0], Normal{Float64}[Normal{Float64}=0.0, σ=1.0)], [0], Dict{String, BitVector}("del" => [0], "trans" => [0])),), Base.RefValue{Float64}(-1.1475814178892636), Base.RefValue{Int64}(0))

Metadata

Metadata

Assignees

No one assigned

    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