This repository was archived by the owner on Aug 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
In-place *_jacvec! assumes square jacobian #184
Copy link
Copy link
Open
Description
auto_jacvec!andnum_jacvec!only work when the output and input dimensions are the same, i.e., the jacobian is square. The issue is this line (and the equivalent fornum_jacvec!), which should probably use both the length and eltype ofdy.
| cache2 = similar(cache1), |
-
Manual cache allocation works but is surprisingly hard to get right, the implicit prescription in the README gets the wrong tag type for the duals: https://github.com/JuliaDiff/SparseDiffTools.jl#jacobian-vector-and-hessian-vector-products
-
The corresponding lines in
JacVecshould similarly be fixed:cache2 = Dual{typeof(ForwardDiff.Tag(DeivVecTag(),eltype(x))),eltype(x),1}.(x, ForwardDiff.Partials.(tuple.(x)))
- Besides, shouldn't
auto_jacvec(!)be upstreamed to ForwardDiff? Strange to have to pull in a sparse-related package to get this functionality. Calculating J_f(x) . y efficiently ForwardDiff.jl#319
MWE:
using SparseDiffTools
function f!(dx, x)
dx[1] = x[2] + x[3]
dx[2] = x[1]
end
x = randn(3)
v = randn(3)
dx = zeros(2)
auto_jacvec!(dx, f!, x, v)Metadata
Metadata
Assignees
Labels
No labels