-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot take Jacobian of a function that returns a tuple #208
Comments
It's documented in the API that the output of the target function passed to julia> using ForwardDiff, StaticArrays
julia> h(xx) = ((x, y)=xx; SVector(x^2 - y^2 - 1, y - x))
h (generic function with 1 method)
julia> h([1,2])
2-element StaticArrays.SVector{2,Int64}:
-4
1
julia> ForwardDiff.jacobian(h, [1, 2])
2×2 Array{Int64,2}:
2 -4
-1 1 |
Thanks, I seem to have missed that in the docs. |
Unless you give ForwardDiff a buffer to write the results to, it will construct the output buffer via julia> ydual = out
2-element StaticArrays.SVector{2,ForwardDiff.Dual{2,Int64}}:
Dual(-4,2,-4)
Dual(1,-1,1)
julia> similar(ydual, Int, 2, 2)
2×2 Array{Int64,2}:
4445979120 4445980464
4450466064 4447128496 ForwardDiff could use |
When using chunk mode, you could store the already computed partials somewhere and when all chunks are done, create the output |
You're referring here to introducing special codepaths for StaticArray types right? I agree that a lot of desirable behaviors could be introduced by creating StaticArrays-specific methods, but I'm not yet sure that ForwardDiff should take on StaticArrays as a dependency... |
I was just saying it is theoretically possible. Providing functionality for AD with statically sized arrays that is completely allocation free and does not require a preallocated output matrix would be nice though. However, for array sizes when chunk mode starts to become good is when statically sized array become less good so I would say that the combination static array + chunk mode is not very important. |
The text was updated successfully, but these errors were encountered: