@@ -47,7 +47,7 @@ A context used in the implementation of the Turing.jl Gibbs sampler.
4747There will be one `GibbsContext` for each iteration of a component sampler.
4848
4949`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!! `
5151calls to its child context. For other variables, their values will be fixed to
5252the values they have in `global_varinfo`.
5353
@@ -140,7 +140,7 @@ function is_target_varname(context::GibbsContext, vns::AbstractArray{<:VarName})
140140end
141141
142142# Tilde pipeline
143- function DynamicPPL. tilde_assume (context:: GibbsContext , right, vn, vi)
143+ function DynamicPPL. tilde_assume!! (context:: GibbsContext , right, vn, vi)
144144 child_context = DynamicPPL. childcontext (context)
145145
146146 # Note that `child_context` may contain `PrefixContext`s -- in which case
@@ -175,7 +175,7 @@ function DynamicPPL.tilde_assume(context::GibbsContext, right, vn, vi)
175175
176176 return if is_target_varname (context, vn)
177177 # Fall back to the default behavior.
178- DynamicPPL. tilde_assume (child_context, right, vn, vi)
178+ DynamicPPL. tilde_assume!! (child_context, right, vn, vi)
179179 elseif has_conditioned_gibbs (context, vn)
180180 # This branch means that a different sampler is supposed to handle this
181181 # variable. From the perspective of this sampler, this variable is
@@ -191,9 +191,10 @@ function DynamicPPL.tilde_assume(context::GibbsContext, right, vn, vi)
191191 # presumably a new variable that should be sampled from its prior. We need to add
192192 # this new variable to the global `varinfo` of the context, but not to the local one
193193 # 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 ()),
197198 right,
198199 vn,
199200 get_global_varinfo (context),
@@ -204,7 +205,7 @@ function DynamicPPL.tilde_assume(context::GibbsContext, right, vn, vi)
204205end
205206
206207# As above but with an RNG.
207- function DynamicPPL. tilde_assume (
208+ function DynamicPPL. tilde_assume!! (
208209 rng:: Random.AbstractRNG , context:: GibbsContext , sampler, right, vn, vi
209210)
210211 # See comment in the above, rng-less version of this method for an explanation.
@@ -215,7 +216,7 @@ function DynamicPPL.tilde_assume(
215216 # This branch means that that `sampler` is supposed to handle
216217 # this variable. We can thus use its default behaviour, with
217218 # 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)
219220 elseif has_conditioned_gibbs (context, vn)
220221 # This branch means that a different sampler is supposed to handle this
221222 # variable. From the perspective of this sampler, this variable is
@@ -231,10 +232,10 @@ function DynamicPPL.tilde_assume(
231232 # presumably a new variable that should be sampled from its prior. We need to add
232233 # this new variable to the global `varinfo` of the context, but not to the local one
233234 # 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) ),
238239 right,
239240 vn,
240241 get_global_varinfo (context),
0 commit comments