From c3fb38f4ddef2129febf3ad31fdde18c1c776dd0 Mon Sep 17 00:00:00 2001 From: Oliver Schulz Date: Sun, 15 Sep 2024 15:50:57 +0200 Subject: [PATCH] Improve Likelihood ctor --- src/combinators/likelihood.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/combinators/likelihood.jl b/src/combinators/likelihood.jl index 9b6ac567..b244fd0f 100644 --- a/src/combinators/likelihood.jl +++ b/src/combinators/likelihood.jl @@ -92,11 +92,12 @@ struct Likelihood{K,X} <: AbstractLikelihood k::K x::X - Likelihood(k::K, x::X) where {K,X} = new{K,X}(k, x) - #!!!!!!!!!!! # For type stability if `K isa UnionAll (e.g. a parameterized MeasureType)` - Likelihood(::Type{K}, x::X) where {K<:AbstractMeasure,X} = new{K,X}(K, x) + Likelihood{K,X}(k, x) where {K,X} = new{K,X}(k, x) end +# For type stability, in case k is a type (resp. a constructor): +Likelihood(k, x::X) where {X} = Likelihood{Core.Typeof(k),X}(k, x) + (lik::AbstractLikelihood)(p) = exp(ULogarithmic, logdensityof(lik.k(p), lik.x)) DensityInterface.DensityKind(::AbstractLikelihood) = IsDensity()