Skip to content

Commit 2e361c9

Browse files
committed
elementwise => pointwise
1 parent 4600f3f commit 2e361c9

File tree

2 files changed

+63
-63
lines changed

2 files changed

+63
-63
lines changed

src/combinators/elementwise.jl

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/combinators/pointwise.jl

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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

Comments
 (0)