Sparse Matrix Functions

Internal Sparse Matrix Representation

ConleyDynamics.SparseMatrixType
SparseMatrix{T}

Composite data type for a sparse matrix with entries of type T.

The struct has the following fields:

  • const nrow::Int: Number of rows
  • const ncol::Int: Number of columns
  • const char::Int: Characteristic of type T
  • const zero::T: Number 0 of type T
  • const one::T: Number 1 of type T
  • entries::Vector{Vector{T}}: Matrix entries corresponding to columns
  • columns::Vector{Vector{Int}}: columns[k] points to nonzero entries in column k
  • rows::Vector{Vector{Int}}: rows[k] points to nonzero entries in the k-th row
source

Access Functions

Base.getindexMethod
Base.getindex(matrix::SparseMatrix, ri::Int, ci::Int)

Get the sparse matrix entry at location (ri,ci).

source
ConleyDynamics.sparse_set_entry!Function
sparse_set_entry!(matrix::SparseMatrix, ri::Int, ci::Int, val)

Set the sparse matrix entry at location (ri,ci) to val.

source
sparse_set_entry!(matrix::SparseMatrix{Int}, ri::Int, ci::Int, val)

Set the sparse matrix entry at location (ri,ci) to val.

This method assumes that the sparse matrix is over the integers, which means that it is interpreted over a finite field. Thus, the new entry is automatically reduced via modular arithmetic.

source
Base.setindex!Method
Base.setindex!(matrix::SparseMatrix, val, ri::Int, ci::Int)

Set the sparse matrix entry at location (ri,ci) to val.

source
ConleyDynamics.sparse_minorFunction
smp = sparse_minor(sm::SparseMatrix, rvec::Vector{Int}, cvec::Vector{Int})

Create sparse submatrix by specifying the desired row and column indices.

source

Basic Functions

ConleyDynamics.sparse_identityFunction
sparse_identity(n::Int; p::Int=0)

Create a sparse identity matrix with n rows and columns.

The optional argument p specifies the field characteristic. If p=0 then the sparse matrix is over the rationals, while if p>0 is a prime, then the matrix is an integer matrix whose entries are interpreted in GF(p).

source
ConleyDynamics.sparse_zeroFunction
sparse_zero(nr::Int, nc::Int; p::Int=0)

Create a sparse zero matrix with nr rows and nc columns.

The optional argument p specifies the field characteristic. If p=0 then the sparse matrix is over the rationals, while if p>0 is a prime, then the matrix is an integer matrix whose entries are interpreted in GF(p).

source

Elementary Matrix Operations

ConleyDynamics.sparse_add_column!Function
sparse_add_column!(matrix::SparseMatrix, ci1::Int, ci2::Int, cn, cd)

Replace column[ci1] by column[ci1] + (cn/cd) * column[ci2].

source
sparse_add_column!(matrix::SparseMatrix{Int}, ci1::Int, ci2::Int,
                   cn::Int, cd::Int)

Replace column[ci1] by column[ci1] + (cn/cd) * column[ci2].

The computation is performed mod p, where the characteristic is taken from matrix.char. An error is thrown if matrix.char==0.

source
ConleyDynamics.sparse_add_row!Function
sparse_add_row!(matrix::SparseMatrix, ri1::Int, ri2::Int, cn, cd)

Replace row[ri1] by row[ri1] + (cn/cd) * row[ri2].

source
sparse_add_row!(matrix::SparseMatrix{Int}, ri1::Int, ri2::Int,
                cn::Int, cd::Int)

Replace row[ri1] by row[ri1] + (cn/cd) * row[ri2].

The computation is performed mod p, where the characteristic is taken from matrix.char. An error is thrown if matrix.char==0.

source
ConleyDynamics.sparse_permuteFunction
sparse_permute(sm::SparseMatrix, pr::Vector{Int}, pc::Vector{Int})

Create sparse matrix by permuting the row and column indices.

The vector pr describes the row permutation, and pc the column permutation.

source
ConleyDynamics.sparse_inverseFunction
sparse_inverse(matrix::SparseMatrix)

Compute the inverse of a sparse matrix.

The function automatically performs the computations over the underlying field of the sparse matrix.

source
ConleyDynamics.sparse_addFunction
sparse_add(A::SparseMatrix, B::SparseMatrix)

Add two sparse matrices.

Exceptions are raised if the matrix sum is not defined or the entry types do not match.

source
ConleyDynamics.sparse_subtractFunction
sparse_subtract(A::SparseMatrix, B::SparseMatrix)

Subtract two sparse matrices.

The function returns A - B. Exceptions are raised if the matrix difference is not defined or the entry types do not match.

source
ConleyDynamics.sparse_multiplyFunction
sparse_multiply(A::SparseMatrix, B::SparseMatrix)

Multiply two sparse matrices.

Exceptions are raised if the matrix product is not defined or the entry types do not match.

source
ConleyDynamics.sparse_scaleFunction
sparse_scale(sfac, A::SparseMatrix)

Scale a sparse matrix by a scalar.

An exception is raised if the entry types do not match.

source
Base.:+Method
Base.:+(A::SparseMatrix, B::SparseMatrix)

Add two sparse matrices.

Exceptions are raised if the matrix sum is not defined or the entry types do not match.

source
Base.:-Method
Base.:-(A::SparseMatrix, B::SparseMatrix)

Subtract two sparse matrices.

Exceptions are raised if the matrix difference is not defined or the entry types do not match.

source
Base.:*Method
Base.:*(A::SparseMatrix, B::SparseMatrix)

Multiply two sparse matrices.

Exceptions are raised if the matrix product is not defined or the entry types do not match.

source
Base.:*Method
Base.:*(sfac, A::SparseMatrix)

Compute the scalar product of sfac and the sparse matrix A.

An exception is raised if the scalar sfac does not have the same type as the matrix entries.

source

Conversion Functions

ConleyDynamics.sparse_from_fullFunction
sparse_from_full(matrix::Matrix{Int}; [p::Int=0])

Create sparse matrix from full integer matrix. If the optional argument p is specified and positive, then the returned matrix is an integer matrix which is interpreted over GF(p). On the other hand, if p is omitted or equal to zero, then the return matrix has rational type.

source
ConleyDynamics.sparse_from_listsFunction
sparse_from_lists(nr, nc, tchar, tzero, tone, r, c, v)

Create sparse matrix from lists describing the entries.

The vectors r, c, and v have to have the same length and the matrix has entry v[k] at (r[k],c[k]). Zero entries will be ignored, and multiple entries for the same matrix position raise an error.

The input arguments have the following meaning:

  • nr::Int: Number of rows
  • nc::Int: Number of columns
  • tchar: Field characteristic if T==Int
  • tzero::T: Number 0 of type T
  • tone::T: Number 1 of type T
  • r::Vector{Int}: Vector of row indices
  • c::Vector{Int}: Vector of column indices
  • v::Vector{T}: Vector of matrix entries

If tchar>0, then the entries in v are all replaced by their values mod tchar.

source
ConleyDynamics.lists_from_sparseFunction
nr, nc, tchar, tzero, tone, r, c, v = lists_from_sparse(sm::SparseMatrix)

Create list representation from sparse matrix.

The output variables are exactly what is needed to create a sparse matrix object using sparse_from_lists.

source

Sparse Helper Functions

ConleyDynamics.scalar_inverseFunction
scalar_inverse(s, p::Int)

Compute the inverse of a scalar.

source
scalar_inverse(s::Int, p::Int)

Compute the inverse of a scalar.

This function computes the inverse in modular arithmetic with base p.

source