Skip to content

WrappedContext post introduction of SamplingContext #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/DynamicPPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export AbstractVarInfo,
SampleFromUniform,
# Contexts
SamplingContext,
DefaultContext,
EvaluationContext,
LikelihoodContext,
PriorContext,
MiniBatchContext,
Expand Down
8 changes: 8 additions & 0 deletions src/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,15 @@ function build_output(modelinfo, linenumbernode)
evaluatordef[:kwargs] = []

# Replace the user-provided function body with the version created by DynamicPPL.
@gensym leafctx
evaluatordef[:body] = quote
# in case someone accessed these
$leafctx = DynamicPPL.unwrap(__context__)
if $leafctx isa $(DynamicPPL.SamplingContext)
__rng__ = $leafctx.rng
__sampler__ = $leafctx.sampler
end

$(modelinfo[:body])
end

Expand Down
Loading