Skip to content

Commit e88e952

Browse files
committed
proxyfuns
1 parent 3d1084f commit e88e952

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
2626
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
2727
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
2828
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
29+
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
2930
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3031
Tricks = "410a4b4d-49e4-4fbc-ab6d-cb71b17b3775"
3132

3233
[compat]
3334
ChainRulesCore = "1"
34-
ChangesOfVariables = "0.1.3"
35+
ChangesOfVariables = "0.1"
3536
Compat = "3.35, 4"
3637
ConstructionBase = "1.3"
3738
DensityInterface = "0.4"
@@ -52,6 +53,7 @@ Reexport = "1"
5253
SpecialFunctions = "2"
5354
Static = "0.8, 1"
5455
Statistics = "1"
56+
StatsBase = "0.34"
5557
Test = "1"
5658
Tricks = "0.1"
5759
julia = "1.6"

src/rand.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,24 @@ Base.rand(rng::AbstractRNG, d::AbstractMeasure) = rand(rng, Float64, d)
88

99
@inline Random.rand!(d::AbstractMeasure, args...) = rand!(GLOBAL_RNG, d, args...)
1010

11+
@inline function Base.rand(
12+
rng::AbstractRNG,
13+
::Type{T},
14+
d::ProductMeasure{A},
15+
) where {T,A<:AbstractArray}
16+
mar = marginals(d)
17+
18+
# Distributions doens't (yet) have the three-argument form
19+
elT = typeof(rand(rng, T, first(mar)))
20+
21+
sz = size(mar)
22+
x = Array{elT,length(sz)}(undef, sz)
23+
@inbounds @simd for j in eachindex(mar)
24+
x[j] = rand(rng, T, mar[j])
25+
end
26+
x
27+
end
28+
1129
# TODO: Make this work
1230
# function Base.rand(rng::AbstractRNG, ::Type{T}, d::AbstractMeasure) where {T}
1331
# x = testvalue(d)

src/utils.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,12 @@ using InverseFunctions: FunctionWithInverse
164164

165165
unwrap(f) = f
166166
unwrap(f::FunctionWithInverse) = f.f
167+
168+
import Statistics
169+
import StatsBase
170+
171+
StatsBase.entropy(m::AbstractMeasure, b::Real) = entropy(proxy(m), b)
172+
Statistics.mean(m::AbstractMeasure) = mean(proxy(m))
173+
Statistics.std(m::AbstractMeasure) = std(proxy(m))
174+
Statistics.var(m::AbstractMeasure) = var(proxy(m))
175+
Statistics.quantile(m::AbstractMeasure, q) = quantile(proxy(m), q)

0 commit comments

Comments
 (0)