A fast implementation of Sparse Banded Matrices in Julia. Primarily developed for use in a Butterfly LU factorization implemented in RecursiveFactorization.jl and LinearSolve.jl.
using SparseBandedMatrices
# Create an empty 5×5 sparse banded matrix
A = SparseBandedMatrix{Float64}(undef, 5, 5)
A[1,1] = 5.0
# Set a lower diagonal with the values [3.0, 4.0, 5.0]
setdiagonal!(A, [3.0, 4.0, 5.0], true)
# Create a matrix with pre-specified diagonals
# This creates a 6×6 matrix with diagonals at indices 1 and 8
B = SparseBandedMatrix{Float64}([1, 8], [[3.0], [-2.0, 5.0, 1.0, 3.0]], 6, 6)The implementation of SparseBandedMatrices is designed to be fast for matrix-matrix and matrix-vector multiplications. The sparse banded structure provides significant performance advantages when working with matrices that have a limited number of non-zero diagonals, which commonly arise in:
- Butterfly LU factorizations (see RecursiveFactorization.jl)
- Linear system solving (see LinearSolve.jl)
- Finite difference discretizations
- Other sparse linear algebra problems with banded structure