Skip to content

Commit b3b9df6

Browse files
committed
Fix loading order of modules; move prefix(::Model) to model.jl
1 parent 57bf292 commit b3b9df6

File tree

3 files changed

+37
-37
lines changed

3 files changed

+37
-37
lines changed

src/DynamicPPL.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,12 @@ abstract type AbstractVarInfo <: AbstractModelTrace end
170170
# Necessary forward declarations
171171
include("utils.jl")
172172
include("chains.jl")
173+
include("contexts.jl")
174+
include("contexts/init.jl")
173175
include("model.jl")
174176
include("sampler.jl")
175177
include("varname.jl")
176178
include("distribution_wrappers.jl")
177-
include("contexts.jl")
178-
include("contexts/init.jl")
179179
include("submodel.jl")
180180
include("varnamedvector.jl")
181181
include("accumulators.jl")

src/contexts.jl

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -280,41 +280,6 @@ function prefix_and_strip_contexts(::IsParent, ctx::AbstractContext, vn::VarName
280280
return vn, setchildcontext(ctx, new_ctx)
281281
end
282282

283-
"""
284-
prefix(model::Model, x::VarName)
285-
prefix(model::Model, x::Val{sym})
286-
prefix(model::Model, x::Any)
287-
288-
Return `model` but with all random variables prefixed by `x`, where `x` is either:
289-
- a `VarName` (e.g. `@varname(a)`),
290-
- a `Val{sym}` (e.g. `Val(:a)`), or
291-
- for any other type, `x` is converted to a Symbol and then to a `VarName`. Note that
292-
this will introduce runtime overheads so is not recommended unless absolutely
293-
necessary.
294-
295-
# Examples
296-
297-
```jldoctest
298-
julia> using DynamicPPL: prefix
299-
300-
julia> @model demo() = x ~ Dirac(1)
301-
demo (generic function with 2 methods)
302-
303-
julia> rand(prefix(demo(), @varname(my_prefix)))
304-
(var"my_prefix.x" = 1,)
305-
306-
julia> rand(prefix(demo(), Val(:my_prefix)))
307-
(var"my_prefix.x" = 1,)
308-
```
309-
"""
310-
prefix(model::Model, x::VarName) = contextualize(model, PrefixContext(x, model.context))
311-
function prefix(model::Model, x::Val{sym}) where {sym}
312-
return contextualize(model, PrefixContext(VarName{sym}(), model.context))
313-
end
314-
function prefix(model::Model, x)
315-
return contextualize(model, PrefixContext(VarName{Symbol(x)}(), model.context))
316-
end
317-
318283
"""
319284
320285
ConditionContext{Values<:Union{NamedTuple,AbstractDict},Ctx<:AbstractContext}

src/model.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,41 @@ julia> # Now `a.x` will be sampled.
799799
"""
800800
fixed(model::Model) = fixed(model.context)
801801

802+
"""
803+
prefix(model::Model, x::VarName)
804+
prefix(model::Model, x::Val{sym})
805+
prefix(model::Model, x::Any)
806+
807+
Return `model` but with all random variables prefixed by `x`, where `x` is either:
808+
- a `VarName` (e.g. `@varname(a)`),
809+
- a `Val{sym}` (e.g. `Val(:a)`), or
810+
- for any other type, `x` is converted to a Symbol and then to a `VarName`. Note that
811+
this will introduce runtime overheads so is not recommended unless absolutely
812+
necessary.
813+
814+
# Examples
815+
816+
```jldoctest
817+
julia> using DynamicPPL: prefix
818+
819+
julia> @model demo() = x ~ Dirac(1)
820+
demo (generic function with 2 methods)
821+
822+
julia> rand(prefix(demo(), @varname(my_prefix)))
823+
(var"my_prefix.x" = 1,)
824+
825+
julia> rand(prefix(demo(), Val(:my_prefix)))
826+
(var"my_prefix.x" = 1,)
827+
```
828+
"""
829+
prefix(model::Model, x::VarName) = contextualize(model, PrefixContext(x, model.context))
830+
function prefix(model::Model, x::Val{sym}) where {sym}
831+
return contextualize(model, PrefixContext(VarName{sym}(), model.context))
832+
end
833+
function prefix(model::Model, x)
834+
return contextualize(model, PrefixContext(VarName{Symbol(x)}(), model.context))
835+
end
836+
802837
"""
803838
(model::Model)([rng, varinfo])
804839

0 commit comments

Comments
 (0)