Skip to content

Commit 3bf6b0e

Browse files
committed
Improve Likelihood ctor
1 parent 24a1023 commit 3bf6b0e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/combinators/likelihood.jl

+4-3
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,12 @@ struct Likelihood{K,X} <: AbstractLikelihood
9292
k::K
9393
x::X
9494

95-
Likelihood(k::K, x::X) where {K,X} = new{K,X}(k, x)
96-
#!!!!!!!!!!! # For type stability if `K isa UnionAll (e.g. a parameterized MeasureType)`
97-
Likelihood(::Type{K}, x::X) where {K<:AbstractMeasure,X} = new{K,X}(K, x)
95+
Likelihood{K,X}(k, x) where {K,X} = new{K,X}(k, x)
9896
end
9997

98+
# For type stability, in case k is a type (resp. a constructor):
99+
Likelihood(k, x::X) where {X} = Likelihood{Core.Typeof(k),X}(k, x)
100+
100101
(lik::AbstractLikelihood)(p) = exp(ULogarithmic, logdensityof(lik.k(p), lik.x))
101102

102103
DensityInterface.DensityKind(::AbstractLikelihood) = IsDensity()

0 commit comments

Comments
 (0)