Matrices

SparseDirectSolver.CSR — Type
CSR{T,INT,VI,VT}

Compressed sparse row matrix on any backend: rowptr::VI, colval::VI (VI <: AbstractVector{INT}), nzval::VT (VT <: AbstractVecOrMat{T}), nrows, ncols, index::IndexBase and transposed::Bool.

  • index is the base of rowptr/colval (INDEX_ONE or INDEX_ZERO); the arrays are never rebased in place.
  • transposed = true means the stored CSR arrays describe transpose(M) of the matrix M the caller means (for example a CSC matrix reinterpreted as the CSR of its transpose, see csr_of_transpose). size, nnz and SparseMatrixCSC(A) refer to the stored CSR matrix; consumers honor the flag.
  • A uniform batch shares rowptr/colval; its values are either a vector of length nbatch * nnz (members one after the other) or an nnz × nbatch matrix.

Constructors:

CSR(rowptr, colval, nzval[, nrows, ncols]; index = 'O', transposed = false)
CSR(A::SparseMatrixCSC; index = 'O')

The first wraps the arrays without copying (square nrows = ncols = length(rowptr) - 1 when the sizes are omitted); the second builds the CSR arrays of A on the host. Only lengths are validated, never array contents, so no device memory is read.

source
SparseDirectSolver.csr_of_transpose — Function
csr_of_transpose(A::SparseMatrixCSC) -> CSR

Zero-copy reinterpretation of the CSC matrix A (m × n) as the CSR matrix of transpose(A) (n × m): A.colptr becomes rowptr, A.rowval becomes colval, the arrays are shared and transposed = true records that the caller means A. This is how MadNLP passes colPtr/rowVal (PLAN §1.1). A solver on such a matrix reads it with the view flipped ('L' ↔ 'U'; for "G" the view is ignored). Raises InvalidValueError when A.rowval or A.nzval is longer than nnz(A) (a SparseMatrixCSC may keep spare capacity, which the shared CSR arrays cannot describe).

source
SparseDirectSolver.to_backend — Function
to_backend(A, backend) -> CSR

A (a SparseMatrixCSC or a CSR) as a CSR whose arrays live on the KernelAbstractions backend. A SparseMatrixCSC is first converted on the host (index keyword as in CSR(A; index)); arrays already on backend are not copied.

source
to_backend(A::SparseMatrixCSC, ::CUDABackend; index = 'O') -> CSR

CSR arrays of A built on the host, then uploaded as CuVectors.

source
to_backend(A::SparseMatrixCSC, ::ROCBackend; index = 'O') -> CSR

CSR arrays of A built on the host, then uploaded as ROCVectors.

source
SparseDirectSolver.nbatch — Function
nbatch(A::CSR)
nbatch(desc::MatrixDescriptor)

Number of matrices in a uniform batch: size(nzval, 2) for matrix values, length(nzval) ÷ nnz for vector values (1 for a plain matrix).

source
SparseDirectSolver.MatrixDescriptor — Type
MatrixDescriptor{T,A}

Dense right-hand side / solution descriptor (≅ CudssMatrix for dense data): data::Union{Nothing,A}, nrows, ncols, nbatch, transposed. nrows × ncols is the logical size of one batch member. With transposed = true the data is row-major, i.e. a column-major array of size (ncols, nrows), as in CUDSS.jl.

MatrixDescriptor(T, n; nbatch = 1)                       # n × 1, no data yet
MatrixDescriptor(T, m, n; nbatch = 1, transposed = false) # as CUDSS.jl: transposed gives n × m
MatrixDescriptor(x::AbstractArray; transposed = false)    # vector, matrix or (n, p, nbatch) array

update! re-points the descriptor to a new buffer without copying. Descriptors created without data accept any AbstractArray{T}; descriptors created from an array accept arrays of the same type.

source

update! also replaces the data of a MatrixDescriptor.