-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport 3-arg
rand
to AbstractPPL 0.5.x (#80)
* Back-port 3-arg `rand` interface. * Bump version for interface change. * Update CI.yml * Fix test errors. --------- Co-authored-by: Hong Ge <[email protected]>
- Loading branch information
Showing
7 changed files
with
75 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using AbstractPPL | ||
using Random | ||
using Test | ||
|
||
mutable struct RandModel <: AbstractProbabilisticProgram | ||
rng | ||
T | ||
end | ||
|
||
function Base.rand(rng::Random.AbstractRNG, ::Type{T}, model::RandModel) where {T} | ||
model.rng = rng | ||
model.T = T | ||
return nothing | ||
end | ||
|
||
@testset "AbstractProbabilisticProgram" begin | ||
@testset "rand defaults" begin | ||
model = RandModel(nothing, nothing) | ||
rand(model) | ||
@test model.rng == Random.default_rng() | ||
@test model.T === NamedTuple | ||
rngs = [Random.default_rng(), Random.MersenneTwister(42)] | ||
Ts = [NamedTuple, Dict] | ||
@testset for T in Ts | ||
model = RandModel(nothing, nothing) | ||
rand(T, model) | ||
@test model.rng == Random.default_rng() | ||
@test model.T === T | ||
end | ||
@testset for rng in rngs | ||
model = RandModel(nothing, nothing) | ||
rand(rng, model) | ||
@test model.rng === rng | ||
@test model.T === NamedTuple | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7d78781
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sunxd3, you can make a new release by commenting:
@JuliaRegistrator register
7d78781
There was a problem hiding this comment.
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/78510
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: