Skip to content

Commit b31f223

Browse files
Merge pull request #63 from ChrisRackauckas-Claude/interface-check-20251230-062428
Fix BigFloat support by generalizing procf type constraint
2 parents c440b8b + ac4a5fe commit b31f223

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/PoissonRandom.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function ad_rand(rng::AbstractRNG, λ::Real)
8282
end
8383

8484
# Procedure F
85-
function procf::Real, K::Int, s::Float64)
85+
function procf::Real, K::Int, s::Real)
8686
# can be pre-computed, but does not seem to affect performance
8787
INV_SQRT_2PI = inv(sqrt(2pi))
8888
ω = INV_SQRT_2PI / s

test/runtests.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,30 @@ for λ in [5.0, 10.0, 15.0, 20.0, 30.0]
9090
test_samples(pois_rand, Distributions.Poisson(λ), n_tsamples)
9191
end
9292

93+
@testset "BigFloat support" begin
94+
@testset "count_rand with BigFloat (λ < 6)" begin
95+
for _ in 1:100
96+
result = pois_rand(BigFloat(3.0))
97+
@test result isa Integer
98+
@test result >= 0
99+
end
100+
end
101+
@testset "ad_rand with BigFloat (λ >= 6)" begin
102+
for _ in 1:100
103+
result = pois_rand(BigFloat(15.0))
104+
@test result isa Integer
105+
@test result >= 0
106+
end
107+
end
108+
@testset "statistical validity with BigFloat" begin
109+
n = 10000
110+
λ = BigFloat(10.0)
111+
samples = [pois_rand(λ) for _ in 1:n]
112+
sample_mean = mean(samples)
113+
@test abs(sample_mean - Float64(λ)) < 3 * sqrt(Float64(λ))
114+
end
115+
end
116+
93117
if get(ENV, "GROUP", "all") == "all" || get(ENV, "GROUP", "all") == "nopre"
94118
@testset "Allocation Tests" begin
95119
include("alloc_tests.jl")

0 commit comments

Comments
 (0)