Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StackOverflowError when applying ForwardDiff.derivative to scaled bessel functions, e.g. besseljx #412

Closed
morgan-mitchell opened this issue Oct 27, 2022 · 2 comments

Comments

@morgan-mitchell
Copy link

morgan-mitchell commented Oct 27, 2022

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.

@ararslan
Copy link
Member

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.

@devmotion
Copy link
Member

I assume it was fixed by JuliaDiff/DiffRules.jl#79.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants