JuliaDiff / JuliaDiff/ForwardDiff.jl

StackOverflowError when differentiating a simple scalar function from SpecialFunctions.jl

Open
#567 2 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.