Home

SparseMatricesCSR.jl

This module contains:

  • Data types:

    • SparseMatrixCSR:Compressed Sparse Row (CSR) sparse matrix implementation with Bi-based indexing.
    • SymSparseMatrixCSR: Symmetric Compressed Sparse Row sparse matrix implementation with Bi-based indexing.
  • Procedures:

    • push_coo!: Helper function to build COO arrays for further building a SparseMatrix
    • finalize_coo!: Finalization of COO arrays building.
    • sparsecsr: Analogous method to sparse function to build a SparseMatrixCSR.
    • symsparsecsr: Analogous method to sparse function to build a SymSparseMatrixCSR.
    • colvals: Analogous method to rowvals to return colvals array.
    • hasrowmajororder: Return true if matrix values are ordered by row.
    • hascolmajororder: Return true if matrix values are ordered by column.
    • getptr: Return the pointer array of a SparseMatrix (rowptr or colptr depending on the SparseMatrix type)
    • getindices: Return the indices array of a SparseMatrix (rowval or colval depending on the SparseMatrix type)
  • Overloaded procedures:

    • *: SparseMatrix-Vector product.
    • mul!: SparseMatrix-Vector product.
    • nnz: Return the number of stored (filled) elements in a sparse array.
    • nonzeros: Return nzval array.
    • nzrange: Return the range of indices for a particular row or column (Depending on the SparseMatrix type)
    • findnz: Return a tuple (I, J, V) where I and J are the row and column indices.
    • rowvals: Return row indices or raises an error (Depending on the SparseMatrix type)
    • convert: Type conversion
source
struct SparseMatrixCSR{Bi,Tv,Ti<:Integer} <: AbstractSparseMatrix{Tv,Ti}

Matrix type for storing Bi-based sparse matrices in the Compressed Sparse Row format. The standard way of constructing SparseMatrixCSR is through the sparsecsr function.

source
struct SymSparseMatrixCSR{T,Ti<:Integer} <: AbstractSparseMatrix{T,Ti}

Matrix type for storing symmetric sparse matrices in the Compressed Sparse Row format. The standard way of constructing SparseMatrixCSR is through the symsparsecsr function.

source
function finalize_coo!(I,J,V,m,n)

Finalize COO arrays for building a SparseMatrixCSC.

source
function finalize_coo!(::Type{SparseMatrixCSC},I,J,V,m,n)

Check and insert diagonal entries in COO vectors if needed.

source
function finalize_coo!(::Type{SparseMatrixCSR},I,J,V,m,n)

Finalize COO arrays for building a SparseMatrixCSR.

source
function finalize_coo!(::Type{SymSparseMatrixCSR},I,J,V,m,n)

Finalize COO arrays for building a SymSparseMatrixCSR. Check and insert diagonal entries in COO vectors if needed.

source
function getvals(S::SparseMatrixCSC)

Return row indices.

source
function getindices(S::SparseMatrixCSR)

Return column indices.

source
function getindices(S::SymSparseMatrixCSR)

Return column indices.

source
function getptr(S::SparseMatrixCSC)

Return columns pointer.

source
function getptr(S::SparseMatrixCSR)

Return rows pointer.

source
function getptr(S::SymSparseMatrixCSR)

Return rows pointer.

source
function hascolmajororder(::Type{SparseMatrixCSC})

Check if values are stored in col-major order. Return true.

source
function hascolmajororder(::Type{SparseMatrixCSR})

Check if values are stored in col-major order. Return false.

source
function hascolmajororder(::Type{SymSparseMatrixCSR})

Check if values are stored in col-major order. Return false.

source
function hasrowmajororder(::Type{SparseMatrixCSC})

Check if values are stored in row-major order. Return false.

source
function hasrowmajororder(::Type{SparseMatrixCSR})

Check if values are stored in row-major order. Return true.

source
function hasrowmajororder(::Type{SymSparseMatrixCSR})

Check if values are stored in row-major order. Return true.

source
function push_coo!(I,J,V,ik,jk,vk)

Inserts entries in COO vectors for further building a SparseMatrixCSC.

source
function push_coo!(::Type{SparseMatrixCSC},I,J,V,ik,jk,vk)

Inserts entries in COO vectors for further building a SparseMatrixCSC.

source
function push_coo!(::Type{SymSparseMatrixCSR},I,J,V,ik,jk,vk)

Inserts entries in COO vectors for further building a SymSparseMatrixCSR. It stores only the upper triangle, ignoring entries with (ik>jk) coordinates.

source
function push_coo!(::Type{SparseMatrixCSR},I,J,V,ik,jk,vk)

Inserts entries in COO vectors for further building a SparseMatrixCSR.

source
sparsecsr(I, J, V, [m, n, combine])

Create a sparse matrix S of dimensions m x n such that S[I[k], J[k]] = V[k]. The combine function is used to combine duplicates. If m and n are not specified, they are set to maximum(I) and maximum(J) respectively. If the combine function is not supplied, combine defaults to + unless the elements of V are Booleans in which case combine defaults to |. All elements of I must satisfy 1 <= I[k] <= m, and all elements of J must satisfy 1 <= J[k] <= n. Numerical zeros in (I, J, V) are retained as structural nonzeros.

source
symsparsecsr(I, J, V, [m, n, combine])

Create a Symmetric sparse matrix S of dimensions m x n such that S[I[k], J[k]] = V[k], and m=n. The combine function is used to combine duplicates. If m and n are not specified, they are set to maximum(I) and maximum(J) respectively. If the combine function is not supplied, combine defaults to +. All elements of I must satisfy 1 <= I[k] <= m, and all elements of J must satisfy 1 <= J[k] <= n. Numerical zeros in (I, J, V) are retained as structural nonzeros.

source
Base.convertMethod.
function convert(::Type{SparseMatrixCSR}, x::AbstractSparseMatrix)

Convert x to a value of type SymSparseMatrixCSR.

source
Base.convertMethod.
function convert(::Type{SymSparseMatrixCSR}, x::SymSparseMatrixCSR)

Convert x to a value of type SymSparseMatrixCSR.

source
Base.convertMethod.
function convert(::Type{SparseMatrixCSC}, x::SparseMatrixCSR)

Convert x to a value of type SparseMatrixCSC.

source
Base.countMethod.
count(pred, S::SparseMatrixCSR) -> Integer

Count the number of elements in nonzeros(S) for which predicate pred returns true.

source
Base.countMethod.
count(pred, S::SymSparseMatrixCSR) -> Integer

Count the number of elements in nonzeros(S) for which predicate pred returns true.

source
LinearAlgebra.mul!Method.
function mul!(y::AbstractVector,A::SparseMatrixCSR,v::AbstractVector{T}) where {T}

Calculates the matrix-vector product $Av$ and stores the result in y, overwriting the existing value of y.

source
LinearAlgebra.mul!Method.
function mul!(y::AbstractVector,A::SymSparseMatrixCSR,v::AbstractVector{T}) where {T}

Calculates the matrix-vector product $Av$ and stores the result in y, overwriting the existing value of y.

source
findnz(S::SymSparseMatrixCSR)

Return a tuple (I, J, V) where I and J are the row and column indices of the stored ("structurally non-zero") values in sparse matrix A, and V is a vector of the values.

source
function findnz(S::SparseMatrixCSR{Bi,Tv,Ti})

Return a tuple (I, J, V) where I and J are the row and column indices of the stored ("structurally non-zero") values in sparse matrix A, and V is a vector of the values.

source
SparseArrays.nnzMethod.
nnz(S::SymSparseMatrixCSR)

Returns the number of stored (filled) elements in a sparse array.

source
SparseArrays.nnzMethod.
nnz(S::SparseMatrixCSR{Bi}) where {Bi}

Returns the number of stored (filled) elements in a sparse array.

source
nonzeros(S::SparseMatrixCSR)

Return a vector of the structural nonzero values in sparse array S. This includes zeros that are explicitly stored in the sparse array. The returned vector points directly to the internal nonzero storage of S, and any modifications to the returned vector will mutate S as well.

source
nonzeros(S::SymSparseMatrixCSR)

Return a vector of the structural nonzero values in sparse array S. This includes zeros that are explicitly stored in the sparse array. The returned vector points directly to the internal nonzero storage of A, and any modifications to the returned vector will mutate A as well.

source
nzrange(S::SymSparseMatrixCSR, row::Integer)

Return the range of indices to the structural nonzero values of a sparse matrix row.

source
nzrange(S::SparseMatrixCSR{Bi}, row::Integer) where {Bi}

Return the range of indices to the structural nonzero values of a sparse matrix row.

source
rowvals(S::SparseMatrixCSR)

Return an error. CSR sparse matrices does not contain raw row values. It contains row pointers instead that can be accessed by using nzrange.

source