Skip to content

Commit e2f7d68

Browse files
committed
Tweak test style, add some model evaluation tests
1 parent 4feb182 commit e2f7d68

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

test/utils.jl

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,14 @@ end
6767
@inferred DynamicPPL.from_vec_transform(dist)
6868
@inferred Bijectors.with_logabsdet_jacobian(from_vec_trfm, unlinked_vec)
6969

70-
b = Bijectors.bijector(dist)
71-
@test b(unlinked) isa Any
70+
# Typically the same as `bijector(dist)`, but technically a different
71+
# function
72+
b = DynamicPPL.link_transform(dist)
73+
@test (b(unlinked); true)
7274
linked, logjac = Bijectors.with_logabsdet_jacobian(b, unlinked)
73-
@test linked isa Any
7475
@test logjac isa Real
7576

76-
binv = Bijectors.inverse(b)
77+
binv = DynamicPPL.invlink_transform(dist)
7778
unlinked_again, logjac_inv = Bijectors.with_logabsdet_jacobian(binv, linked)
7879
@test isapprox_nested(unlinked, unlinked_again)
7980
@test isapprox(logjac, -logjac_inv)
@@ -93,6 +94,19 @@ end
9394
from_linked_vec_trfm, linked_vec
9495
)
9596
end
97+
98+
# Create a model and check that we can evaluate it with both unlinked and linked
99+
# VarInfo. This relies on the transformations working correctly so is more of an
100+
# 'end to end' test
101+
@model test() = x ~ dist
102+
model = test()
103+
vi_unlinked = VarInfo(model)
104+
vi_linked = DynamicPPL.link!!(VarInfo(model), model)
105+
@test (DynamicPPL.evaluate!!(model, vi_unlinked); true)
106+
@test (DynamicPPL.evaluate!!(model, vi_linked); true)
107+
model_init = DynamicPPL.setleafcontext(model, DynamicPPL.InitContext())
108+
@test (DynamicPPL.evaluate!!(model_init, vi_unlinked); true)
109+
@test (DynamicPPL.evaluate!!(model_init, vi_linked); true)
96110
end
97111

98112
# Unconstrained univariate

0 commit comments

Comments
 (0)