-
Notifications
You must be signed in to change notification settings - Fork 32
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
Handle nested PrefixContext #787
Conversation
b08c2e2
to
01935af
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #787 +/- ##
==========================================
+ Coverage 86.16% 86.17% +0.01%
==========================================
Files 36 36
Lines 4301 4305 +4
==========================================
+ Hits 3706 3710 +4
Misses 595 595 ☔ View full report in Codecov by Sentry. |
Pull Request Test Coverage Report for Build 12970005900Details
💛 - Coveralls |
function prefix(::PrefixContext{Prefix}, vn::VarName{Sym}) where {Prefix,Sym} | ||
if @generated | ||
return :(VarName{$(QuoteNode(Symbol(Prefix, PREFIX_SEPARATOR, Sym)))}(getoptic(vn))) | ||
else | ||
VarName{Symbol(Prefix, PREFIX_SEPARATOR, Sym)}(getoptic(vn)) | ||
end | ||
# TODO(penelopeysm): Prefixing arguably occurs the wrong way round here | ||
function prefix(ctx::PrefixContext{Prefix}, vn::VarName{Sym}) where {Prefix,Sym} | ||
return prefix( | ||
childcontext(ctx), VarName{Symbol(Prefix, PREFIX_SEPARATOR, Sym)}(getoptic(vn)) | ||
) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
performance
using DynamicPPL, Distributions, Chairmarks
@model function submodel()
x ~ Normal(0, 1)
end
@model function parentmodel()
x1 ~ to_submodel(submodel(), true)
end
m = parentmodel()
@be VarInfo(m)
# Current master
Benchmark: 3827 samples with 2 evaluations
min 10.667 μs (171 allocs: 8.609 KiB)
median 11.042 μs (171 allocs: 8.609 KiB)
mean 12.263 μs (171 allocs: 8.609 KiB, 0.03% gc time)
max 4.467 ms (171 allocs: 8.609 KiB, 98.57% gc time)
# This PR
julia> @be VarInfo(m)
Benchmark: 3749 samples with 2 evaluations
min 11.209 μs (171 allocs: 8.609 KiB)
median 11.729 μs (171 allocs: 8.609 KiB)
mean 12.650 μs (171 allocs: 8.609 KiB, 0.03% gc time)
max 3.150 ms (171 allocs: 8.609 KiB, 98.04% gc time)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lovely; thanks @penelopeysm :)
@sunxd3 Will wait for you if you'd like to review, feel free to pass if you don't have time / don't want to:) |
thanks @penelopeysm, I haven't followed closely with this part of the code, but it looks good to me |
This PR introduces code to better handle
PrefixContext
nested within arbitrary chains of contexts.PrefixContext > AbstractContext > PrefixContext
Correctly handles the case where there are multiple PrefixContexts in a chain that are not contiguous, i.e. point (3) in #786.
(Note, I still think this should return
a.b.x
notb.a.x
(cf point (2) in #786) but I've refrained from changing this behaviour in this PR because it would be a breaking change.)AbstractContext > PrefixContext
Correctly handles the case where
PrefixContext
is not the outermost context, i.e. point (4) in #786.DebugContext > PrefixContext
This also makes sure to prefix variables accordingly inside
check_model_and_trace
.Fixes #785:
ValuesAsInModelContext > PrefixContext
Finally,
values_as_in_model
correctly picks up prefixes now:Fixes #788