Internal API

Linked List Sparse Matrix format

ExtendableSparse.SparseMatrixLNKType
mutable 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.

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

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

Misc methods

ExtendableSparse.@makefrommatrixMacro

" @makefrommatrix(fact)

For an AbstractFactorization MyFact, provide methods

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