Skip to content

Commit dea62bb

Browse files
committed
Add a test for values_as_in_model(rng, model, ...)
1 parent edbfe3a commit dea62bb

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/model.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,22 @@ const GDEMO_DEFAULT = DynamicPPL.TestUtils.demo_assume_observe_literal()
396396
end
397397
end
398398
end
399+
400+
@testset "check that sampling obeys rng if passed" begin
401+
@model function f()
402+
x ~ Normal(0)
403+
return y ~ Normal(x)
404+
end
405+
model = f()
406+
# Call values_as_in_model with the rng
407+
values = values_as_in_model(Random.Xoshiro(43), model, false)
408+
# Check that they match the values that would be used if vi was seeded
409+
# with that seed instead
410+
expected_vi = VarInfo(Random.Xoshiro(43), model)
411+
for vn in keys(values)
412+
@test values[vn] == expected_vi[vn]
413+
end
414+
end
399415
end
400416

401417
@testset "Erroneous model call" begin

0 commit comments

Comments
 (0)