We are excited to announce Bessels.jl which is a special function library written in Julia to compute Bessel and Modified Bessel functions, Spherical Bessel functions, Airy functions, and Hankel functions. Currently the library supports single and double precision results for real arguments of any order.
There are several advantages of this library as it is written entirely in Julia, generally high performant, and does not allocate. Bessels.jl
provides a lot of overlapping functionality with SpecialFunctions.jl and tries to match or exceed the accuracy of SpecialFunctions.jl
in most domains. The available functions can be found in the API.
Benchmarks
Some speed comparisons to SpecialFunctions.jl
can be found in the Readme. Here are a few comparisons though note that different algorithms are used for different domains in both libraries.
# Bessel functions of the first kind
julia> @benchmark SpecialFunctions.besselj(v, x) setup=(v=rand()*100; x = rand()*100)
BenchmarkTools.Trial: 4681 samples with 803 evaluations.
Range (min โฆ max): 162.007 ns โฆ 11.076 ฮผs โ GC (min โฆ max): 0.00% โฆ 0.00%
Time (median): 1.121 ฮผs โ GC (median): 0.00%
Time (mean ยฑ ฯ): 1.329 ฮผs ยฑ 1.505 ฮผs โ GC (mean ยฑ ฯ): 0.01% ยฑ 0.53%
โโโ โโโโโ โโ โ
โโโโโโโโโโโโ
โโโโโโ
โโโโโโโ
โโโโโโโ
โโโโโโโโโ
โโโโโโโโโโโโโโโโโโโ โ
162 ns Histogram: log(frequency) by time 9.45 ฮผs <
Memory estimate: 16 bytes, allocs estimate: 1.
julia> @benchmark Bessels.besselj(v, x) setup=(v=rand()*100; x = rand()*100)
BenchmarkTools.Trial: 10000 samples with 983 evaluations.
Range (min โฆ max): 58.547 ns โฆ 356.359 ns โ GC (min โฆ max): 0.00% โฆ 0.00%
Time (median): 99.869 ns โ GC (median): 0.00%
Time (mean ยฑ ฯ): 144.048 ns ยฑ 80.418 ns โ GC (mean ยฑ ฯ): 0.00% ยฑ 0.00%
โ
โโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
58.5 ns Histogram: frequency by time 278 ns <
Memory estimate: 0 bytes, allocs estimate: 0.
# Modified Bessel function of second kind and zero order
julia> @benchmark SpecialFunctions.besselk(0, x) setup=(x = rand()*100)
BenchmarkTools.Trial: 10000 samples with 807 evaluations.
Range (min โฆ max): 121.483 ns โฆ 1.209 ฮผs โ GC (min โฆ max): 0.00% โฆ 70.69%
Time (median): 197.039 ns โ GC (median): 0.00%
Time (mean ยฑ ฯ): 213.963 ns ยฑ 49.302 ns โ GC (mean ยฑ ฯ): 0.08% ยฑ 1.08%
โ โโ
โโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
121 ns Histogram: frequency by time 449 ns <
Memory estimate: 16 bytes, allocs estimate: 1.
julia> @benchmark Bessels.besselk(0, x) setup=(x = rand()*100)
BenchmarkTools.Trial: 10000 samples with 998 evaluations.
Range (min โฆ max): 16.096 ns โฆ 25.895 ns โ GC (min โฆ max): 0.00% โฆ 0.00%
Time (median): 18.430 ns โ GC (median): 0.00%
Time (mean ยฑ ฯ): 18.425 ns ยฑ 0.270 ns โ GC (mean ยฑ ฯ): 0.00% ยฑ 0.00%
โโโโโโโโโโ โ
โโโโโ
โโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
16.1 ns Histogram: log(frequency) by time 18.8 ns <
Memory estimate: 0 bytes, allocs estimate: 0.
Limitations
- No support for complex arguments. This is actively being developed and support for Airy functions in the entire complex plane will be available in the next few days.
- Does not yet work with automatic differentiation libraries. Though, differentiation wrt to argument are mostly covered by AD rules. For derivatives wrt to order please see BesselK.jl.
- Only support single and double precision. In the future we plan to support the
Double64
type provided by DoubleFloats.jl.
Our current development is focused on tackling these limitations as well as supporting other functions such as inhomogenous Airy functions. There is a current discussion on the scope of this project in this issue. Please leave any comments on what type of special functions you would like to see supported or any other feature requests. That would be most helpful in focusing development effort.
And of course I would like to particularly acknowledge @Oscar_Smith for reviewing every single PR, contributing, and being a big motivation to further develop this project. I would also like to thank @cgeoga for providing very valuable additions to the code and helpful discussions.
Please feel free to ask any questions or provide any requests!