ForwardDiff - MethodError: no method matching extract_jacobian

Adrien_Vet
Mon, 13 Jan 2025 13:06:48 +0000
General Usage

Hello everyone,

I’m struggling with the differentiation of some functions using the ForwardDiff package. Here is a reproducible example :

using StaticArrays
using ForwardDiff

function f_test(x)
       return exp(x[1])*sin(x[2])
end

y = SVector(0.0, 0.0) # or a random SVector

ForwardDiff.jacobian(f_test, y)

Unfortunately I get this error:

ERROR: MethodError: no method matching extract_jacobian(::Type{ForwardDiff.Tag{…}}, ::ForwardDiff.Dual{ForwardDiff.Tag{…}, Float64, 2}, ::SVector{2, Float64})

Closest candidates are:
  extract_jacobian(::Type{T}, ::StaticArray, ::S) where {T, S<:StaticArray}
   @ ForwardDiffStaticArraysExt C:\Users\Adrien VET\.julia\packages\ForwardDiff\UBbGT\ext\ForwardDiffStaticArraysExt.jl:74
  extract_jacobian(::Type{T}, ::AbstractArray, ::StaticArray) where T
   @ ForwardDiffStaticArraysExt C:\Users\Adrien VET\.julia\packages\ForwardDiff\UBbGT\ext\ForwardDiffStaticArraysExt.jl:84

Stacktrace:
 [1] vector_mode_jacobian
   @ C:\Users\Adrien VET\.julia\packages\ForwardDiff\UBbGT\ext\ForwardDiffStaticArraysExt.jl:91 [inlined]
 [2] jacobian(f::typeof(f_test), x::SVector{2, Float64})
   @ ForwardDiffStaticArraysExt C:\Users\Adrien VET\.julia\packages\ForwardDiff\UBbGT\ext\ForwardDiffStaticArraysExt.jl:66
 [3] top-level scope
   @ REPL[99]:1
Some type information was truncated. Use `show(err)` to see complete types.

I don’t get why I have this error. I see in the docstring that the function to differentiate has to take an AbstractArray and output an AbstractArray ; and every SVector is indeed an AbstractArray…

4 posts - 3 participants