Consider this:
using ForwardDiff
function f!(F, x)
F[1] = (x[1]+3)*(x[2]^3-7)+18
F[2] = sin(x[2]*exp(x[1])-1)
return F
end
F = Array{Float64}(undef, 2)
x = [1, 1]
Now let’s compute the Jacobian. The documentation, says:
ForwardDiff.jacobian(f!, y::AbstractArray, x::AbstractArray, cfg::JacobianConfig = JacobianConfig(f!, y, x), check=Val{true}())
Return
J(f!)
evaluated atx
, assumingf!
is called asf!(y, x)
where the result is stored iny
.
since f!(F, x)
works, then this should work:
∇f!(F, x) = ForwardDiff.jacobian!(f!, F, x)
however
julia> ∇f!(F, x)
ERROR: MethodError: no method matching jacobian!(::typeof(f!), ::Vector{Float64}, ::Vector{Int64})
Closest candidates are:
jacobian!(::Union{AbstractArray, DiffResults.DiffResult}, ::Any, ::AbstractArray, ::AbstractArray) at /Users/amrods/.julia/packages/ForwardDiff/QOqCN/src/jacobian.jl:75
jacobian!(::Union{AbstractArray, DiffResults.DiffResult}, ::Any, ::AbstractArray, ::AbstractArray, ::ForwardDiff.JacobianConfig{T, V, N, D} where {V, N, D}) where T at /Users/amrods/.julia/packages/ForwardDiff/QOqCN/src/jacobian.jl:75
jacobian!(::Union{AbstractArray, DiffResults.DiffResult}, ::Any, ::AbstractArray, ::AbstractArray, ::ForwardDiff.JacobianConfig{T, V, N, D} where {V, N, D}, ::Val{CHK}) where {T, CHK} at /Users/amrods/.julia/packages/ForwardDiff/QOqCN/src/jacobian.jl:75
...
Stacktrace:
[1] ∇f!(F::Vector{Float64}, x::Vector{Int64})
@ Main ~/discourseQ4.jl:137
[2] top-level scope
@ REPL[1]:1
Is that a bug in ForwardDiff
or its documentation?