Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# DynamicPPL Changelog

## 0.36.9

Fixed a failure when sampling from `ProductNamedTupleDistribution` due to
missing `tovec` methods for `NamedTuple` and `Tuple`.

## 0.36.8

Made `LogDensityFunction` a subtype of `AbstractMCMC.AbstractModel`.
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DynamicPPL"
uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8"
version = "0.36.8"
version = "0.36.9"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
2 changes: 2 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ to_linked_vec_transform(x) = inverse(from_linked_vec_transform(x))
# or fix `tovec` to flatten the full matrix instead of using `Bijectors.triu_to_vec`.
tovec(x::Real) = [x]
tovec(x::AbstractArray) = vec(x)
tovec(t::Tuple) = mapreduce(tovec, vcat, t)
tovec(nt::NamedTuple) = mapreduce(tovec, vcat, values(nt))
tovec(C::Cholesky) = tovec(Matrix(C.UL))

"""
Expand Down
11 changes: 11 additions & 0 deletions test/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -617,4 +617,15 @@ const GDEMO_DEFAULT = DynamicPPL.TestUtils.demo_assume_observe_literal()
]) ≈ 1.0 * xs_test[2] rtol = 0.1
end
end

@testset "ProductNamedTupleDistribution sampling" begin
priors = (a=Normal(), b=Normal())
d = product_distribution(priors)
@model function sample_nt(priors_dist)
x ~ priors_dist
return x
end
model = sample_nt(d)
@test model() isa NamedTuple
end
end
6 changes: 6 additions & 0 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
dist = LKJCholesky(2, 1)
x = rand(dist)
@test DynamicPPL.tovec(x) == vec(x.UL)

nt = (a=[1, 2], b=3.0)
@test DynamicPPL.tovec(nt) == [1, 2, 3.0]

t = (2.0, [3.0, 4.0])
@test DynamicPPL.tovec(t) == [2.0, 3.0, 4.0]
end

@testset "unique_syms" begin
Expand Down
Loading