We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
here
1 parent 75bba13 commit 1dc299cCopy full SHA for 1dc299c
Project.toml
@@ -1,7 +1,7 @@
1
name = "TracedRandom"
2
uuid = "03576162-b2ff-4022-a931-e67b9900fd45"
3
authors = ["Xuan <[email protected]>"]
4
-version = "0.1.0"
+version = "0.1.1"
5
6
[deps]
7
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
src/TracedRandom.jl
@@ -2,12 +2,27 @@ module TracedRandom
using Random
-export rand!, randn!, randexp, randexp!,
+export here, rand!, randn!, randexp, randexp!,
bitrand, randstring, randsubseq, randsubseq!,
shuffle, shuffle!, randperm, randperm!, randcycle, randcycle!
8
9
const Address = Union{Symbol,Pair{Symbol}}
10
11
+struct Here end
12
+
13
+"""
14
+ here
15
16
+Special address that refers to the address namespace of the calling context.
17
+Supported when [`rand`](@ref) is called on a non-primitive stochastic function,
18
+causing all named random variables sampled by that function to be spliced into
19
+the address namespace of the calling context.
20
21
+const here = Here()
22
23
+Base.rand(::Here, fn::Function, args...) = fn(args...)
24
+Base.rand(::AbstractRNG, ::Here, fn::Function, args...) = fn(args...)
25
26
Base.rand(::Address, fn::Function, args...) = fn(args...)
27
Base.rand(::AbstractRNG, ::Address, fn::Function, args...) = fn(args...)
28
test/runtests.jl
@@ -9,6 +9,12 @@ Random.seed!(0)
untraced = gaussian_mixture([1, 10, 100])
@test traced == untraced
+Random.seed!(0)
+traced = rand(here, gaussian_mixture, [1, 10, 100])
+untraced = gaussian_mixture([1, 10, 100])
+@test traced == untraced
end
@testset "Addressed calls with global RNG" begin
0 commit comments