-
Notifications
You must be signed in to change notification settings - Fork 430
Closed
Description
I noticed that the implementations of Bessel functions used here are quite slow, and replacing them with Bessel.jl can give major speedups.
For examples, replacing
Distributions.jl/src/univariate/continuous/rician.jl
Lines 112 to 116 in c2a7387
function logpdf(d::Rician, x::Real) | |
ν, σ = params(d) | |
result = log(2 * abs(x) / σ^2) + logpdf(NoncentralChisq(2, (ν / σ)^2), (x / σ)^2) | |
return x < 0 || isinf(x) ? oftype(result, -Inf) : result | |
end |
julia> import Bessels as B
julia> @eval Distributions function logpdf(d::Rician, x::Real)
ν, σ = params(d); σ² = σ^2
result = log(x/σ² * $B.besseli0(x*ν/σ²)) - (x^2 + ν^2)/2σ²
return x < 0 || isinf(x) ? oftype(result, -Inf) : result
end
leads to ~x3-4 performance improvement immediately. Presumably, there are much more cases where this is possible.
Would adding a Bessels.jl dep be considered a reasonable thing by Distributions.jl devs?
Metadata
Metadata
Assignees
Labels
No labels