Internal API
Linked List Sparse Matrix format
ExtendableSparse.SparseMatrixLNK
— Typemutable struct SparseMatrixLNK{Tv, Ti<:Integer} <: SparseArrays.AbstractSparseArray{Tv, Ti<:Integer, 2}
Struct to hold sparse matrix in the linked list format.
Modeled after the linked list sparse matrix format described in the whitepaper and the SPARSEKIT2 source code by Y. Saad. He writes "This is one of the oldest data structures used for sparse matrix computations."
The relevant source formats.f is also available in the debian/science gitlab.
The advantage of the linked list structure is the fact that upon insertion of a new entry, the arrays describing the structure can grow at their respective ends and can be conveniently updated via push!
. No copying of existing data is necessary.
m::Integer
: Number of rows
n::Integer
: Number of columns
nnz::Integer
: Number of nonzeros
nentries::Integer
: Length of arrays
colptr::Vector{Ti} where Ti<:Integer
: Linked list of column entries. Initial length is n, it grows with each new entry.colptr[index] contains the next index in the list or zero, in the later case terminating the list which starts at index 1<=j<=n for each column j.
rowval::Vector{Ti} where Ti<:Integer
: Row numbers. For each index it contains the zero (initial state) or the row numbers corresponding to the column entry list in colptr.Initial length is n, it grows with each new entry.
nzval::Vector
: Nonzero entry values correspondin to each pair (colptr[index],rowval[index])Initial length is n, it grows with each new entry.
ExtendableSparse.SparseMatrixLNK
— MethodSparseMatrixLNK(m, n)
Constructor of empty matrix.
ExtendableSparse.SparseMatrixLNK
— MethodSparseMatrixLNK(csc)
Constructor from SparseMatrixCSC.
ExtendableSparse.SparseMatrixLNK
— MethodSparseMatrixLNK(m, n)
Constructor of empty matrix.
ExtendableSparse.SparseMatrixLNK
— MethodSparseMatrixLNK(valuetype, indextype, m, n)
Constructor of empty matrix.
ExtendableSparse.SparseMatrixLNK
— MethodSparseMatrixLNK(valuetype, m, n)
Constructor of empty matrix.
SparseArrays.SparseMatrixCSC
— MethodSparseMatrixCSC(lnk)
Constructor from SparseMatrixLNK.
Base.:+
— Method+(lnk, csc)
Add SparseMatrixCSC matrix and SparseMatrixLNK
lnk, returning a SparseMatrixCSC
Base.getindex
— Methodgetindex(lnk, i, j)
Return value stored for entry or zero if not found
Base.setindex!
— Methodsetindex!(lnk, v, i, j)
Update value of existing entry, otherwise extend matrix if v is nonzero.
Base.size
— Methodsize(lnk)
Return tuple containing size of the matrix.
ExtendableSparse.flush!
— Methodflush!(lnk)
Dummy flush! method for SparseMatrixLNK. Just used in test methods
ExtendableSparse.rawupdateindex!
— Methodrawupdateindex!(lnk, op, v, i, j)
Update element of the matrix with operation op
. It assumes that op(0,0)==0
. If v
is zero a new entry is created nevertheless.
ExtendableSparse.updateindex!
— Methodupdateindex!(lnk, op, v, i, j)
Update element of the matrix with operation op
. It assumes that op(0,0)==0
. If v
is zero, no new entry is created.
SparseArrays.nnz
— Methodnnz(lnk)
Return number of nonzero entries.
Some methods for SparseMatrixCSC
ExtendableSparse.eliminate_dirichlet!
— Methodeliminate_dirichlet!(A,dirichlet_marker)
Eliminate dirichlet nodes in matrix by setting
A[:,i]=0; A[i,:]=0; A[i,i]=1
for a node i
marked as Dirichlet.
Returns A.
ExtendableSparse.eliminate_dirichlet
— Methodeliminate_dirichlet(A,dirichlet_marker)
Create a copy B of A sharing the sparsity pattern. Eliminate dirichlet nodes in B by setting
B[:,i]=0; B[i,:]=0; B[i,i]=1
for a node i
marked as Dirichlet.
Returns B.
ExtendableSparse.findindex
— Methodfindindex(csc, i, j)
Return index corresponding to entry [i,j] in the array of nonzeros, if the entry exists, otherwise, return 0.
ExtendableSparse.flush!
— Methodflush!(csc)
Trival flush! method for allowing to run the code with both ExtendableSparseMatrix
and SparseMatrixCSC
.
ExtendableSparse.mark_dirichlet
— Methodmark_dirichlet(A; penalty=1.0e20)
Return boolean vector marking Dirichlet nodes, known by A[i,i]>=penalty
ExtendableSparse.pattern_equal
— Methodpattern_equal(a::SparseMatrixCSC,b::SparseMatrixCSC)
Check if sparsity patterns of two SparseMatrixCSC objects are equal. This is generally faster than comparing hashes.
ExtendableSparse.phash
— Methodphash(csc)
Hash of csc matrix pattern.
ExtendableSparse.updateindex!
— Methodupdateindex!(csc, op, v, i, j)
Update element of the matrix with operation op
whithout introducing new nonzero elements.
This can replace the following code and save one index search during acces:
using ExtendableSparse # hide
using SparseArrays # hide
A=spzeros(3,3)
A[1,2]+=0.1
A
using ExtendableSparse # hide
using SparseArrays # hide
A=spzeros(3,3)
updateindex!(A,+,0.1,1,2)
A
Misc methods
ExtendableSparse.@makefrommatrix
— Macro" @makefrommatrix(fact)
For an AbstractFactorization MyFact
, provide methods
MyFact(A::ExtendableSparseMatrix; kwargs...)
MyFact(A::SparseMatrixCSC; kwargs...)