@@ -502,7 +502,7 @@ function conditioned(context::ConditionContext)
502
502
# precedence over decendants of `context`.
503
503
return _merge (context. values, conditioned (childcontext (context)))
504
504
end
505
- function conditioned (context:: PrefixContext{Prefix} ) where {Prefix}
505
+ function conditioned (context:: PrefixContext )
506
506
return conditioned (collapse_prefix_stack (context))
507
507
end
508
508
@@ -681,6 +681,9 @@ function fixed(context::FixedContext)
681
681
# precedence over decendants of `context`.
682
682
return _merge (context. values, fixed (childcontext (context)))
683
683
end
684
+ function fixed (context:: PrefixContext )
685
+ return fixed (collapse_prefix_stack (context))
686
+ end
684
687
685
688
"""
686
689
collapse_prefix_stack(context::AbstractContext)
@@ -691,7 +694,16 @@ the `PrefixContext`s from the context stack.
691
694
```jldoctest
692
695
julia> using DynamicPPL: collapse_prefix_stack
693
696
694
- julia> c1 = PrefixContext({:a}(ConditionContext((x=1, )))
697
+ julia> c1 = PrefixContext{:a}(ConditionContext((x=1, )));
698
+
699
+ julia> collapse_prefix_stack(c1)
700
+ ConditionContext(Dict(a.x => 1), DefaultContext())
701
+
702
+ julia> # Here, `x` gets prefixed only with `a`, whereas `y` is prefixed with both.
703
+ c2 = PrefixContext{:a}(ConditionContext((x=1, ), PrefixContext{:b}(ConditionContext((y=2,)))));
704
+
705
+ julia> collapse_prefix_stack(c2)
706
+ ConditionContext(Dict{VarName{:a}, Int64}(a.b.y => 2, a.x => 1), DefaultContext())
695
707
```
696
708
"""
697
709
function collapse_prefix_stack (context:: PrefixContext{Prefix} ) where {Prefix}
@@ -703,7 +715,14 @@ function collapse_prefix_stack(context::PrefixContext{Prefix}) where {Prefix}
703
715
# depth of the context stack.
704
716
return prefix_cond_and_fixed_variables (collapsed, VarName {Prefix} ())
705
717
end
706
- collapse_prefix_stack (context:: AbstractContext ) = context
718
+ function collapse_prefix_stack (context:: AbstractContext )
719
+ return collapse_prefix_stack (NodeTrait (collapse_prefix_stack, context), context)
720
+ end
721
+ collapse_prefix_stack (:: IsLeaf , context) = context
722
+ function collapse_prefix_stack (:: IsParent , context)
723
+ new_child_context = collapse_prefix_stack (childcontext (context))
724
+ return setchildcontext (context, new_child_context)
725
+ end
707
726
708
727
"""
709
728
prefix_cond_and_fixed_variables(context::AbstractContext, prefix::VarName)
0 commit comments