SparsityDetection.jl icon indicating copy to clipboard operation
SparsityDetection.jl copied to clipboard

Structured Matrix Detection

Open ChrisRackauckas opened this issue 5 years ago • 5 comments

If the sparse matrix actually has structure, it would be nice to have a way to detect that and return the structured matrix type.

ChrisRackauckas avatar Oct 31 '19 16:10 ChrisRackauckas

If the sparse matrix actually has structure

Which matrix? :-)

shashi avatar Feb 06 '20 03:02 shashi

I think it's just determine_structure(A::SparseMatrixCSC). Completely not type-stable of course, but analyses the sparsity pattern and spits out the matrix type.

ChrisRackauckas avatar Feb 06 '20 04:02 ChrisRackauckas

Does anyone have that function somewhere?

shashi avatar Feb 06 '20 04:02 shashi

Not that I know of. There are pieces of it in factorize:

https://github.com/JuliaLang/julia/blob/2fcb1b16fc734be41ebf348ddfe37809b081f027/stdlib/LinearAlgebra/src/dense.jl#L1196-L1224

I'd also want to catch if it's Banded, BlockBanded, or BandedBlockBanded. @dlfivefifty are constructors from sparse matrices implemented anywhere for those?

ChrisRackauckas avatar Feb 06 '20 04:02 ChrisRackauckas

Constructors to sparse are implemented (sparse(::BandedMatrix)). From sparse is not but should be pretty easy, at least for banded: only need to overload bandwidths(A::SparseMatrixCSC). Something like this (though should be rewritten not to allocate):

function bandwidths(A::SparseMatrixCSC)
    Is, Js = ??? # Don't remember how to get the I and J indices from a sparse matrix
    maximum(Is - Js),maximum(Js - Is)
end

dlfivefifty avatar Feb 06 '20 13:02 dlfivefifty