Skip to content

Conversation

@gdalle
Copy link
Owner

@gdalle gdalle commented Oct 3, 2024

Fixes #64 and fixes #65 by optimizing structured coloring & decompression for these matrix types:

Package Type Optimal coloring Optimal decompression
LinearAlgebra Diagonal
LinearAlgebra Bidiagonal
LinearAlgebra Tridiagonal
BandedMatrices BandedMatrix no need
BlockBandedMatrices BlockBandedMatrix no need
BlockBandedMatrices BandedBlockBandedMatrix

For BandedMatrix and BlockBandedMatrix, the standard decompression based on SparseMatrixCSC will work fine because their storage is column-major (ref1, ref2). We only need a specific overload for BandedBlockBandedMatrix, which is a BlockMatrix of BandedMatrix-like blocks (so we need to decompress block by block).

General philosophy

Separate coloring from decompression:

  • For coloring, define a new StructuredColoringAlgorithm that uses optimal coloring formulas (note that for block-banded the coloring given here is not actually optimal if the blocks themselves are sparse).
  • For decompression, leverage the usual result type (ColumnColoringResult / RowColoringResult), which means that even greedy colorings on structured matrices benefit from optimized decompression.

Remaning issues

For decompression of BlockBandedMatrices, I still need to figure out JuliaArrays/BlockArrays.jl#418. But it already works because the fallback algorithm relies on the nonzeros of the sparse encoding, so it does not try to access illegal indices outside of the bands.

Implementation details

This is a clean rewrite of some code that was already present in ArrayInterface.jl and FiniteDiff.jl:

https://github.com/JuliaArrays/ArrayInterface.jl/blob/2e2b81bfb53e9e9fc41f26b927fb980afcbfa9f5/src/ArrayInterface.jl#L372-L384

https://github.com/JuliaArrays/ArrayInterface.jl/blob/2e2b81bfb53e9e9fc41f26b927fb980afcbfa9f5/ext/ArrayInterfaceBandedMatricesExt.jl#L68-L72

https://github.com/JuliaArrays/ArrayInterface.jl/blob/2e2b81bfb53e9e9fc41f26b927fb980afcbfa9f5/ext/ArrayInterfaceBlockBandedMatricesExt.jl#L207-L244

https://github.com/JuliaDiff/FiniteDiff.jl/blob/b574440c5d54708aa23a90c48f4a000dd1c6d915/ext/FiniteDiffBandedMatricesExt.jl#L13-L27

I still need to implement optimal decompression for block-banded matrices.

https://github.com/JuliaDiff/FiniteDiff.jl/blob/b574440c5d54708aa23a90c48f4a000dd1c6d915/ext/FiniteDiffBlockBandedMatricesExt.jl#L16-L68

@codecov
Copy link

codecov bot commented Oct 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (d6b9e65) to head (b24c181).

Additional details and impacted files
@@            Coverage Diff             @@
##              main      #139    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           17        20     +3     
  Lines         1939      2070   +131     
==========================================
+ Hits          1939      2070   +131     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gdalle gdalle closed this Oct 4, 2024
@gdalle gdalle deleted the gd/structured3 branch October 4, 2024 08:41
@gdalle gdalle restored the gd/structured3 branch October 6, 2024 14:59
@gdalle gdalle reopened this Oct 6, 2024
@gdalle gdalle changed the base branch from gd/structured2-test to main October 6, 2024 14:59
@gdalle gdalle marked this pull request as ready for review October 7, 2024 10:46
@gdalle gdalle marked this pull request as draft October 7, 2024 19:31
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.

Optimized coloring for specific matrix types Optimized decompression for specific matrix types

1 participant