@@ -72,6 +72,10 @@ function logdensity(d::ProductMeasure{F,T}, x::Tuple) where {F,T<:Tuple}
72
72
mapreduce (logdensity, + , d. f .(d. pars), x)
73
73
end
74
74
75
+ function Base. rand (rng:: AbstractRNG , :: Type{T} , d:: ProductMeasure{F,I} ) where {T,F,I<: Tuple }
76
+ rand .(d. pars)
77
+ end
78
+
75
79
# ##############################################################################
76
80
# I <: AbstractArray
77
81
@@ -100,6 +104,11 @@ function Base.show(io::IO, d::ProductMeasure{F,I}) where {F, I<:CartesianIndices
100
104
print (io, " )" )
101
105
end
102
106
107
+
108
+ # function Base.rand(rng::AbstractRNG, ::Type{T}, d::ProductMeasure{F,I}) where {T,F,I<:CartesianIndices}
109
+
110
+ # end
111
+
103
112
# ##############################################################################
104
113
# I <: Base.Generator
105
114
@@ -113,6 +122,15 @@ function logdensity(d::ProductMeasure{F,I}, x) where {F, I<:Base.Generator}
113
122
end
114
123
115
124
125
+ function Base. rand (rng:: AbstractRNG , :: Type{T} , d:: ProductMeasure{F,I} ) where {T,F,I<: Base.Generator }
126
+ mar = marginals (d)
127
+ elT = typeof (rand (rng, T, first (mar)))
128
+
129
+ sz = size (mar)
130
+ r = ResettableRNG (rng, rand (rng, UInt))
131
+ Base. Generator (s -> rand (r, d. pars. f (s)), d. pars. iter)
132
+ end
133
+
116
134
function Base. rand (rng:: AbstractRNG , :: Type{T} , d:: ProductMeasure{F,I} ) where {T,F,I<: Base.Generator }
117
135
mar = marginals (d)
118
136
elT = typeof (rand (rng, T, first (mar)))
@@ -123,7 +141,8 @@ function Base.rand(rng::AbstractRNG, ::Type{T}, d::ProductMeasure{F,I}) where {T
123
141
end
124
142
125
143
@propagate_inbounds function Random. rand! (rng:: AbstractRNG , d:: ProductMeasure , x:: AbstractArray )
126
- T = float (eltype (x))
144
+ # TODO : Generalize this
145
+ T = Float64
127
146
for (j,m) in zip (eachindex (x), marginals (d))
128
147
@inbounds x[j] = rand (rng, T, m)
129
148
end
135
154
136
155
137
156
138
- # @propagate_inbounds function MeasureBase.logdensity(d::ProductMeasure{A}, x) where{T, A<:AbstractArray{T,1}}
139
- # data = marginals(d)
140
- # @boundscheck size(data) == size(x) || throw(BoundsError)
141
- # @tullio s = logdensity(data[i], x[i])
142
- # s
143
- # end
144
-
145
- # @propagate_inbounds function MeasureBase.logdensity(d::ProductMeasure{A}, x) where{T, A<:AbstractArray{T,2}}
146
- # data = marginals(d)
147
- # @boundscheck size(data) == size(x) || throw(BoundsError)
148
- # @tullio s = @inbounds logdensity(data[i,j], x[i,j])
149
- # s
150
- # end
151
-
152
- # @propagate_inbounds function MeasureBase.logdensity(d::ProductMeasure{A}, x) where{T, A<:AbstractArray{T,3}}
153
- # data = marginals(d)
154
- # @boundscheck size(data) == size(x) || throw(BoundsError)
155
- # @tullio s = @inbounds logdensity(data[i,j,k], x[i,j,k])
156
- # s
157
- # end
158
-
159
- # @propagate_inbounds function MeasureBase.logdensity(d::ProductMeasure{A}, x) where{T, A<:AbstractArray{T,4}}
160
- # data = marginals(d)
161
- # @boundscheck size(data) == size(x) || throw(BoundsError)
162
- # @tullio s = @inbounds logdensity(data[i,j,k,l], x[i,j,k,l])
163
- # s
164
- # end
165
-
166
- # @propagate_inbounds function MeasureBase.logdensity(d::ProductMeasure{A}, x) where{T, A<:AbstractArray{T,5}}
167
- # data = marginals(d)
168
- # @boundscheck size(data) == size(x) || throw(BoundsError)
169
- # @tullio s = @inbounds logdensity(data[i,j,k,l,m], x[i,j,k,l,m])
170
- # s
171
- # end
172
-
173
157
export rand!
174
158
using Random: rand!, GLOBAL_RNG, AbstractRNG
175
159
0 commit comments