API Reference
This page contains the complete API documentation for GenericSparseArrays.jl.
GenericSparseArrays.AbstractGenericSparseArrayGenericSparseArrays.GenericSparseMatrixCOOGenericSparseArrays.GenericSparseMatrixCSCGenericSparseArrays.GenericSparseMatrixCSRGenericSparseArrays.GenericSparseVectorBase.:*Base.:*Base.:*Base.:+Base.:+Base.:+Base.kronBase.kronBase.kron
Types
GenericSparseArrays.AbstractGenericSparseArray — Type
AbstractGenericSparseArray{Tv,Ti,N} <: AbstractSparseArray{Tv,Ti,N}Supertype for sparse arrays that can have their underlying storage on various devices (CPU, GPU, accelerators). This package keeps the hierarchy backend-agnostic; dispatch is expected to leverage the concrete types of internal buffers (e.g. Vector, CuArray, etc.) rather than an explicit backend flag.
GenericSparseArrays.GenericSparseVector — Type
GenericSparseVector{Tv,Ti,IndT<:AbstractVector{Ti},ValT<:AbstractVector{Tv}} <: AbstractGenericSparseVector{Tv,Ti}Sparse vector with generic index and value storage containers which may reside on different devices. The logical length is stored along with index/value buffers.
Fields
n::Ti- logical length of the vectornzind::IndT- indices of stored (typically nonzero) entries (1-based)nzval::ValT- stored values
Constructors validate that the index and value vectors have matching length.
GenericSparseArrays.GenericSparseMatrixCSC — Type
GenericSparseMatrixCSC{Tv,Ti,ColPtrT,RowValT,NzValT} <: AbstractGenericSparseMatrix{Tv,Ti}Compressed Sparse Column (CSC) matrix with generic storage vectors for column pointer, row indices, and nonzero values. Buffer types (e.g. Vector, GPU array types) enable dispatch on device characteristics.
Fields
m::Int- number of rowsn::Int- number of columnscolptr::ColPtrT- column pointer array (length n+1)rowval::RowValT- row indices of stored entriesnzval::NzValT- stored values
GenericSparseArrays.GenericSparseMatrixCSR — Type
GenericSparseMatrixCSR{Tv,Ti,RowPtrT,ColValT,NzValT} <: AbstractGenericSparseMatrix{Tv,Ti}Compressed Sparse Row (CSR) matrix with generic storage vectors for row pointer, column indices, and nonzero values. Buffer types (e.g. Vector, GPU array types) enable dispatch on device characteristics.
Fields
m::Int- number of rowsn::Int- number of columnsrowptr::RowPtrT- row pointer array (length m+1)colval::ColValT- column indices of stored entriesnzval::NzValT- stored values
GenericSparseArrays.GenericSparseMatrixCOO — Type
GenericSparseMatrixCOO{Tv,Ti,RowIndT<:AbstractVector{Ti},ColIndT<:AbstractVector{Ti},NzValT<:AbstractVector{Tv}} <: AbstractGenericSparseMatrix{Tv,Ti}Coordinate (COO) sparse matrix with generic storage vectors for row indices, column indices, and nonzero values. Buffer types (e.g. Vector, GPU array types) enable dispatch on device characteristics.
Fields
m::Int- number of rowsn::Int- number of columnsrowind::RowIndT- row indices of stored entriescolind::ColIndT- column indices of stored entriesnzval::NzValT- stored values
Functions
Base.:* — Method
*(A::GenericSparseMatrixCOO, B::GenericSparseMatrixCOO)Multiply two sparse matrices in COO format. Both matrices must have compatible dimensions (number of columns of A equals number of rows of B) and be on the same backend (device).
The multiplication converts to CSC format, performs the multiplication with GPU-compatible kernels, and converts back to COO format. This approach is used for all cases including transpose/adjoint since COO doesn't have an efficient direct multiplication algorithm.
Examples
julia> using GenericSparseArrays, SparseArrays
julia> A = GenericSparseMatrixCOO(sparse([1, 2], [1, 2], [2.0, 3.0], 2, 2));
julia> B = GenericSparseMatrixCOO(sparse([1, 2], [1, 2], [4.0, 5.0], 2, 2));
julia> C = A * B;
julia> collect(C)
2×2 Matrix{Float64}:
8.0 0.0
0.0 15.0Base.:* — Method
*(A::GenericSparseMatrixCSC, B::GenericSparseMatrixCSC)Multiply two sparse matrices in CSC format. Both matrices must have compatible dimensions (number of columns of A equals number of rows of B) and be on the same backend (device).
The multiplication uses GPU-compatible kernels for efficient sparse-sparse matrix multiplication (SpGEMM).
Examples
julia> using GenericSparseArrays, SparseArrays
julia> A = GenericSparseMatrixCSC(sparse([1, 2], [1, 2], [2.0, 3.0], 2, 2));
julia> B = GenericSparseMatrixCSC(sparse([1, 2], [1, 2], [4.0, 5.0], 2, 2));
julia> C = A * B;
julia> collect(C)
2×2 Matrix{Float64}:
8.0 0.0
0.0 15.0Base.:* — Method
*(A::GenericSparseMatrixCSR, B::GenericSparseMatrixCSR)Multiply two sparse matrices in CSR format. Both matrices must have compatible dimensions (number of columns of A equals number of rows of B) and be on the same backend (device).
The multiplication uses GPU-compatible kernels for efficient sparse-sparse matrix multiplication (SpGEMM).
Examples
julia> using GenericSparseArrays, SparseArrays
julia> A = GenericSparseMatrixCSR(GenericSparseMatrixCOO(sparse([1, 2], [1, 2], [2.0, 3.0], 2, 2)));
julia> B = GenericSparseMatrixCSR(GenericSparseMatrixCOO(sparse([1, 2], [1, 2], [4.0, 5.0], 2, 2)));
julia> C = A * B;
julia> collect(C)
2×2 Matrix{Float64}:
8.0 0.0
0.0 15.0Base.:+ — Method
+(A::GenericSparseMatrixCOO, B::GenericSparseMatrixCOO)Add two sparse matrices in COO format. Both matrices must have the same dimensions and be on the same backend (device).
The result is a COO matrix with entries from both A and B properly merged, with duplicate entries (same row and column) combined by summing their values.
Examples
julia> using GenericSparseArrays, SparseArrays
julia> A = GenericSparseMatrixCOO(sparse([1, 2], [1, 2], [1.0, 2.0], 2, 2));
julia> B = GenericSparseMatrixCOO(sparse([1, 2], [2, 1], [3.0, 4.0], 2, 2));
julia> C = A + B;
julia> collect(C)
2×2 Matrix{Float64}:
1.0 3.0
4.0 2.0Base.:+ — Method
+(A::GenericSparseMatrixCSC, B::GenericSparseMatrixCSC)Add two sparse matrices in CSC format. Both matrices must have the same dimensions and be on the same backend (device).
Examples
julia> using GenericSparseArrays, SparseArrays
julia> A = GenericSparseMatrixCSC(sparse([1, 2], [1, 2], [1.0, 2.0], 2, 2));
julia> B = GenericSparseMatrixCSC(sparse([1, 2], [2, 1], [3.0, 4.0], 2, 2));
julia> C = A + B;
julia> collect(C)
2×2 Matrix{Float64}:
1.0 3.0
4.0 2.0Base.:+ — Method
+(A::GenericSparseMatrixCSR, B::GenericSparseMatrixCSR)Add two sparse matrices in CSR format. Both matrices must have the same dimensions and be on the same backend (device).
Examples
julia> using GenericSparseArrays, SparseArrays
julia> A = GenericSparseMatrixCSR(sparse([1, 2], [1, 2], [1.0, 2.0], 2, 2));
julia> B = GenericSparseMatrixCSR(sparse([1, 2], [2, 1], [3.0, 4.0], 2, 2));
julia> C = A + B;
julia> collect(C)
2×2 Matrix{Float64}:
1.0 3.0
4.0 2.0Base.kron — Method
kron(A::GenericSparseMatrixCSC, B::GenericSparseMatrixCSC)Compute the Kronecker product of two sparse matrices in CSC format.
The Kronecker product is computed by converting to COO format, computing the product, and converting back to CSC format.
Examples
julia> using GenericSparseArrays, SparseArrays
julia> A = GenericSparseMatrixCSC(sparse([1, 2], [1, 2], [1.0, 2.0], 2, 2));
julia> B = GenericSparseMatrixCSC(sparse([1, 2], [1, 2], [3.0, 4.0], 2, 2));
julia> C = kron(A, B);
julia> size(C)
(4, 4)
julia> nnz(C)
4Base.kron — Method
kron(A::GenericSparseMatrixCSR, B::GenericSparseMatrixCSR)Compute the Kronecker product of two sparse matrices in CSR format.
The Kronecker product is computed by converting to COO format, computing the product, and converting back to CSR format.
Examples
julia> using GenericSparseArrays, SparseArrays
julia> A_coo = GenericSparseMatrixCOO(sparse([1, 2], [1, 2], [1.0, 2.0], 2, 2));
julia> B_coo = GenericSparseMatrixCOO(sparse([1, 2], [1, 2], [3.0, 4.0], 2, 2));
julia> A = GenericSparseMatrixCSR(A_coo);
julia> B = GenericSparseMatrixCSR(B_coo);
julia> C = kron(A, B);
julia> size(C)
(4, 4)
julia> nnz(C)
4Base.kron — Method
kron(A::GenericSparseMatrixCOO, B::GenericSparseMatrixCOO)Compute the Kronecker product of two sparse matrices in COO format.
The Kronecker product of two matrices A (size m×n) and B (size p×q) is an (mp)×(nq) matrix formed by multiplying each element of A by the entire matrix B.
Examples
julia> using GenericSparseArrays, SparseArrays
julia> A = GenericSparseMatrixCOO(sparse([1, 2], [1, 2], [1.0, 2.0], 2, 2));
julia> B = GenericSparseMatrixCOO(sparse([1, 2], [1, 2], [3.0, 4.0], 2, 2));
julia> C = kron(A, B);
julia> size(C)
(4, 4)
julia> nnz(C)
4