Skip to content

Commit c14a63e

Browse files
committed
Fixed bug which made it so prefix was never using @generated (#256)
Does what the title says!
1 parent 472dfe7 commit c14a63e

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DynamicPPL"
22
uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8"
3-
version = "0.11.0"
3+
version = "0.11.1"
44

55
[deps]
66
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"

src/context_implementations.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,7 @@ function dot_assume(
236236
@assert length(dist) == size(var, 1)
237237
r = get_and_set_val!(rng, vi, vns, dist, spl)
238238
lp = sum(Bijectors.logpdf_with_trans(dist, r, istrans(vi, vns[1])))
239-
var .= r
240-
return var, lp
239+
return r, lp
241240
end
242241
function dot_assume(
243242
rng,
@@ -250,8 +249,7 @@ function dot_assume(
250249
r = get_and_set_val!(rng, vi, vns, dists, spl)
251250
# Make sure `r` is not a matrix for multivariate distributions
252251
lp = sum(Bijectors.logpdf_with_trans.(dists, r, istrans(vi, vns[1])))
253-
var .= r
254-
return var, lp
252+
return r, lp
255253
end
256254
function dot_assume(rng, spl::Sampler, ::Any, ::AbstractArray{<:VarName}, ::Any, ::Any)
257255
return error(

src/contexts.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function PrefixContext{PrefixInner}(
6666
ctx::PrefixContext{PrefixOuter}
6767
) where {PrefixInner,PrefixOuter}
6868
if @generated
69-
:(PrefixContext{$(QuoteNode(Symbol(PrefixOuter, _prefix_seperator, PrefixInner)))}(
69+
:(PrefixContext{$(QuoteNode(Symbol(PrefixOuter, PREFIX_SEPARATOR, PrefixInner)))}(
7070
ctx.ctx
7171
))
7272
else
@@ -76,7 +76,7 @@ end
7676

7777
function prefix(::PrefixContext{Prefix}, vn::VarName{Sym}) where {Prefix,Sym}
7878
if @generated
79-
return :(VarName{$(QuoteNode(Symbol(Prefix, _prefix_seperator, Sym)))}(vn.indexing))
79+
return :(VarName{$(QuoteNode(Symbol(Prefix, PREFIX_SEPARATOR, Sym)))}(vn.indexing))
8080
else
8181
VarName{Symbol(Prefix, PREFIX_SEPARATOR, Sym)}(vn.indexing)
8282
end

test/contexts.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@testset "contexts.jl" begin
2+
@testset "PrefixContext" begin
3+
ctx = @inferred PrefixContext{:f}(
4+
PrefixContext{:e}(
5+
PrefixContext{:d}(
6+
PrefixContext{:c}(
7+
PrefixContext{:b}(PrefixContext{:a}(DefaultContext()))
8+
),
9+
),
10+
),
11+
)
12+
vn = VarName{:x}()
13+
vn_prefixed = @inferred DynamicPPL.prefix(ctx, vn)
14+
@test DynamicPPL.getsym(vn_prefixed) == Symbol("a.b.c.d.e.f.x")
15+
@test vn_prefixed.indexing === vn.indexing
16+
17+
vn = VarName{:x}((1,))
18+
vn_prefixed = @inferred DynamicPPL.prefix(ctx, vn)
19+
@test DynamicPPL.getsym(vn_prefixed) == Symbol("a.b.c.d.e.f.x")
20+
@test vn_prefixed.indexing === vn.indexing
21+
end
22+
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ include("test_util.jl")
3939
include("prob_macro.jl")
4040
include("independence.jl")
4141
include("distribution_wrappers.jl")
42+
include("contexts.jl")
4243
include("context_implementations.jl")
4344

4445
include("threadsafe.jl")

0 commit comments

Comments
 (0)