File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -770,4 +770,43 @@ DynamicPPL.getspace(::DynamicPPL.Sampler{MySAlg}) = (:s,)
770770 @test any (! Base. Fix1 (DynamicPPL. istrans, varinfo_linked), vns_m)
771771 end
772772 end
773+
774+ @testset " sampling from linked varinfo" begin
775+ # `~`
776+ @model function demo (n= 1 )
777+ x = Vector (undef, n)
778+ for i in eachindex (x)
779+ x[i] ~ Exponential ()
780+ end
781+ return x
782+ end
783+ model1 = demo (1 )
784+ varinfo1 = DynamicPPL. link!! (VarInfo (model1), model1)
785+ # Sampling from `model2` should hit the `istrans(vi) == true` branches
786+ # because all the existing variables are linked.
787+ model2 = demo (2 )
788+ varinfo2 = last (DynamicPPL. evaluate!! (model2, deepcopy (varinfo1), SamplingContext ()))
789+ for vn in [@varname (x[1 ]), @varname (x[2 ])]
790+ @test DynamicPPL. istrans (varinfo2, vn)
791+ end
792+
793+ # `.~`
794+ @model function demo_dot (n= 1 )
795+ x ~ Exponential ()
796+ if n > 1
797+ y = Vector (undef, n - 1 )
798+ y .~ Exponential ()
799+ end
800+ return x
801+ end
802+ model1 = demo_dot (1 )
803+ varinfo1 = DynamicPPL. link!! (DynamicPPL. untyped_varinfo (model1), model1)
804+ # Sampling from `model2` should hit the `istrans(vi) == true` branches
805+ # because all the existing variables are linked.
806+ model2 = demo_dot (2 )
807+ varinfo2 = last (DynamicPPL. evaluate!! (model2, deepcopy (varinfo1), SamplingContext ()))
808+ for vn in [@varname (x), @varname (y[1 ])]
809+ @test DynamicPPL. istrans (varinfo2, vn)
810+ end
811+ end
773812end
You can’t perform that action at this time.
0 commit comments