Skip to content

Commit

Permalink
Merge branch 'master' into add-accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
theogf authored Jun 7, 2023
2 parents cd9c216 + a3b8f6d commit 4c9cff6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MeasureTheory"
uuid = "eadaa1a4-d27c-401d-8699-e962e1bbc33b"
authors = ["Chad Scherrer <[email protected]> and contributors"]
version = "0.18.3"
version = "0.18.4"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
4 changes: 2 additions & 2 deletions src/parameterized/binomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ end
x (0, 1)
end

function Base.rand(rng::AbstractRNG, ::Type, d::Binomial{(:n, :p)})
rand(rng, Dists.Binomial(d.n, d.p))
function Base.rand(rng::AbstractRNG, ::Type{T}, d::Binomial{(:n, :p)}) where {T}
rand(rng, T, Dists.Binomial(d.n, d.p))
end

Binomial(n) = Binomial(n, 0.5)
Expand Down
8 changes: 8 additions & 0 deletions src/resettable-rng.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ for T in vcat(subtypes(Signed), subtypes(Unsigned), subtypes(AbstractFloat))
end
end

function Base.rand(r::ResettableRNG, d::AbstractMeasure)
rand(r.rng, d)
end

function Base.rand(r::ResettableRNG, ::Type{T}, d::AbstractMeasure) where {T}
rand(r.rng, T, d)
end

Base.iterate(r::ResettableRNG) = iterate(r, nothing)

function Base.iterate(r::ResettableRNG, ::Nothing)
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ end
@test logdensity_def(Binomial(; n, logitp), y)
@test logdensity_def(Binomial(; n, probitp), y)

rng = ResettableRNG(Random.MersenneTwister())
@test rand(rng, Binomial(n=0, p=1.0)) == 0
@test rand(rng, Binomial(n=10, p=1.0)) == 10

@test_broken logdensity_def(Binomial(n, p), CountingMeasure(ℤ[0:n]), x)
binomlogpdf(n, p, x)
end
Expand Down

0 comments on commit 4c9cff6

Please sign in to comment.