Sparse Matrix Functions
Internal Sparse Matrix Representation
ConleyDynamics.SparseMatrix
— TypeSparseMatrix{T}
Composite data type for a sparse matrix with entries of type T
.
The struct has the following fields:
const nrow::Int
: Number of rowsconst ncol::Int
: Number of columnsconst char::Int
: Characteristic of typeT
const zero::T
: Number 0 of typeT
const one::T
: Number 1 of typeT
entries::Vector{Vector{T}}
: Matrix entries corresponding tocolumns
columns::Vector{Vector{Int}}
:column[k]
points to nonzero entries in column krows::Vector{Vector{Int}}
:rows[k]
points to nonzero entries in the k-th row
Access Functions
ConleyDynamics.sparse_get_entry
— Functionsparse_get_entry(matrix::SparseMatrix, ri::Int, ci::Int)
Get the sparse matrix entry at location (ri,ci)
.
Base.getindex
— MethodBase.getindex(matrix::SparseMatrix, ri::Int, ci::Int)
Get the sparse matrix entry at location (ri,ci)
.
ConleyDynamics.sparse_set_entry!
— Functionsparse_set_entry!(matrix::SparseMatrix, ri::Int, ci::Int, val)
Set the sparse matrix entry at location (ri,ci)
to val
.
Base.setindex!
— MethodBase.setindex!(matrix::SparseMatrix, val, ri::Int, ci::Int)
Set the sparse matrix entry at location (ri,ci)
to val
.
ConleyDynamics.sparse_get_column
— Functionsparse_get_column(matrix::SparseMatrix, ci::Int)
Get the ci-th column of the sparse matrix.
ConleyDynamics.sparse_get_nz_column
— Functionsparse_get_nz_column(matrix::SparseMatrix, ci::Int)
Get the row indices for the nonzero entries in the ci-th column of the sparse matrix.
ConleyDynamics.sparse_minor
— Functionsmp = sparse_minor(sm::SparseMatrix, rvec::Vector{Int}, cvec::Vector{Int})
Create sparse submatrix by specifying the desired row and column indices.
Basic Functions
ConleyDynamics.sparse_size
— Functionsparse_size(matrix::SparseMatrix, dim::Int)
Number of rows (dim=1
) or columns (dim=2
) of a sparse matrix.
ConleyDynamics.sparse_low
— Functionsparse_low(matrix::SparseMatrix, col::Int)
Row index of the lowest nonzero matrix entry in column col
.
ConleyDynamics.sparse_is_sut
— Functionbool = sparse_is_sut(sm::SparseMatrix)
Check whether the sparse matrix is strictly upper triangular.
ConleyDynamics.sparse_identity
— Functionsparse_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)
.
ConleyDynamics.sparse_fullness
— Functionsparse_fullness(sm::SparseMatrix)
Display the fullness of the sparse matrix sm
.
ConleyDynamics.sparse_sparsity
— Functionsparse_sparsity(sm::SparseMatrix)
Display the sparsity of the sparse matrix sm
.
ConleyDynamics.sparse_show
— Functionsparse_show(sm::SparseMatrix)
Display the sparse matrix sm
.
Elementary Matrix Operations
ConleyDynamics.sparse_add_column!
— Functionsparse_add_column!(matrix::SparseMatrix, ci1::Int, ci2::Int, cn, cd)
Replace column[ci1]
by column[ci1] + (cn/cd) * column[ci2]
.
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
.
ConleyDynamics.sparse_add_row!
— Functionsparse_add_row!(matrix::SparseMatrix, ri1::Int, ri2::Int, cn, cd)
Replace row[ri1]
by row[ri1] + (cn/cd) * row[ri2]
.
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
.
ConleyDynamics.sparse_permute
— Functionsparse_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.
ConleyDynamics.sparse_remove!
— Functionsparse_remove!(matrix::SparseMatrix, ri::Int, ci::Int)
Remove the sparse matrix entry at location (ri,ci)
.
ConleyDynamics.sparse_multiply
— Functionsparse_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.
Base.:*
— MethodBase.:*(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.
Conversion Functions
ConleyDynamics.sparse_from_full
— Functionsparse_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.
ConleyDynamics.full_from_sparse
— Functionfull_from_sparse(sm::SparseMatrix)
Create full matrix from sparse matrix.
ConleyDynamics.sparse_from_lists
— Functionsparse_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 rowsnc::Int
: Number of columnstchar
: Field characteristic ifT==Int
tzero::T
: Number 0 of typeT
tone::T
: Number 1 of typeT
r::Vector{Int}
: Vector of row indicesc::Vector{Int}
: Vector of column indicesv::Vector{T}
: Vector of matrix entries
If tchar>0
, then the entries in v
are all replaced by their values mod tchar
.
ConleyDynamics.lists_from_sparse
— Functionnr, 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
.