Internal API
Linked List Sparse Matrix format
ExtendableSparse.SparseMatrixLNK
— Typemutable 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 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
SparseArrays.SparseMatrixCSC
— MethodSparseMatrixCSC(A)
Create SparseMatrixCSC from ExtendableSparseMatrix
Base.:*
— Method*(d, ext)
Base.:*
— Method*(ext, d)
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.:\
— MethodA
\
for ExtendableSparse. It calls the LU factorization form Sparspak.jl, unless GPL components are allowed in the Julia sysimage and the floating point type of the matrix is Float64 or Complex64. In that case, Julias standard `` is called, which is realized via UMFPACK.
Base.:\
— Method\(symm_ext, b)
\
for Hermitian{ExtendableSparse}
Base.:\
— Method\(symm_ext, b)
\
for Symmetric{ExtendableSparse}
Base.eltype
— Methodeltype(_)
Return element type.
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
LinearAlgebra.cond
— Functioncond(A)
cond(A, p)
flush!
and calculate cond from cscmatrix
LinearAlgebra.issymmetric
— Methodissymmetric(A)
flush!
and check for symmetry of cscmatrix
LinearAlgebra.ldiv!
— Methodldiv!(r, ext, x)
flush!
and ldiv with ext.cscmatrix
LinearAlgebra.mul!
— Methodmul!(r, ext, x)
flush!
and multiply with ext.cscmatrix
LinearAlgebra.norm
— Functionnorm(A)
norm(A, p)
flush!
and calculate norm from cscmatrix
LinearAlgebra.opnorm
— Functionopnorm(A)
opnorm(A, p)
flush!
and calculate opnorm from cscmatrix
SparseArrays.dropzeros!
— Methoddropzeros!(ext)
SparseArrays.findnz
— Methodfindnz(ext)
flush!
and return findnz(ext.cscmatrix).
SparseArrays.getcolptr
— Methodgetcolptr(ext)
flush!
and return colptr of in ext.cscmatrix.
SparseArrays.nnz
— Methodnnz(ext)
flush!
and return number of nonzeros in ext.cscmatrix.
SparseArrays.nonzeros
— Methodnonzeros(ext)
flush!
and return nonzeros in ext.cscmatrix.
SparseArrays.rowvals
— Methodrowvals(ext)
flush!
and return rowvals in ext.cscmatrix.
New API
Under development - aimed at multithreading
ExtendableSparse.AbstractSparseMatrixExtension
— Typeabstract 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.tid
is a
task or partition id
SparseArrays.SparseMatrixCSC
— MethodSparseMatrixCSC(A)
Create SparseMatrixCSC from ExtendableSparseMatrix
Base.:*
— Method*(d, ext)
Base.:*
— Method*(ext, d)
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.:\
— MethodA
\
for ExtendableSparse. It calls the LU factorization form Sparspak.jl, unless GPL components are allowed in the Julia sysimage and the floating point type of the matrix is Float64 or Complex64. In that case, Julias standard `` is called, which is realized via UMFPACK.
Base.:\
— Method\(symm_ext, b)
\
for Hermitian{ExtendableSparse}
Base.:\
— Method\(symm_ext, b)
\
for Symmetric{ExtendableSparse}
Base.eltype
— Methodeltype(_)
Return element type.
LinearAlgebra.cond
— Functioncond(A)
cond(A, p)
flush!
and calculate cond from cscmatrix
LinearAlgebra.issymmetric
— Methodissymmetric(A)
flush!
and check for symmetry of cscmatrix
LinearAlgebra.ldiv!
— Methodldiv!(r, ext, x)
flush!
and ldiv with ext.cscmatrix
LinearAlgebra.mul!
— Methodmul!(r, ext, x)
flush!
and multiply with ext.cscmatrix
LinearAlgebra.norm
— Functionnorm(A)
norm(A, p)
flush!
and calculate norm from cscmatrix
LinearAlgebra.opnorm
— Functionopnorm(A)
opnorm(A, p)
flush!
and calculate opnorm from cscmatrix
SparseArrays.dropzeros!
— Methoddropzeros!(ext)
SparseArrays.findnz
— Methodfindnz(ext)
flush!
and return findnz(ext.cscmatrix).
SparseArrays.getcolptr
— Methodgetcolptr(ext)
flush!
and return colptr of in ext.cscmatrix.
SparseArrays.nnz
— Methodnnz(ext)
flush!
and return number of nonzeros in ext.cscmatrix.
SparseArrays.nonzeros
— Methodnonzeros(ext)
flush!
and return nonzeros in ext.cscmatrix.
SparseArrays.rowvals
— Methodrowvals(ext)
flush!
and return rowvals in ext.cscmatrix.
ExtendableSparse.SparseMatrixDILNKC
— MethodSparseMatrixDILNKC(m, n)
Constructor of empty matrix.
ExtendableSparse.SparseMatrixDILNKC
— MethodSparseMatrixDILNKC(csc)
Constructor from SparseMatrixCSC.
ExtendableSparse.SparseMatrixDILNKC
— MethodSparseMatrixDILNKC(m, n)
Constructor of empty matrix.
ExtendableSparse.SparseMatrixDILNKC
— MethodSparseMatrixDILNKC(valuetype, indextype, m, n)
Constructor of empty matrix.
ExtendableSparse.SparseMatrixDILNKC
— MethodSparseMatrixDILNKC(valuetype, m, n)
Constructor of empty matrix.
ExtendableSparse.SparseMatrixDILNKC
— Typemutable struct SparseMatrixDILNKC{Tv, Ti<:Integer} <: ExtendableSparse.AbstractSparseMatrixExtension{Tv, Ti<:Integer}
Modification of SparseMatrixLNK where the pointer to first index of
column j is stored in a dictionary.
SparseArrays.SparseMatrixCSC
— MethodSparseMatrixCSC(lnk)
Constructor from SparseMatrixDILNKC.
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.add_directly
— Methodadd_directly(lnk, csc)
Add lnk and csc without creation of intermediate data. (to be fixed)
ExtendableSparse.add_via_COO
— Methodadd_via_COO(lnk, csc)
Add lnk and csc via interim COO (coordinate) format, i.e. arrays I,J,V.
ExtendableSparse.addentry!
— Methodaddentry!(lnk, i, j, k, k0)
Add entry.
ExtendableSparse.findindex
— Methodfindindex(lnk, i, j)
Find index in matrix.
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.
Misc methods
ExtendableSparse.@makefrommatrix
— Macro" @makefrommatrix(fact)
For an AbstractFactorization MyFact
, provide methods
MyFact(A::ExtendableSparseMatrix; kwargs...)
MyFact(A::SparseMatrixCSC; kwargs...)