JuliaDiff / JuliaDiff/ForwardDiff.jl
Nested jacobian! calls
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 1k
- Forks
- 160
- PR merge metrics
- No merged PRs in 30d
Description
Hi!
I'm having some troubles using nested inplace jacobian:
using ForwardDiff
using LinearAlgebra
#some data
x0 = randn(50000);
p0 = randn(2);
#pre allocate outputs
out = similar(x0);
outjac = Array{Float64}(undef, 50000, 2);
outjac2 = Array{Float64}(undef,100000, 2)
#'regular' and in place function
f(p) = @. p[1] * exp(-x0 * p[2]);
f!(out, p) = @. out = p[1] * exp(-x0 * p[2]);
ForwardDiff.jacobian!(outjac2,(outjacin,p) -> (outjacin .= ForwardDiff.jacobian(f, p)), outjac, p0) #works like a charm
ForwardDiff.jacobian!(outjac2,(outjacin,p) -> ForwardDiff.jacobian!(outjacin, f!, out, p), outjac, p0); # breaks
It throws MethodError: no method matching Float64(::ForwardDiff.Dual{ForwardDiff.Tag{getfield(Main, Symbol("##77#78")),Float64},Float64,2})
Both inner functions work and produce the same result:
g1 = (outjacin,p) -> ForwardDiff.jacobian!(outjacin, f!, out, p)
g1(outjac,p0)
g2 = (outjacin,p) -> (outjacin .= ForwardDiff.jacobian(f, p))
g2(outjac,p0)
Thanks for the help!
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
Start by running the supplied reproducer around the nested ForwardDiff.jacobian! calls and compare it with the non-in-place jacobian path. Investigate how the inner jacobian! handles Dual values and determine what is needed for nested differentiation. Done means the in-place nested call no longer raises the Float64(::ForwardDiff.Dual) MethodError and produces the same result as the working path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100