@@ -26,11 +26,15 @@ To compute log-density relative to `basemeasure(m)` or *define* a log-density
2626`logdensity_def`.
2727
2828To compute a log-density relative to a specific base-measure, see
29- `logdensity_rel`.
29+ `logdensity_rel`.
30+
31+ # Implementation
32+
33+ Do not specialize `logdensityof` directly for subtypes of `AbstractMeasure`,
34+ specialize `MeasureBase.logdensity_def` and `MeasureBase.strict_logdensityof` instead.
3035"""
31- @inline function logdensityof (μ:: AbstractMeasure , x)
32- result = dynamic (unsafe_logdensityof (μ, x))
33- _checksupport (insupport (μ, x), result)
36+ @inline function logdensityof (μ:: AbstractMeasure , x) # !!!!!!!!!!!!!!!!!
37+ strict_logdensityof (μ, x)
3438end
3539
3640@inline function logdensityof_rt (:: T , :: U ) where {T,U}
@@ -41,6 +45,24 @@ _checksupport(cond, result) = ifelse(cond == true, result, oftype(result, -Inf))
4145
4246export unsafe_logdensityof
4347
48+ """
49+ MeasureBase.strict_logdensityof(μ, x)
50+
51+ Compute the log-density of the measure `μ` at `x` relative to `rootmeasure(m)`.
52+ In contrast to [`logdensityof(μ, x)`](@ref), this will not take implicit pushforwards
53+ of `μ` (depending on the type of `x`) into account.
54+ """
55+ function strict_logdensityof end
56+
57+ @inline function strict_logdensityof (μ, x)
58+ result = dynamic (unsafe_logdensityof (μ, x))
59+ _checksupport (insupport (μ, x), result)
60+ end
61+
62+ @inline function strict_logdensityof_rt (:: T , :: U ) where {T,U}
63+ Core. Compiler. return_type (strict_logdensityof, Tuple{T,U})
64+ end
65+
4466# https://discourse.julialang.org/t/counting-iterations-to-a-type-fixpoint/75876/10?u=cscherrer
4567"""
4668 unsafe_logdensityof(m, x)
@@ -68,14 +90,27 @@ See also `logdensityof`.
6890end
6991
7092"""
71- logdensity_rel(m1, m2 , x)
93+ logdensity_rel(μ, ν , x)
7294
73- Compute the log-density of `m1 ` relative to `m2 ` at `x`. This function checks
74- whether `x` is in the support of `m1 ` or `m2 ` (or both, or neither). If `x` is
95+ Compute the log-density of `μ ` relative to `ν ` at `x`. This function checks
96+ whether `x` is in the support of `μ ` or `ν ` (or both, or neither). If `x` is
7597known to be in the support of both, it can be more efficient to call
76- `unsafe_logdensity_rel`.
98+ `unsafe_logdensity_rel`.
99+ """
100+ function logdensity_rel (μ, ν, x)
101+ strict_logdensity_rel (μ, ν, x)
102+ end
103+
77104"""
78- @inline function logdensity_rel (μ:: M , ν:: N , x:: X ) where {M,N,X}
105+ MeasureBase.strict_logdensity_rel(μ, ν, x)
106+
107+ Compute the log-density of `μ` relative to `ν` at `x`. In contrast to
108+ [`logdensity_rel(μ, ν, x)`](@ref), this will not take implicit pushforwards
109+ of `μ` and `ν` (depending on the type of `x`) into account.
110+ """
111+ function strict_logdensity_rel end
112+
113+ @inline function strict_logdensity_rel (μ:: M , ν:: N , x:: X ) where {M,N,X}
79114 T = unstatic (
80115 promote_type (
81116 return_type (logdensity_def, (μ, x)),
0 commit comments