Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxyfuns #151

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Tricks = "410a4b4d-49e4-4fbc-ab6d-cb71b17b3775"

[compat]
ChainRulesCore = "1"
ChangesOfVariables = "0.1.3"
ChangesOfVariables = "0.1"
Compat = "3.35, 4"
ConstructionBase = "1.3"
DensityInterface = "0.4"
Expand All @@ -52,6 +53,7 @@ Reexport = "1"
SpecialFunctions = "2"
Static = "0.8, 1"
Statistics = "1"
StatsBase = "0.34"
Test = "1"
Tricks = "0.1"
julia = "1.6"
18 changes: 18 additions & 0 deletions src/rand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@

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

@inline function Base.rand(

Check warning on line 11 in src/rand.jl

View check run for this annotation

Codecov / codecov/patch

src/rand.jl#L11

Added line #L11 was not covered by tests
rng::AbstractRNG,
::Type{T},
d::ProductMeasure{A},
) where {T,A<:AbstractArray}
mar = marginals(d)

Check warning on line 16 in src/rand.jl

View check run for this annotation

Codecov / codecov/patch

src/rand.jl#L16

Added line #L16 was not covered by tests

# Distributions doens't (yet) have the three-argument form
elT = typeof(rand(rng, T, first(mar)))

Check warning on line 19 in src/rand.jl

View check run for this annotation

Codecov / codecov/patch

src/rand.jl#L19

Added line #L19 was not covered by tests

sz = size(mar)
x = Array{elT,length(sz)}(undef, sz)
@inbounds @simd for j in eachindex(mar)
x[j] = rand(rng, T, mar[j])
end
x

Check warning on line 26 in src/rand.jl

View check run for this annotation

Codecov / codecov/patch

src/rand.jl#L21-L26

Added lines #L21 - L26 were not covered by tests
end

# TODO: Make this work
# function Base.rand(rng::AbstractRNG, ::Type{T}, d::AbstractMeasure) where {T}
# x = testvalue(d)
Expand Down
9 changes: 9 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,12 @@

unwrap(f) = f
unwrap(f::FunctionWithInverse) = f.f

import Statistics
import StatsBase

StatsBase.entropy(m::AbstractMeasure, b::Real) = entropy(proxy(m), b)
Statistics.mean(m::AbstractMeasure) = mean(proxy(m))
Statistics.std(m::AbstractMeasure) = std(proxy(m))
Statistics.var(m::AbstractMeasure) = var(proxy(m))
Statistics.quantile(m::AbstractMeasure, q) = quantile(proxy(m), q)

Check warning on line 175 in src/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils.jl#L171-L175

Added lines #L171 - L175 were not covered by tests
Loading