StackOverflowError when applying ForwardDiff.derivative to scaled bessel functions, e.g. besseljx
morgan-mitchell opened this issue · comments
I am getting a StackOverflowError
when I attempt to compute the derivative of besselix
using ForwardDiff. This seems to induce besselix
to call itself recursively ad infinitum:
julia> ForwardDiff.derivative(x->besselix(0,x),1.)
ERROR: StackOverflowError:
Stacktrace:
[1] besselix(nu::Int64, x::ForwardDiff.Dual{ForwardDiff.Tag{var"#664#665", Float64}, Float64, 1}) (repeats 79984 times)
@ SpecialFunctions ~/.julia/packages/SpecialFunctions/FhmL1/src/bessel.jl:583
This does not happen with besseli
, used in the same way:
julia> ForwardDiff.derivative(x->besseli(0,x),1.)
0.565159103992485
Similarly, I can take the derivative of besselj
but not besseljx
.
I can't reproduce the issue with ForwardDiff v0.10.35 and SpecialFunctions v2.2.0, neither with Julia v1.8.5 nor v1.9.0-rc1:
julia> using ForwardDiff, SpecialFunctions
julia> ForwardDiff.derivative(x -> besselix(0, x), 1.0)
-0.257849192243932
I recommend updating the versions of the packages you're using. In the meantime I'm going to close as unreproducible.
I assume it was fixed by JuliaDiff/DiffRules.jl#79.