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
15 changes: 15 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# DynamicPPL Changelog

## 0.35.3

`model | (@varname(x) => 1.0, @varname(y) => 2.0)` now works.
Previously, this would throw a `MethodError` if the tuple had more than one element.

## 0.35.2

`unflatten(::VarInfo, params)` now works with params that have non-float types (such as Int or Bool).

## 0.35.1

`subset(::AbstractVarInfo, ::AbstractVector{<:VarName})` now preserves the ordering of the varnames in the original varinfo argument.
Previously, this would select the varnames according to their order in the second argument.
This fixes an upstream Turing.jl issue with Gibbs sampling when a component sampler was assigned multiple variables.

## 0.35.0

**Breaking changes**
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.35.2"
version = "0.35.3"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
2 changes: 1 addition & 1 deletion src/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ AbstractDict (e.g. `model | (x=1, y=2)`), as well as if they are splatted (e.g.
`condition(model, x=1, y=2)`).
"""
_make_conditioning_values(values::Union{NamedTuple,AbstractDict}) = values
_make_conditioning_values(values::Tuple{Pair{<:VarName}}) = Dict(values)
_make_conditioning_values(values::NTuple{N,Pair{<:VarName}}) where {N} = Dict(values)
_make_conditioning_values(v::Pair{<:Symbol}, vs::Pair{<:Symbol}...) = NamedTuple(v, vs...)
_make_conditioning_values(v::Pair{<:VarName}, vs::Pair{<:VarName}...) = Dict(v, vs...)

Expand Down
9 changes: 9 additions & 0 deletions test/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,22 @@ const GDEMO_DEFAULT = DynamicPPL.TestUtils.demo_assume_observe_literal()
conditioned_model = condition(model, (y=2,))
@test keys(VarInfo(conditioned_model)) == [@varname(x)]
end

@testset "conditioning AbstractDict" begin
# condition just 1 variable
expected_values = Dict(@varname(y) => 2)
@test condition(model, Dict(@varname(y) => 2)).context.values == expected_values
@test condition(model, @varname(y) => 2).context.values == expected_values
@test (model | (@varname(y) => 2,)).context.values == expected_values
conditioned_model = condition(model, Dict(@varname(y) => 2))
@test keys(VarInfo(conditioned_model)) == [@varname(x)]

# condition 2 variables
expected_values = Dict(@varname(x) => 1, @varname(y) => 2)
@test condition(model, (@varname(x) => 1, @varname(y) => 2)).context.values ==
expected_values
conditioned_model = condition(model, (@varname(x) => 1, @varname(y) => 2))
@test keys(VarInfo(conditioned_model)) == []
end

@testset "deconditioning" begin
Expand Down
Loading