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: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.4.7"

[deps]
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[compat]
Expand All @@ -13,6 +14,7 @@ Distributions = "0.25"
ExplicitImports = "1.14.0"
JET = "0.9, 0.10, 0.11"
LogExpFunctions = "0.3"
PrecompileTools = "1"
Random = "1.10"
Statistics = "1"
Test = "1"
Expand Down
11 changes: 11 additions & 0 deletions src/PoissonRandom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module PoissonRandom

using Random: Random, AbstractRNG, randexp
using LogExpFunctions: log1pmx
using PrecompileTools: @compile_workload

export pois_rand, PassthroughRNG

Expand Down Expand Up @@ -136,4 +137,14 @@ pois_rand(PoissonRandom.PassthroughRNG(), λ)
pois_rand(λ::Real) = pois_rand(Random.GLOBAL_RNG, λ)
pois_rand(rng::AbstractRNG, λ::Real) = λ < 6 ? count_rand(rng, λ) : ad_rand(rng, λ)

@compile_workload begin
# Precompile the most common code paths
# Small λ uses count_rand, large λ uses ad_rand
pois_rand(3.0) # count_rand path (λ < 6)
pois_rand(50.0) # ad_rand path (λ >= 6)
# PassthroughRNG for GPU compatibility
pois_rand(PassthroughRNG(), 3.0)
pois_rand(PassthroughRNG(), 50.0)
end

end # module
Loading