-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #463 from probcomp/mrb/kernel_dsl_arg_fix
(Kernel DSL) Revert esc change toplevel, include GlobalRef to handle evaluation ambiguity in modules/submodules.
- Loading branch information
Showing
3 changed files
with
85 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
@gen function kernel_dsl_test_model() | ||
x ~ normal(0.0, 1.0) | ||
y ~ normal(x, 1.0) | ||
return y | ||
end | ||
|
||
@pkern function k1(tr, t) | ||
metadata = false | ||
for _ in 1 : t | ||
tr, acc = mh(tr, select(:x)) | ||
if acc | ||
metadata = true | ||
end | ||
end | ||
return tr, metadata | ||
end | ||
|
||
@gen function k1_proposal(tr) | ||
x ~ normal(0.0, 1.0) | ||
end | ||
|
||
@kern function k1_non_primitive(tr, t) | ||
for _ in 1 : t | ||
tr ~ mh(tr, k1_proposal, ()) | ||
end | ||
end | ||
|
||
@testset "Kernel DSL" begin | ||
tr = simulate(kernel_dsl_test_model, ()) | ||
original = get_choices(tr)[:x] | ||
tr, acc = k1(tr, 1) | ||
if acc | ||
@test original != get_choices(tr)[:x] | ||
else | ||
@test original == get_choices(tr)[:x] | ||
end | ||
original = get_choices(tr)[:x] | ||
tr, acc = k1_non_primitive(tr, 1) | ||
tr, acc = Gen.reversal(k1_non_primitive)(tr, 1) | ||
end |