Skip to content

Commit c8750f3

Browse files
author
Chris Geoga
committed
Fix issue that made order derivatives of besseli zero when
`isinteger(v)`.
1 parent bcdb6ab commit c8750f3

File tree

4 files changed

+576
-583
lines changed

4 files changed

+576
-583
lines changed

src/BesselFunctions/besseli.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,6 @@ _besseli(nu::Union{Int16, Float16}, x::Union{Int16, Float16}) = Float16(_besseli
414414
_besseli(nu::AbstractRange, x::T) where T = besseli!(zeros(T, length(nu)), nu, x)
415415

416416
function _besseli(nu::T, x::T) where T <: Union{Float32, Float64}
417-
isinteger(nu) && return _besseli(Int(nu), x)
418417
~isfinite(x) && return x
419418
abs_nu = abs(nu)
420419
abs_x = abs(x)

test/besseli_test.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ end
131131
(v, x) = 12.0, 3.2
132132
@test besseli(v,x) 7.1455266650203694069897133431e-7
133133

134-
(v,x) = 13.0, -1.0
134+
# Negative arguments only allowed with v::Int!
135+
(v,x) = 13, -1.0
135136
@test besseli(v,x) -1.995631678207200756444e-14
136137

137138
(v,x) = 12.6, -3.0
@@ -146,8 +147,7 @@ end
146147
(v, x) = -12.3, 8.2
147148
@test besseli(v,x) 0.267079696793126091886043602895
148149

149-
(v, x) = -14.0, -9.9
150+
# Negative arguments only allowed with v::Int!
151+
(v, x) = -14, -9.9
150152
@test besseli(v,x) 0.2892290867115615816280234648
151153

152-
(v, x) = -14.6, -10.6
153-
#@test besseli(v,x) ≈ -0.157582642056898598750175404443 - 0.484989503203097528858271270828*im

test/data/besseli/enzyme/README.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
```julia
2-
using ArbNumerics, DelimitedFiles, SpecialFunctions, Enzyme, Bessels
2+
using ArbNumerics, DelimitedFiles, SpecialFunctions
33

44
# Because you can't just use FiniteDifferences due to the "numerical noise".
55
simplefd(f,x,h=ArbReal(1e-40)) = (f(x+h)-f(x))/h
66

77
ArbNumerics.setprecision(ArbReal, digits=100)
88
arb_besseli(v,x) = ArbNumerics.besseli(ArbReal(v), ArbReal(x))
99

10-
# TODO (cg 2023/05/30 11:44): temporarily, we make vgrid[end]=15.1 instead of
11-
# 15.0 or some other integer because the integer-order `besseli` derivatives
12-
# need to be fixed with dispatch, like `besselk`.
13-
vgrid = range(1e-3, 15.1, length=20)
10+
vgrid = range(1e-3, 15.0, length=20)
1411
xgrid = range(1e-3, 100.0, length=30)
1512
vx = vec(collect(Iterators.product(vgrid, xgrid)))
1613

17-
our_dx(v,x) = autodiff(Forward, _x->Bessels.besseli(v, _x), Duplicated, Duplicated(x, 1.0))[2]
18-
our_dv(v,x) = autodiff(Forward, _v->Bessels.besseli(_v, x), Duplicated, Duplicated(v, 1.0))[2]
19-
2014
if !isinteractive()
2115
ref_values = map(vx) do vxj
2216
(v,x) = vxj

0 commit comments

Comments
 (0)