6.2 Conversion Functions
Conversion functions between dense and sparse matrices are provided.
6.2.1 Dense to Sparse Conversion
Converting a dense matrix \(m\) to a sparse representation produces a vector \(w\) and two integer arrays, \(u\) and \(v\).
vector
csr_extract_w
(matrix a)
Return non-zero values in matrix a; see section compressed row storage.
int[]
csr_extract_v
(matrix a)
Return column indices for values in csr_extract_w(a)
; see
compressed row storage.
int[]
csr_extract_u
(matrix a)
Return array of row starting indices for entries in csr_extract_w(a)
followed by the size of csr_extract_w(a)
plus one; see section
compressed row storage.
6.2.2 Sparse to Dense Conversion
To convert a sparse matrix representation to a dense matrix, there is a single function.
matrix
csr_to_dense_matrix
(int m, int n, vector w, int[] v, int[] u)
Return dense \(\text{m} \times \text{n}\) matrix with non-zero matrix
entries w, column indices v, and row starting indices u; the vector w
and array v must be the same size (corresponding to the total number of
nonzero entries in the matrix), array v must have index values bounded
by m, array u must have length equal to m + 1 and contain index values
bounded by the number of nonzeros (except for the last entry, which must
be equal to the number of nonzeros plus one). See section
compressed row storage for more details.