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 arrays v and u must all be the same size, and the arrays v and u
must have index values bounded by m and n. see section compressed row storage for
more details.