Skip to content

Commit 15c8760

Browse files
committed
Fixing up For and ProductMeasure
1 parent 6b40d5c commit 15c8760

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

src/combinators/for.jl

+2-6
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,13 @@ julia> For(eachrow(rand(4,2))) do x Normal(x[1], x[2]) end |> marginals |> colle
7575
```
7676
7777
"""
78-
For(f, dims...) = ProductMeasure(f, dims)
78+
For(f, dims...) = ProductMeasure(i -> f(i...), zip(dims...))
7979

8080
For(f, inds::AbstractArray) = ProductMeasure(f, inds)
8181

82-
82+
For(f, n::Int) = ProductMeasure(f, 1:n)
8383
For(f, dims::Int...) = ProductMeasure(i -> f(Tuple(i)...), CartesianIndices(dims))
8484

85-
function For(f, inds::AbstractArray...)
86-
g(x) = f(x...)
87-
For(g, mappedarray(tuple, inds...))
88-
end
8985

9086
function Base.eltype(d::ProductMeasure{F,I}) where {F,I<:AbstractArray}
9187
return eltype(d.f(first(d.pars)))

src/combinators/product.jl

+4-6
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,11 @@ function Base.rand(rng::AbstractRNG, ::Type{T}, d::ProductMeasure{F,I}) where {T
134134
end
135135

136136
@propagate_inbounds function Random.rand!(rng::AbstractRNG, d::ProductMeasure, x::AbstractArray)
137-
mar = marginals(d)
138-
@boundscheck size(mar) == size(x) || throw(BoundsError)
139-
140-
@inbounds for j in eachindex(x)
141-
x[j] = rand(rng, eltype(x), mar[j])
137+
T = eltype(x)
138+
for(j,m) in zip(eachindex(x), marginals(d))
139+
@inbounds x[j] = rand(rng, T, m)
142140
end
143-
x
141+
return x
144142
end
145143

146144

test/runtests.jl

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ using DynamicIterators: trace, TimeLift
77
using TransformVariables: transform, as𝕀, inverse
88

99
using MeasureTheory
10+
using MeasureTheory: Const
11+
1012
using Aqua
1113
Aqua.test_all(MeasureTheory; ambiguities=false, unbound_args=false)
1214

0 commit comments

Comments
 (0)