Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "PoissonRandom"
uuid = "e409e4f3-bfea-5376-8464-e040bb5c01ab"
version = "0.4.7"
version = "0.4.8"

[deps]
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
Expand Down
9 changes: 9 additions & 0 deletions src/PoissonRandom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ Random.rand(rng::PassthroughRNG) = rand()
Random.randexp(rng::PassthroughRNG) = randexp()
Random.randn(rng::PassthroughRNG) = randn()

# When an overlay method table (e.g. CUDA.jl's `@device_override
# Random.randexp(::AbstractRNG)`) shadows the methods above, the overlay body
# runs with rng::PassthroughRNG and may call `Random.rand(rng, UInt52Raw())`
# or `Random.rand(rng, T)`. The stdlib Sampler chain bottoms out at
# `_rand52(r, rng_native_52(r))` → `rand(r, UInt64)`; provide those so the
# chain still reaches bare rand(T) and the device-side default_rng path.
Random.rng_native_52(::PassthroughRNG) = UInt64
Random.rand(rng::PassthroughRNG, ::Type{T}) where {T} = rand(T)

count_rand(λ::Real) = count_rand(Random.default_rng(), λ)
function count_rand(rng::AbstractRNG, λ::Real)
n = 0
Expand Down
16 changes: 16 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,22 @@ end
end
end

@testset "PassthroughRNG dispatch" begin
using Random: Random, UInt52Raw
prng = PassthroughRNG()
# The CUDA.jl @device_override Random.randexp(::AbstractRNG) shadows our
# specific Random.randexp(::PassthroughRNG) on the GPU because Julia's
# OverlayMethodTable returns overlay matches without consulting the base
# table when the overlay fully covers the signature. The override body
# then calls these against PassthroughRNG; if they MethodError, kernel
# compilation fails with InvalidIRError on jl_f_throw_methoderror.
@test Random.rng_native_52(prng) === UInt64
@test Random.rand(prng, UInt52Raw()) isa UInt64
@test Random.rand(prng, UInt64) isa UInt64
@test Random.rand(prng, Float32) isa Float32
@test Random.rand(prng, Float64) isa Float64
end

if get(ENV, "GROUP", "all") == "all" || get(ENV, "GROUP", "all") == "nopre"
@testset "Allocation Tests" begin
include("alloc_tests.jl")
Expand Down
Loading