Skip to content

Commit 39a0756

Browse files
committed
Make logp concretely typed by default and respect types in resetlogp!
1 parent 26d90d7 commit 39a0756

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/varinfo.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ end
485485

486486
# VarInfo
487487

488-
VarInfo(meta=Metadata()) = VarInfo(meta, Ref{Real}(0.0), Ref(0))
488+
VarInfo(meta=Metadata()) = VarInfo(meta, Ref{Float64}(0.0), Ref(0))
489489

490490
"""
491491
TypedVarInfo(vi::UntypedVarInfo)
@@ -618,8 +618,7 @@ acclogp!(vi::AbstractVarInfo, logp::Real) = vi.logp[] += logp
618618
Reset the value of the log of the joint probability of the observed data and parameters
619619
sampled in `vi` to 0.
620620
"""
621-
resetlogp!(vi::AbstractVarInfo) = setlogp!(vi, 0)
622-
621+
resetlogp!(vi::AbstractVarInfo) = setlogp!(vi, zero(getlogp(vi)))
623622

624623
"""
625624
get_num_produce(vi::VarInfo)

test/varinfo.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,13 @@ include(dir*"/test/test_utils/AllUtils.jl")
391391
@testset "varinfo" begin
392392
dists = [Normal(0, 1), MvNormal([0; 0], [1.0 0; 0 1.0]), Wishart(7, [1 0.5; 0.5 1])]
393393
function test_varinfo!(vi)
394-
@test getlogp(vi) == 0
394+
@test getlogp(vi) === 0.0
395395
setlogp!(vi, 1)
396-
@test getlogp(vi) == 1
396+
@test getlogp(vi) === 1.0
397397
acclogp!(vi, 1)
398-
@test getlogp(vi) == 2
398+
@test getlogp(vi) === 2.0
399399
resetlogp!(vi)
400-
@test getlogp(vi) == 0
400+
@test getlogp(vi) === 0.0
401401

402402
spl2 = Sampler(PG(5, :w, :u), empty_model())
403403
vn_w = @varname w

0 commit comments

Comments
 (0)