Internal API
Linked List Sparse Matrix format
ExtendableSparse.SparseMatrixLNK — Type
mutable struct SparseMatrixLNK{Tv, Ti<:Integer} <: ExtendableSparse.AbstractSparseMatrixExtension{Tv, Ti<:Integer}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 corresponding to each pair (colptr[index],rowval[index])Initial length is n, it grows with each new entry.
ExtendableSparse.SparseMatrixLNK — Method
SparseMatrixLNK(m, n)
Constructor of empty matrix.
ExtendableSparse.SparseMatrixLNK — Method
SparseMatrixLNK(csc)
Constructor from SparseMatrixCSC.
ExtendableSparse.SparseMatrixLNK — Method
SparseMatrixLNK(m, n)
Constructor of empty matrix.
ExtendableSparse.SparseMatrixLNK — Method
SparseMatrixLNK(valuetype, indextype, m, n)
Constructor of empty matrix.
ExtendableSparse.SparseMatrixLNK — Method
SparseMatrixLNK(valuetype, m, n)
Constructor of empty matrix.
SparseArrays.SparseMatrixCSC — Method
SparseMatrixCSC(lnk)
Constructor from SparseMatrixLNK.
Base.:+ — Method
+(lnk, csc)
Add SparseMatrixCSC matrix and SparseMatrixLNK lnk, returning a SparseMatrixCSC
Base.getindex — Method
getindex(lnk, i, j)
Return value stored for entry or zero if not found
Base.setindex! — Method
setindex!(lnk, v, i, j)
Update value of existing entry, otherwise extend matrix if v is nonzero.
ExtendableSparse.flush! — Method
flush!(lnk)
Dummy flush! method for SparseMatrixLNK. Just used in test methods
ExtendableSparse.rawupdateindex! — Method
rawupdateindex!(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! — Method
updateindex!(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 — Method
nnz(lnk)
Return number of nonzero entries.
Some methods for SparseMatrixCSC
SparseArrays.SparseMatrixCSC — Method
SparseMatrixCSC(A)
Create SparseMatrixCSC from ExtendableSparseMatrix
Base.:+ — Method
+(ext, csc)
Add SparseMatrixCSC matrix and ExtendableSparseMatrix ext.
Base.:- — Method
-(ext, csc)
Subtract SparseMatrixCSC matrix from ExtendableSparseMatrix ext.
Base.:- — Method
-(csc, ext)
Subtract ExtendableSparseMatrix ext from SparseMatrixCSC.
Base.eltype — Method
eltype(_)
Return element type.
ExtendableSparse.eliminate_dirichlet! — Method
eliminate_dirichlet!(A,dirichlet_marker)Eliminate dirichlet nodes in matrix by setting
A[:,i]=0; A[i,:]=0; A[i,i]=1for a node i marked as Dirichlet.
Returns A.
ExtendableSparse.eliminate_dirichlet — Method
eliminate_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]=1for a node i marked as Dirichlet.
Returns B.
ExtendableSparse.findindex — Method
findindex(csc, i, j)
Return index corresponding to entry [i,j] in the array of nonzeros, if the entry exists, otherwise, return 0.
ExtendableSparse.flush! — Method
flush!(csc)
Trivial flush! method for allowing to run the code with both ExtendableSparseMatrix and SparseMatrixCSC.
ExtendableSparse.mark_dirichlet — Method
mark_dirichlet(A; penalty=1.0e20)
Return boolean vector marking Dirichlet nodes, known by A[i,i]>=penalty
ExtendableSparse.pattern_equal — Method
pattern_equal(a::SparseMatrixCSC,b::SparseMatrixCSC)Check if sparsity patterns of two SparseMatrixCSC objects are equal. This is generally faster than comparing hashes.
ExtendableSparse.phash — Method
phash(csc)
Hash of csc matrix pattern.
ExtendableSparse.updateindex! — Method
updateindex!(csc, op, v, i, j)
Update element of the matrix with operation op without introducing new nonzero elements.
This can replace the following code and save one index search during access:
using ExtendableSparse # hide
using SparseArrays # hide
A=spzeros(3,3)
A[1,2]+=0.1
Ausing ExtendableSparse # hide
using SparseArrays # hide
A=spzeros(3,3)
updateindex!(A,+,0.1,1,2)
ALinearAlgebra.cond — Function
cond(A)
cond(A, p)
flush! and calculate cond from cscmatrix
LinearAlgebra.issymmetric — Method
issymmetric(A)
flush! and check for symmetry of cscmatrix
LinearAlgebra.ldiv! — Method
ldiv!(r, ext, x)
flush! and ldiv with ext.cscmatrix
LinearAlgebra.mul! — Method
mul!(r, ext, x)
flush! and multiply with ext.cscmatrix
LinearAlgebra.norm — Function
norm(A)
norm(A, p)
flush! and calculate norm from cscmatrix
LinearAlgebra.opnorm — Function
opnorm(A)
opnorm(A, p)
flush! and calculate opnorm from cscmatrix
SparseArrays.dropzeros! — Method
dropzeros!(ext)
SparseArrays.findnz — Method
findnz(ext)
flush! and return findnz(ext.cscmatrix).
SparseArrays.getcolptr — Method
getcolptr(ext)
flush! and return colptr of in ext.cscmatrix.
SparseArrays.nnz — Method
nnz(ext)
flush! and return number of nonzeros in ext.cscmatrix.
SparseArrays.nonzeros — Method
nonzeros(ext)
flush! and return nonzeros in ext.cscmatrix.
SparseArrays.rowvals — Method
rowvals(ext)
flush! and return rowvals in ext.cscmatrix.
New API
Under development - aimed at multithreading
ExtendableSparse.AbstractSparseMatrixExtension — Type
abstract type AbstractSparseMatrixExtension{Tv, Ti} <: SparseArrays.AbstractSparseArray{Tv, Ti, 2}Abstract type for sparse matrix extension.
Subtypes T_ext must implement:
- Constructor
T_ext(m,n) SparseArrays.nnz(ext::T_ext)Base.size(ext::T_ext)Base.sum(extmatrices::Vector{T_ext}, csx): add csr or csc matrix and extension matrices (one per partition) and return csx matrixBase.+(ext::T_ext, csx)(optional) - Add extension matrix and csc/csr matrix, return csx matrixrawupdateindex!(ext::Text, op, v, i, j, tid) where {Tv, Ti}: Setext[i,j]op=v, possibly insert new entry into matrix.tidis a
task or partition id
SparseArrays.SparseMatrixCSC — Method
SparseMatrixCSC(A)
Create SparseMatrixCSC from ExtendableSparseMatrix
Base.:+ — Method
+(ext, csc)
Add SparseMatrixCSC matrix and ExtendableSparseMatrix ext.
Base.:- — Method
-(ext, csc)
Subtract SparseMatrixCSC matrix from ExtendableSparseMatrix ext.
Base.:- — Method
-(csc, ext)
Subtract ExtendableSparseMatrix ext from SparseMatrixCSC.
Base.eltype — Method
eltype(_)
Return element type.
LinearAlgebra.cond — Function
cond(A)
cond(A, p)
flush! and calculate cond from cscmatrix
LinearAlgebra.issymmetric — Method
issymmetric(A)
flush! and check for symmetry of cscmatrix
LinearAlgebra.ldiv! — Method
ldiv!(r, ext, x)
flush! and ldiv with ext.cscmatrix
LinearAlgebra.mul! — Method
mul!(r, ext, x)
flush! and multiply with ext.cscmatrix
LinearAlgebra.norm — Function
norm(A)
norm(A, p)
flush! and calculate norm from cscmatrix
LinearAlgebra.opnorm — Function
opnorm(A)
opnorm(A, p)
flush! and calculate opnorm from cscmatrix
SparseArrays.dropzeros! — Method
dropzeros!(ext)
SparseArrays.findnz — Method
findnz(ext)
flush! and return findnz(ext.cscmatrix).
SparseArrays.getcolptr — Method
getcolptr(ext)
flush! and return colptr of in ext.cscmatrix.
SparseArrays.nnz — Method
nnz(ext)
flush! and return number of nonzeros in ext.cscmatrix.
SparseArrays.nonzeros — Method
nonzeros(ext)
flush! and return nonzeros in ext.cscmatrix.
SparseArrays.rowvals — Method
rowvals(ext)
flush! and return rowvals in ext.cscmatrix.
ExtendableSparse.SparseMatrixDILNKC — Method
SparseMatrixDILNKC(m, n)
Constructor of empty matrix.
ExtendableSparse.SparseMatrixDILNKC — Method
SparseMatrixDILNKC(csc)
Constructor from SparseMatrixCSC.
ExtendableSparse.SparseMatrixDILNKC — Method
SparseMatrixDILNKC(m, n)
Constructor of empty matrix.
ExtendableSparse.SparseMatrixDILNKC — Method
SparseMatrixDILNKC(valuetype, indextype, m, n)
Constructor of empty matrix.
ExtendableSparse.SparseMatrixDILNKC — Method
SparseMatrixDILNKC(valuetype, m, n)
Constructor of empty matrix.
ExtendableSparse.SparseMatrixDILNKC — Type
mutable struct SparseMatrixDILNKC{Tv, Ti<:Integer} <: ExtendableSparse.AbstractSparseMatrixExtension{Tv, Ti<:Integer}Modification of SparseMatrixLNK where the pointer to first index ofcolumn j is stored in a dictionary.
SparseArrays.SparseMatrixCSC — Method
SparseMatrixCSC(lnk)
Constructor from SparseMatrixDILNKC.
Base.getindex — Method
getindex(lnk, i, j)
Return value stored for entry or zero if not found
Base.setindex! — Method
setindex!(lnk, v, i, j)
Update value of existing entry, otherwise extend matrix if v is nonzero.
ExtendableSparse.add_directly — Method
add_directly(lnk, csc)
Add lnk and csc without creation of intermediate data. (to be fixed)
ExtendableSparse.add_via_COO — Method
add_via_COO(lnk, csc)
Add lnk and csc via interim COO (coordinate) format, i.e. arrays I,J,V.
ExtendableSparse.addentry! — Method
addentry!(lnk, i, j, k, k0)
Add entry.
ExtendableSparse.findindex — Method
findindex(lnk, i, j)
Find index in matrix.
ExtendableSparse.rawupdateindex! — Method
rawupdateindex!(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! — Method
updateindex!(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 — Method
nnz(lnk)
Return number of nonzero entries.
Misc methods
ExtendableSparse.@makefrommatrix — Macro
" @makefrommatrix(fact)
For an AbstractFactorization MyFact, provide methods
MyFact(A::ExtendableSparseMatrix; kwargs...)
MyFact(A::SparseMatrixCSC; kwargs...)