Internal API

Linked List Sparse Matrix format

ExtendableSparse.SparseMatrixLNKType
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 correspondin to each pair (colptr[index],rowval[index])

    Initial length is n, it grows with each new entry.

source
Base.getindexMethod
getindex(lnk, i, j)

Return value stored for entry or zero if not found

source
Base.setindex!Method
setindex!(lnk, v, i, j)

Update value of existing entry, otherwise extend matrix if v is nonzero.

source
Base.sizeMethod
size(lnk)

Return tuple containing size of the matrix.

source
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.

source
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.

source

Some methods for SparseMatrixCSC

Base.:\Method
A

\ 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.

source
Base.:\Method
\(symm_ext, b)

\ for Hermitian{ExtendableSparse}

source
Base.:\Method
\(symm_ext, b)

\ for Symmetric{ExtendableSparse}

source
ExtendableSparse.eliminate_dirichletMethod
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]=1

for a node i marked as Dirichlet.

Returns B.

source
ExtendableSparse.findindexMethod
findindex(csc, i, j)

Return index corresponding to entry [i,j] in the array of nonzeros, if the entry exists, otherwise, return 0.

source
ExtendableSparse.flush!Method
flush!(csc)

Trival flush! method for allowing to run the code with both ExtendableSparseMatrix and SparseMatrixCSC.

source
ExtendableSparse.pattern_equalMethod
pattern_equal(a::SparseMatrixCSC,b::SparseMatrixCSC)

Check if sparsity patterns of two SparseMatrixCSC objects are equal. This is generally faster than comparing hashes.

source
ExtendableSparse.updateindex!Method
updateindex!(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
source

New API

Under development - aimed at multithreading

ExtendableSparse.AbstractSparseMatrixExtensionType
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 matrix
  • Base.+(ext::T_ext, csx) (optional) - Add extension matrix and csc/csr matrix, return csx matrix
  • rawupdateindex!(ext::Text, op, v, i, j, tid) where {Tv, Ti}: Set ext[i,j]op=v, possibly insert new entry into matrix. tid is a

task or partition id

source
Base.:\Method
A

\ 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.

source
Base.:\Method
\(symm_ext, b)

\ for Hermitian{ExtendableSparse}

source
Base.:\Method
\(symm_ext, b)

\ for Symmetric{ExtendableSparse}

source
ExtendableSparse.SparseMatrixDILNKCType
mutable 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.

source
Base.getindexMethod
getindex(lnk, i, j)

Return value stored for entry or zero if not found

source
Base.setindex!Method
setindex!(lnk, v, i, j)

Update value of existing entry, otherwise extend matrix if v is nonzero.

source
Base.sizeMethod
size(lnk)

Return tuple containing size of the matrix.

source
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.

source
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.

source

Misc methods

ExtendableSparse.@makefrommatrixMacro

" @makefrommatrix(fact)

For an AbstractFactorization MyFact, provide methods

    MyFact(A::ExtendableSparseMatrix; kwargs...)
    MyFact(A::SparseMatrixCSC; kwargs...)
source