You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using ForwardDiff
g(x) = [[x^2, sqrt(x)]]
println(ForwardDiff.derivative(g, 2))
But this code:
using DiffResults
using ForwardDiff
g(x) = [[x^2, sqrt(x)]]
result = DiffResults.DiffResult(similar(g(2)), similar(g(2)))
result = ForwardDiff.derivative!(result, g, 2)
println(result)
To me the issue is bigger than one missing method: you are trying to use ForwardDiff in a setting where it is not meant to work. As the docstring of ForwardDiff.derivative clearly states,
This method assumes that isa(f(x), Union{Real,AbstractArray}).
Thus, even if you add this method, calling derivative with non-array outputs will be outside of the public API. It won't necessarily be tested, and it will be vulnerable to breaking even between patch versions. That is, unless the API is extended, but I'm not sure it's worth it to open such a can of worms?
The following code works:
But this code:
Leads to a runtime error:
Adding the following line fixes this problem:
The text was updated successfully, but these errors were encountered: