File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 11module DynamicPPLFastLDFTests
22
33using AbstractPPL: AbstractPPL
4+ using Chairmarks
45using DynamicPPL
56using Distributions
67using DistributionsAD: filldist
7677 end
7778end
7879
80+ @testset " FastLDF: performance" begin
81+ # Evaluating these three models should not lead to any allocations.
82+ @model function f ()
83+ x ~ Normal ()
84+ return 1.0 ~ Normal (x)
85+ end
86+ @model function submodel_inner ()
87+ m ~ Normal (0 , 1 )
88+ s ~ Exponential ()
89+ return (m= m, s= s)
90+ end
91+ # Note that for the allocation tests to work on this one, `inner` has
92+ # to be passed as an argument to `submodel_outer`, instead of just
93+ # being called inside the model function itself
94+ @model function submodel_outer (inner)
95+ params ~ to_submodel (inner)
96+ y ~ Normal (params. m, params. s)
97+ return 1.0 ~ Normal (y)
98+ end
99+ @testset for model in (f (), submodel_inner (), submodel_outer (submodel_inner ()))
100+ vi = VarInfo (model)
101+ fldf = DynamicPPL. Experimental. FastLDF (model, DynamicPPL. getlogjoint_internal, vi)
102+ x = vi[:]
103+ bench = median (@be LogDensityProblems. logdensity (fldf, x))
104+ @test iszero (bench. allocs)
105+ end
106+ end
107+
79108@testset " AD with FastLDF" begin
80109 # Used as the ground truth that others are compared against.
81110 ref_adtype = AutoForwardDiff ()
You can’t perform that action at this time.
0 commit comments