Skip to content
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

Add fast path for forwarddiff_color_jacobian! with sparse J #146

Merged
merged 4 commits into from
Jul 20, 2021
Merged

Add fast path for forwarddiff_color_jacobian! with sparse J #146

merged 4 commits into from
Jul 20, 2021

Conversation

sjdaines
Copy link

@sjdaines sjdaines commented Jul 18, 2021

Partial fix for #138 #100

Add a fast path for the case where J and sparsity are are both SparseMatrixCSC
and have the same sparsity pattern.

Partial fix for #138

Bodges in a fast path for the case where J and sparsity are are both SparseMatrixCSC
and have the same number of columns and stored values.
@codecov-commenter
Copy link

codecov-commenter commented Jul 18, 2021

Codecov Report

Merging #146 (b968680) into master (e798411) will increase coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #146      +/-   ##
==========================================
+ Coverage   83.05%   83.10%   +0.05%     
==========================================
  Files          12       12              
  Lines         667      669       +2     
==========================================
+ Hits          554      556       +2     
  Misses        113      113              
Impacted Files Coverage Δ
src/differentiation/compute_jacobian_ad.jl 93.04% <100.00%> (+0.11%) ⬆️
src/coloring/high_level.jl 100.00% <0.00%> (ø)
src/coloring/matrix2graph.jl 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e798411...b968680. Read the comment docs.

@@ -316,3 +333,17 @@ function forwarddiff_color_jacobian!(J::AbstractMatrix{<:Number},
end
return J
end

# fast version of FiniteDiff._colorediteration! for the case where J and sparsity have the same sparsity pattern
@inline function _colorediteration!(Jsparsity::SparseMatrixCSC,vfx,colorvec,color_i,ncols)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this just go to FiniteDiff.jl?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sjdaines
Copy link
Author

sjdaines commented Jul 18, 2021

OK done... now requires PR JuliaDiff/FiniteDiff.jl#124 (however admit I don't fully understand how this could work and might be proliferating cut-and-paste cases instead of sane dispatches).

Now we have:

  1. add a _use_sparseCSC_common_sparsity!(J, sparsity) test function to FiniteDiff.iteration_utils.
  2. move the new _colorediteration!(Jsparsity::SparseMatrixCSC,vfx,colorvec,color_i,ncols) to FiniteDiff.iteration_utils
  3. FiniteDiff.finite_difference_jacobian! uses the same optimisation (although doesn't look like anyone has hit this problem there?)

Simplifies fast path logic.
All other cases (J is not a SparseMatrixCSC, or J has a different sparsity
pattern) use previous slow path.
@ChrisRackauckas
Copy link
Member

Add a lower bound on 2.8.1

@ChrisRackauckas ChrisRackauckas merged commit ae26f23 into JuliaDiff:master Jul 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants