@@ -57,13 +57,7 @@ function combine(acc::LogProbAccumulator, acc2::LogProbAccumulator)
57
57
return basetypeof (acc)(logp (acc) + logp (acc2))
58
58
end
59
59
60
- function Base.:+ (acc1:: LogProbAccumulator , acc2:: LogProbAccumulator )
61
- if basetypeof (acc1) != = basetypeof (acc2)
62
- msg = " Cannot add accumulators of different types: $(basetypeof (acc1)) and $(basetypeof (acc2)) "
63
- throw (ArgumentError (msg))
64
- end
65
- return basetypeof (acc1)(logp (acc1) + logp (acc2))
66
- end
60
+ acclogp (acc:: LogProbAccumulator , val) = basetypeof (acc)(logp (acc) + val)
67
61
68
62
Base. zero (acc:: T ) where {T<: LogProbAccumulator } = T (zero (logp (acc)))
69
63
@@ -99,7 +93,7 @@ logp(acc::LogPriorAccumulator) = acc.logp
99
93
accumulator_name (:: Type{<:LogPriorAccumulator} ) = :LogPrior
100
94
101
95
function accumulate_assume!! (acc:: LogPriorAccumulator , val, logjac, vn, right)
102
- return acc + LogPriorAccumulator ( logpdf (right, val))
96
+ return acclogp ( acc, logpdf (right, val))
103
97
end
104
98
accumulate_observe!! (acc:: LogPriorAccumulator , right, left, vn) = acc
105
99
@@ -143,7 +137,7 @@ logp(acc::LogJacobianAccumulator) = acc.logJ
143
137
accumulator_name (:: Type{<:LogJacobianAccumulator} ) = :LogJacobian
144
138
145
139
function accumulate_assume!! (acc:: LogJacobianAccumulator , val, logjac, vn, right)
146
- return acc + LogJacobianAccumulator ( logjac)
140
+ return acclogp ( acc, logjac)
147
141
end
148
142
accumulate_observe!! (acc:: LogJacobianAccumulator , right, left, vn) = acc
149
143
@@ -169,7 +163,7 @@ function accumulate_observe!!(acc::LogLikelihoodAccumulator, right, left, vn)
169
163
# Note that it's important to use the loglikelihood function here, not logpdf, because
170
164
# they handle vectors differently:
171
165
# https://github.com/JuliaStats/Distributions.jl/issues/1972
172
- return acc + LogLikelihoodAccumulator ( Distributions. loglikelihood (right, left))
166
+ return acclogp ( acc, Distributions. loglikelihood (right, left))
173
167
end
174
168
175
169
"""
208
202
209
203
function Base. show (io:: IO , acc:: VariableOrderAccumulator )
210
204
return print (
211
- io, " VariableOrderAccumulator($(repr (acc. num_produce)) , $(repr (acc. order)) )"
205
+ io, " VariableOrderAccumulator($(string (acc. num_produce)) , $(repr (acc. order)) )"
212
206
)
213
207
end
214
208
0 commit comments