JuliaDiff / JuliaDiff/ForwardDiff.jl
StackOverflowError when differentiating a simple scalar function from SpecialFunctions.jl
Open
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 1k
- Forks
- 160
- PR merge metrics
- No merged PRs in 30d
Description
Here is the MWE:
using ForwardDiff
using SpecialFunctions
log_i0(z::Number) = besseli(0,z) |> log
ForwardDiff.jacobian(x -> log_i0.(x), [1.1, 2.2, 3.3])
REPL output:
ERROR: LoadError: StackOverflowError:
Stacktrace:
[1] besselix(nu::Int64, x::ForwardDiff.Dual{ForwardDiff.Tag{var"#8#9", Float64}, Float64, 3}) (repeats 79984 times)
@ SpecialFunctions ~/.julia/packages/SpecialFunctions/NBIqR/src/bessel.jl:583
in expression starting at (...)
Interestingly,
ForwardDiff.jacobian(x -> log.(besseli.(0, x)), [1.1, 2.2, 3.3])
works great. Am I missing something super-obvious here? (My honest apologies if I am.)
Environment:
- Julia Version 1.6.2
- SpecialFunctions v1.8.1
- ForwardDiff v0.10.23
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the MWE with ForwardDiff and SpecialFunctions, then inspect SpecialFunctions/src/bessel.jl around line 583 and compare it with the working broadcasted expression. Done means differentiating log_i0 over the sample vector no longer raises a StackOverflowError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100