@@ -26,11 +26,15 @@ To compute log-density relative to `basemeasure(m)` or *define* a log-density
26
26
`logdensity_def`.
27
27
28
28
To 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.
30
35
"""
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)
34
38
end
35
39
36
40
@inline function logdensityof_rt (:: T , :: U ) where {T,U}
@@ -41,6 +45,24 @@ _checksupport(cond, result) = ifelse(cond == true, result, oftype(result, -Inf))
41
45
42
46
export unsafe_logdensityof
43
47
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
+
44
66
# https://discourse.julialang.org/t/counting-iterations-to-a-type-fixpoint/75876/10?u=cscherrer
45
67
"""
46
68
unsafe_logdensityof(m, x)
@@ -68,14 +90,27 @@ See also `logdensityof`.
68
90
end
69
91
70
92
"""
71
- logdensity_rel(m1, m2 , x)
93
+ logdensity_rel(μ, ν , x)
72
94
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
75
97
known 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
+
77
104
"""
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}
79
114
T = unstatic (
80
115
promote_type (
81
116
return_type (logdensity_def, (μ, x)),
0 commit comments