@@ -31,13 +31,23 @@ function Base.rand(rng::AbstractRNG, ::Type{T}, d::AbstractProductMeasure) where
3131 _rand_product (rng, T, mar, eltype (mar))
3232end
3333
34- function _rand_product (rng:: AbstractRNG , :: Type{T} , mar, :: Type{M} ) where {T,M<: AbstractMeasure }
34+ function _rand_product (
35+ rng:: AbstractRNG ,
36+ :: Type{T} ,
37+ mar,
38+ :: Type{M} ,
39+ ) where {T,M<: AbstractMeasure }
3540 map (mar) do dⱼ
3641 rand (rng, T, dⱼ)
3742 end
3843end
3944
40- function _rand_product (rng:: AbstractRNG , :: Type{T} , mar:: ReadonlyMappedArray , :: Type{M} ) where {T,M<: AbstractMeasure }
45+ function _rand_product (
46+ rng:: AbstractRNG ,
47+ :: Type{T} ,
48+ mar:: ReadonlyMappedArray ,
49+ :: Type{M} ,
50+ ) where {T,M<: AbstractMeasure }
4151 mappedarray (mar. data) do dⱼ
4252 rand (rng, T, mar. f (dⱼ))
4353 end |> collect
@@ -49,14 +59,17 @@ function _rand_product(rng::AbstractRNG, ::Type{T}, mar, ::Type{M}) where {T,M}
4959 end
5060end
5161
52-
53- function _rand_product (rng:: AbstractRNG , :: Type{T} , mar:: ReadonlyMappedArray , :: Type{M} ) where {T,M}
62+ function _rand_product (
63+ rng:: AbstractRNG ,
64+ :: Type{T} ,
65+ mar:: ReadonlyMappedArray ,
66+ :: Type{M} ,
67+ ) where {T,M}
5468 mappedarray (mar. data) do dⱼ
5569 rand (rng, mar. f (dⱼ))
5670 end |> collect
5771end
5872
59-
6073@inline function logdensity_def (d:: AbstractProductMeasure , x)
6174 mapreduce (logdensity_def, + , marginals (d), x)
6275end
7083end
7184
7285function Pretty. tile (d:: ProductMeasure{T} ) where {T<: Tuple }
73- Pretty. list_layout (Pretty. tile .([marginals (d)... ]), sep= " ⊗ " )
86+ Pretty. list_layout (Pretty. tile .([marginals (d)... ]), sep = " ⊗ " )
7487end
7588
7689# For tuples, `mapreduce` has trouble with type inference
7790@inline function logdensity_def (d:: ProductMeasure{T} , x) where {T<: Tuple }
78- ℓs = map (logdensity_def, marginals (d),x)
91+ ℓs = map (logdensity_def, marginals (d), x)
7992 sum (ℓs)
8093end
8194
@@ -115,30 +128,35 @@ function basemeasure(μ::ProductMeasure{Base.Generator{I,F}}) where {I,F}
115128 _basemeasure (μ, B, static (Base. issingletontype (B)))
116129end
117130
118-
119-
120131function basemeasure (μ:: ProductMeasure{A} ) where {T,A<: AbstractMappedArray{T} }
121132 B = Core. Compiler. return_type (basemeasure, Tuple{T})
122133 _basemeasure (μ, B, static (Base. issingletontype (B)))
123134end
124135
125136function _basemeasure (μ:: ProductMeasure , :: Type{B} , :: True ) where {T,B}
126- return instance (B) ^ axes (marginals (μ))
137+ return instance (B)^ axes (marginals (μ))
127138end
128139
129- function _basemeasure (μ:: ProductMeasure{A} , :: Type{B} , :: False ) where {T,A<: AbstractMappedArray{T} ,B}
140+ function _basemeasure (
141+ μ:: ProductMeasure{A} ,
142+ :: Type{B} ,
143+ :: False ,
144+ ) where {T,A<: AbstractMappedArray{T} ,B}
130145 mar = marginals (μ)
131146 productmeasure (mappedarray (basemeasure, mar))
132147end
133148
134- function _basemeasure (μ:: ProductMeasure{Base.Generator{I,F}} , :: Type{B} , :: False ) where {I,F,B}
149+ function _basemeasure (
150+ μ:: ProductMeasure{Base.Generator{I,F}} ,
151+ :: Type{B} ,
152+ :: False ,
153+ ) where {I,F,B}
135154 mar = marginals (μ)
136155 productmeasure (Base. Generator (basekernel (mar. f), mar. iter))
137156end
138157
139158marginals (μ:: ProductMeasure ) = μ. marginals
140159
141-
142160testvalue (d:: AbstractProductMeasure ) = map (testvalue, marginals (d))
143161
144162export ⊗
@@ -184,18 +202,17 @@ function _rand(rng::AbstractRNG, ::Type{T}, d::ProductMeasure, mar::AbstractArra
184202 rand! (rng, d, x)
185203end
186204
187-
188205@inline function insupport (d:: AbstractProductMeasure , x:: AbstractArray )
189206 mar = marginals (d)
190- for (j,mj) in enumerate (mar)
207+ for (j, mj) in enumerate (mar)
191208 dynamic (insupport (mj, x[j])) || return false
192209 end
193210 return true
194211end
195212
196213@inline function insupport (d:: AbstractProductMeasure , x)
197- for (mj,xj) in zip (marginals (d), x)
214+ for (mj, xj) in zip (marginals (d), x)
198215 dynamic (insupport (mj, xj)) || return false
199216 end
200217 return true
201- end
218+ end
0 commit comments