@@ -47,7 +47,7 @@ A context used in the implementation of the Turing.jl Gibbs sampler.
47
47
There will be one `GibbsContext` for each iteration of a component sampler.
48
48
49
49
`target_varnames` is a a tuple of `VarName`s that the current component sampler
50
- is sampling. For those `VarName`s, `GibbsContext` will just pass `tilde_assume`
50
+ is sampling. For those `VarName`s, `GibbsContext` will just pass `tilde_assume!! `
51
51
calls to its child context. For other variables, their values will be fixed to
52
52
the values they have in `global_varinfo`.
53
53
@@ -140,7 +140,7 @@ function is_target_varname(context::GibbsContext, vns::AbstractArray{<:VarName})
140
140
end
141
141
142
142
# Tilde pipeline
143
- function DynamicPPL. tilde_assume (context:: GibbsContext , right, vn, vi)
143
+ function DynamicPPL. tilde_assume!! (context:: GibbsContext , right, vn, vi)
144
144
child_context = DynamicPPL. childcontext (context)
145
145
146
146
# Note that `child_context` may contain `PrefixContext`s -- in which case
@@ -175,7 +175,7 @@ function DynamicPPL.tilde_assume(context::GibbsContext, right, vn, vi)
175
175
176
176
return if is_target_varname (context, vn)
177
177
# Fall back to the default behavior.
178
- DynamicPPL. tilde_assume (child_context, right, vn, vi)
178
+ DynamicPPL. tilde_assume!! (child_context, right, vn, vi)
179
179
elseif has_conditioned_gibbs (context, vn)
180
180
# This branch means that a different sampler is supposed to handle this
181
181
# variable. From the perspective of this sampler, this variable is
@@ -191,9 +191,10 @@ function DynamicPPL.tilde_assume(context::GibbsContext, right, vn, vi)
191
191
# presumably a new variable that should be sampled from its prior. We need to add
192
192
# this new variable to the global `varinfo` of the context, but not to the local one
193
193
# being used by the current sampler.
194
- value, new_global_vi = DynamicPPL. tilde_assume (
195
- child_context,
196
- DynamicPPL. SampleFromPrior (),
194
+ value, new_global_vi = DynamicPPL. tilde_assume!! (
195
+ # child_context might be a PrefixContext so we have to be careful to not
196
+ # overwrite it.
197
+ DynamicPPL. setleafcontext (child_context, DynamicPPL. InitContext ()),
197
198
right,
198
199
vn,
199
200
get_global_varinfo (context),
@@ -204,7 +205,7 @@ function DynamicPPL.tilde_assume(context::GibbsContext, right, vn, vi)
204
205
end
205
206
206
207
# As above but with an RNG.
207
- function DynamicPPL. tilde_assume (
208
+ function DynamicPPL. tilde_assume!! (
208
209
rng:: Random.AbstractRNG , context:: GibbsContext , sampler, right, vn, vi
209
210
)
210
211
# See comment in the above, rng-less version of this method for an explanation.
@@ -215,7 +216,7 @@ function DynamicPPL.tilde_assume(
215
216
# This branch means that that `sampler` is supposed to handle
216
217
# this variable. We can thus use its default behaviour, with
217
218
# the 'local' sampler-specific VarInfo.
218
- DynamicPPL. tilde_assume (rng, child_context, sampler, right, vn, vi)
219
+ DynamicPPL. tilde_assume!! (rng, child_context, sampler, right, vn, vi)
219
220
elseif has_conditioned_gibbs (context, vn)
220
221
# This branch means that a different sampler is supposed to handle this
221
222
# variable. From the perspective of this sampler, this variable is
@@ -231,10 +232,10 @@ function DynamicPPL.tilde_assume(
231
232
# presumably a new variable that should be sampled from its prior. We need to add
232
233
# this new variable to the global `varinfo` of the context, but not to the local one
233
234
# being used by the current sampler.
234
- value, new_global_vi = DynamicPPL. tilde_assume (
235
- rng,
236
- child_context,
237
- DynamicPPL. SampleFromPrior ( ),
235
+ value, new_global_vi = DynamicPPL. tilde_assume!! (
236
+ # child_context might be a PrefixContext so we have to be careful to not
237
+ # overwrite it.
238
+ DynamicPPL. setleafcontext (child_context, DynamicPPL . InitContext (rng) ),
238
239
right,
239
240
vn,
240
241
get_global_varinfo (context),
0 commit comments