Skip to content

Commit 48aca59

Browse files
authored
Allow conditioning with tuples with more than one element (#849)
1 parent e331523 commit 48aca59

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

HISTORY.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# DynamicPPL Changelog
22

3+
## 0.35.3
4+
5+
`model | (@varname(x) => 1.0, @varname(y) => 2.0)` now works.
6+
Previously, this would throw a `MethodError` if the tuple had more than one element.
7+
8+
## 0.35.2
9+
10+
`unflatten(::VarInfo, params)` now works with params that have non-float types (such as Int or Bool).
11+
12+
## 0.35.1
13+
14+
`subset(::AbstractVarInfo, ::AbstractVector{<:VarName})` now preserves the ordering of the varnames in the original varinfo argument.
15+
Previously, this would select the varnames according to their order in the second argument.
16+
This fixes an upstream Turing.jl issue with Gibbs sampling when a component sampler was assigned multiple variables.
17+
318
## 0.35.0
419

520
**Breaking changes**

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DynamicPPL"
22
uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8"
3-
version = "0.35.2"
3+
version = "0.35.3"
44

55
[deps]
66
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

src/model.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ AbstractDict (e.g. `model | (x=1, y=2)`), as well as if they are splatted (e.g.
287287
`condition(model, x=1, y=2)`).
288288
"""
289289
_make_conditioning_values(values::Union{NamedTuple,AbstractDict}) = values
290-
_make_conditioning_values(values::Tuple{Pair{<:VarName}}) = Dict(values)
290+
_make_conditioning_values(values::NTuple{N,Pair{<:VarName}}) where {N} = Dict(values)
291291
_make_conditioning_values(v::Pair{<:Symbol}, vs::Pair{<:Symbol}...) = NamedTuple(v, vs...)
292292
_make_conditioning_values(v::Pair{<:VarName}, vs::Pair{<:VarName}...) = Dict(v, vs...)
293293

test/model.jl

+9
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,22 @@ const GDEMO_DEFAULT = DynamicPPL.TestUtils.demo_assume_observe_literal()
117117
conditioned_model = condition(model, (y=2,))
118118
@test keys(VarInfo(conditioned_model)) == [@varname(x)]
119119
end
120+
120121
@testset "conditioning AbstractDict" begin
122+
# condition just 1 variable
121123
expected_values = Dict(@varname(y) => 2)
122124
@test condition(model, Dict(@varname(y) => 2)).context.values == expected_values
123125
@test condition(model, @varname(y) => 2).context.values == expected_values
124126
@test (model | (@varname(y) => 2,)).context.values == expected_values
125127
conditioned_model = condition(model, Dict(@varname(y) => 2))
126128
@test keys(VarInfo(conditioned_model)) == [@varname(x)]
129+
130+
# condition 2 variables
131+
expected_values = Dict(@varname(x) => 1, @varname(y) => 2)
132+
@test condition(model, (@varname(x) => 1, @varname(y) => 2)).context.values ==
133+
expected_values
134+
conditioned_model = condition(model, (@varname(x) => 1, @varname(y) => 2))
135+
@test keys(VarInfo(conditioned_model)) == []
127136
end
128137

129138
@testset "deconditioning" begin

0 commit comments

Comments
 (0)