Skip to content

Commit e1c8fd1

Browse files
formatting
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent e5b7e44 commit e1c8fd1

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

src/context_implementations.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@ function dot_tilde_assume(context::PrefixContext, right, left, vn, vi)
304304
return dot_tilde_assume(context.context, right, left, prefix.(Ref(context), vn), vi)
305305
end
306306

307-
function dot_tilde_assume(rng::Random.AbstractRNG, context::PrefixContext, sampler, right, left, vn, vi)
307+
function dot_tilde_assume(
308+
rng::Random.AbstractRNG, context::PrefixContext, sampler, right, left, vn, vi
309+
)
308310
return dot_tilde_assume(
309311
rng, context.context, sampler, right, left, prefix.(Ref(context), vn), vi
310312
)

src/distribution_wrappers.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ Base.size(dist::NoDist) = Base.size(dist.dist)
4343

4444
Distributions.rand(rng::Random.AbstractRNG, d::NoDist) = rand(rng, d.dist)
4545
# NOTE(torfjelde): Need this to avoid stack overflow.
46-
function Distributions.rand!(rng::Random.AbstractRNG, d::NoDist{Distributions.ArrayLikeVariate{N}}, x::AbstractArray{<:Real, N}) where {N}
46+
function Distributions.rand!(
47+
rng::Random.AbstractRNG,
48+
d::NoDist{Distributions.ArrayLikeVariate{N}},
49+
x::AbstractArray{<:Real,N},
50+
) where {N}
4751
return Distributions.rand!(rng, d.dist, x)
4852
end
4953
Distributions.logpdf(d::NoDist{<:Univariate}, ::Real) = 0

src/test_utils.jl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,9 @@ TestParentContext() = TestParentContext(DefaultContext())
10881088
DynamicPPL.NodeTrait(::TestParentContext) = DynamicPPL.IsParent()
10891089
DynamicPPL.childcontext(context::TestParentContext) = context.context
10901090
DynamicPPL.setchildcontext(::TestParentContext, child) = TestParentContext(child)
1091-
Base.show(io::IO, c::TestParentContext) = print(io, "TestParentContext(", DynamicPPL.childcontext(c), ")")
1091+
function Base.show(io::IO, c::TestParentContext)
1092+
return print(io, "TestParentContext(", DynamicPPL.childcontext(c), ")")
1093+
end
10921094

10931095
"""
10941096
test_context(context::AbstractContext, model::Model)
@@ -1103,19 +1105,27 @@ function test_context(context::DynamicPPL.AbstractContext, model::DynamicPPL.Mod
11031105
# `NodeTrait`.
11041106
node_trait = DynamicPPL.NodeTrait(context)
11051107
# Throw error immediately if it it's missing a `NodeTrait` implementation.
1106-
node_trait isa Union{DynamicPPL.IsLeaf, DynamicPPL.IsParent} || throw(ValueError("Invalid NodeTrait: $node_trait"))
1108+
node_trait isa Union{DynamicPPL.IsLeaf,DynamicPPL.IsParent} ||
1109+
throw(ValueError("Invalid NodeTrait: $node_trait"))
11071110

11081111
# The interface methods.
11091112
if node_trait isa DynamicPPL.IsParent
11101113
# `childcontext` and `setchildcontext`
11111114
# With new child context
11121115
childcontext_new = TestParentContext()
1113-
@test DynamicPPL.childcontext(DynamicPPL.setchildcontext(context, childcontext_new)) == childcontext_new
1116+
@test DynamicPPL.childcontext(
1117+
DynamicPPL.setchildcontext(context, childcontext_new)
1118+
) == childcontext_new
11141119
end
11151120

11161121
# To see change, let's make sure we're using a different leaf context than the current.
1117-
leafcontext_new = DynamicPPL.leafcontext(context) isa DefaultContext ? PriorContext() : DefaultContext()
1118-
@test DynamicPPL.leafcontext(DynamicPPL.setleafcontext(context, leafcontext_new)) == leafcontext_new
1122+
leafcontext_new = if DynamicPPL.leafcontext(context) isa DefaultContext
1123+
PriorContext()
1124+
else
1125+
DefaultContext()
1126+
end
1127+
@test DynamicPPL.leafcontext(DynamicPPL.setleafcontext(context, leafcontext_new)) ==
1128+
leafcontext_new
11191129

11201130
# Make sure that the we can evaluate the model with the context (i.e. that none of the tilde-functions are incorrectly overloaded).
11211131
# The tilde-pipeline contains two different paths: with `SamplingContext` as a parent, and without it.

test/contexts.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ end
5959
PrefixContext{:x}(DefaultContext()),
6060
PointwiseLogdensityContext(),
6161
ConditionContext((x=1.0,)),
62-
ConditionContext((x=1.0,), DynamicPPL.TestUtils.TestParentContext(ConditionContext((y=2.0,)))),
62+
ConditionContext(
63+
(x=1.0,), DynamicPPL.TestUtils.TestParentContext(ConditionContext((y=2.0,)))
64+
),
6365
ConditionContext((x=1.0,), PrefixContext{:a}(ConditionContext((var"a.y"=2.0,)))),
6466
ConditionContext((x=[1.0, missing],)),
6567
]
@@ -169,7 +171,8 @@ end
169171

170172
# Extract the ground truth symbols.
171173
vns_syms = Set([
172-
Symbol("prefix", DynamicPPL.PREFIX_SEPARATOR, DynamicPPL.getsym(vn)) for vn in DynamicPPL.TestUtils.varnames(model)
174+
Symbol("prefix", DynamicPPL.PREFIX_SEPARATOR, DynamicPPL.getsym(vn)) for
175+
vn in DynamicPPL.TestUtils.varnames(model)
173176
])
174177

175178
# Check that all variables are prefixed correctly.

0 commit comments

Comments
 (0)