-
Notifications
You must be signed in to change notification settings - Fork 44
Add method to mirror ForwardDiff's syntax for writing Jacobian of an oop function to an allocated matrix #128
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
Conversation
…ocated matrix (rather than allocate new matrix for Jacobian)
Codecov Report
@@ Coverage Diff @@
## master #128 +/- ##
==========================================
+ Coverage 80.46% 81.56% +1.10%
==========================================
Files 12 12
Lines 558 613 +55
==========================================
+ Hits 449 500 +51
- Misses 109 113 +4
Continue to review full report at Codecov.
|
It might be good to separate the StaticArray case anyways by using |
If SparseMatrixCSC has its own branch, then https://github.com/JuliaDiff/SparseDiffTools.jl/pull/128/files#diff-7e39b900cec80b7d52f89704e277c0f56afc3c2197d5ba4fef1fa9c943bcb0a2R135-R136 can be removed. |
StaticArrays cannot be mutated, so they need a fully non-mutating path. We should simply throw an error if |
We should do it slightly the other way around. Your version is a bit faster, so we should make your version be the one that is normally used, and we should send anything with |
…ver J is mutable.
…rsion instead of calling ForwardDiff.
great work, thanks! |
In ForwardDiff.jl, there is the ability to define an out-of-place function
f(x)
and autodiff it usingwhere
jac
is allocated outside ofForwardDiff.jacobian!
. I have a specific use case where it'd be nice to have such a functionality in SparseDiffTools.jl and have implemented it. The tests should pass.You may notice that I've defined
in addition to
I'm not too familiar with StaticArrays.jl, but I was unable to get one of the StaticArrays tests to pass when I used
instead of
To ensure I can mirror the function from ForwardDiff, I need the first line of code to work, but it seems to cause an error for StaticArrays.
Thus, to avoid changing the behavior of the package by too much, I just defined a version of
forwarddiff_color_jacobian
specifically whenJ
is a sparse matrix, since it should be safe to doJ .+= ...
The more general version offorwarddiff_color_jacobian
continues to useJ += ...
If you think that it'd be better to switch the two (i.e. write aforwarddiff_color_jacobian(J::StaticArray{<: Number}, ...)
and usingJ .+= ..
for the general version), then I'm happy to update the code.