Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/DynamicPPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ export AbstractVarInfo,
@logprob_str,
# Convenience functions
logprior,
logjoint
logjoint,
# Convenience macros
@addlogprob!

# Reexport
using Distributions: loglikelihood
Expand Down
11 changes: 11 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
"""
@addlogprob!(ex)

Add the result of the evaluation of `ex` to the joint log probability.
"""
macro addlogprob!(ex)
return quote
acclogp!($(esc(:(_varinfo))), $(esc(ex)))
end
end

"""
getargs_dottilde(x)

Expand Down
14 changes: 14 additions & 0 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ using DynamicPPL: getargs_dottilde, getargs_tilde

using Test

@testset "addlogprob!" begin
@model function testmodel()
global lp_before = getlogp(_varinfo)
@addlogprob!(42)
global lp_after = getlogp(_varinfo)
end

model = testmodel()
varinfo = DynamicPPL.VarInfo(model)
model(varinfo)
@test iszero(lp_before)
@test getlogp(varinfo) == lp_after == 42
end

@testset "getargs_dottilde" begin
# Some things that are not expressions.
@test getargs_dottilde(:x) === nothing
Expand Down