|
| 1 | +export ⊙ |
| 2 | + |
| 3 | +@concrete terse struct PointwiseProductMeasure{T} <: AbstractMeasure |
| 4 | + data :: T |
| 5 | + |
| 6 | + PointwiseProductMeasure(μs...) = new{typeof(μs)}(μs) |
| 7 | + PointwiseProductMeasure(μs) = new{typeof(μs)}(μs) |
| 8 | +end |
| 9 | + |
| 10 | +Base.size(μ::PointwiseProductMeasure) = size(μ.data) |
| 11 | + |
| 12 | +function Base.show(io::IO, μ::PointwiseProductMeasure) |
| 13 | + io = IOContext(io, :compact => true) |
| 14 | + print(io, join(string.(μ.data), " ⊙ ")) |
| 15 | +end |
| 16 | + |
| 17 | +function Base.show_unquoted(io::IO, μ::PointwiseProductMeasure, indent::Int, prec::Int) |
| 18 | + if Base.operator_precedence(:*) ≤ prec |
| 19 | + print(io, "(") |
| 20 | + show(io, μ) |
| 21 | + print(io, ")") |
| 22 | + else |
| 23 | + show(io, μ) |
| 24 | + end |
| 25 | + return nothing |
| 26 | +end |
| 27 | + |
| 28 | +Base.length(m::PointwiseProductMeasure{T}) where {T} = length(m.data) |
| 29 | + |
| 30 | +function ⊙(μ::PointwiseProductMeasure{X}, ν::PointwiseProductMeasure{Y}) where {X,Y} |
| 31 | + data = (μ.data..., ν.data...) |
| 32 | + PointwiseProductMeasure(data...) |
| 33 | +end |
| 34 | + |
| 35 | +function ⊙(μ, ν::PointwiseProductMeasure{Y}) where {Y} |
| 36 | + data = (μ, ν.data...) |
| 37 | + PointwiseProductMeasure(data...) |
| 38 | +end |
| 39 | + |
| 40 | +function ⊙(μ::PointwiseProductMeasure{X}, ν::N) where {X, N <: AbstractMeasure} |
| 41 | + data = (μ.data..., ν) |
| 42 | + PointwiseProductMeasure(data...) |
| 43 | +end |
| 44 | + |
| 45 | +function ⊙(μ::M, ν::N) where {M <: AbstractMeasure, N <: AbstractMeasure} |
| 46 | + data = (μ, ν) |
| 47 | + PointwiseProductMeasure(data...) |
| 48 | +end |
| 49 | + |
| 50 | +function ⊙(μ::AbstractMeasure, ℓ::LogLikelihood) |
| 51 | + data = (μ, ℓ) |
| 52 | + PointwiseProductMeasure(data...) |
| 53 | +end |
| 54 | + |
| 55 | +function logdensity(d::PointwiseProductMeasure, x) |
| 56 | + sum((logdensity(dⱼ, x) for dⱼ in d.data)) |
| 57 | +end |
| 58 | + |
| 59 | +function sampletype(d::PointwiseProductMeasure) |
| 60 | + @inbounds sampletype(first(d.data)) |
| 61 | +end |
| 62 | + |
| 63 | +basemeasure(μ::PointwiseProductMeasure) = @inbounds basemeasure(first(d.data)) |
0 commit comments