Skip to content

Commit

Permalink
Define Random.Sampler (#1314)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion authored May 2, 2021
1 parent 99b2b57 commit a00a914
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/genericrand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ with this `sampler` method, which would be used for batch sampling.
The general fallback is `sampler(d::Distribution) = d`.
"""
sampler(s::Sampleable) = s

# Random API
Random.Sampler(::Type{<:AbstractRNG}, s::Sampleable, ::Val{1}) = s
Random.Sampler(::Type{<:AbstractRNG}, s::Sampleable, ::Val{Inf}) = sampler(s)
16 changes: 16 additions & 0 deletions test/samplers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,20 @@ import Distributions:
test_samples(S(d), d, n_tsamples, rng=rng)
end
end

@testset "Random.Sampler" begin
for dist in (
Binomial(5, 0.3),
Exponential(2.0),
Gamma(0.1, 1.0),
Gamma(2.0, 1.0),
MatrixNormal(3, 4),
MvNormal(3, 1.0),
Normal(1.5, 2.0),
Poisson(0.5),
)
@test Random.Sampler(rng, dist, Val(1)) == dist
@test Random.Sampler(rng, dist) == sampler(dist)
end
end
end

4 comments on commit a00a914

@devmotion
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/35816

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.25.0 -m "<description of version>" a00a9148c2ca08ed19ea60f4bf3378537f2b005e
git push origin v0.25.0

@StefanKarpinski
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, is this actually a breaking release? Because by bumping the leading non-zero digit of the version number, that’s what it’s signaling. Which forces everyone everywhere who depends on this package to change their compatibility.

@devmotion
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, unfortunately it is, it contains two PRs with breaking changes: #1317

Please sign in to comment.