Skip to content

tovec causing an error when sampling a Product named tuple distribution #933

@SamuelBrand1

Description

@SamuelBrand1

Following on from helpful chat in #929 I've found a bug in DPPL/Turing sampling from ProductNamedTupleDistribution around tovec being used down the stack.

Here is a reprex:

julia> using Distributions, Turing

julia> priors = (a = Normal(), b = Normal());

julia> priors_dist = product_distribution(priors)
# ProductNamedTupleDistribution{(:a, :b)}(
# a: Normal{Float64}(μ=0.0, σ=1.0)
# b: Normal{Float64}(μ=0.0, σ=1.0)
# )


julia> @model function sample_nt(priors_dist)
       x ~ priors_dist
       
       return x
       end
# sample_nt (generic function with 2 methods)

julia> mdl = sample_nt(priors_dist);

julia> mdl()

ERROR: MethodError: no method matching tovec(::@NamedTuple{a::Float64, b::Float64})
The function tovec exists, but no method is defined for this combination of argument types.

Closest candidates are:
tovec(::LinearAlgebra.Cholesky)
@ DynamicPPL ~/.julia/packages/DynamicPPL/vlXDM/src/utils.jl:446
tovec(::AbstractArray)
@ DynamicPPL ~/.julia/packages/DynamicPPL/vlXDM/src/utils.jl:445
tovec(::Real)
@ DynamicPPL ~/.julia/packages/DynamicPPL/vlXDM/src/utils.jl:444

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