Sparse storage formats#
CSR
There are a variety of matrix storage formats available for representing the sparse matrix. One of the most popular is compressed sparse row (CSR) format, that is represented by three arrays: row_ptr, col_ind and val, and index parameter.
nrows |
Number of rows in the sparse matrix. |
ncols |
Number of columns in the sparse matrix. |
nnz |
Number of non-zero entries in the sparse matrix (which may include explicit zeros). This is also the length of the col_ind and val arrays. |
index |
Parameter that is used to specify whether the matrix has zero or one-based indexing. |
val |
An array of length |
col_ind |
An integer array of length |
row_ptr |
An integer array of size equal to |
A sparse matrix can be represented in a CSR format in a following way (assuming zero-based indexing):
nrows |
3 |
||||
ncols |
3 |
||||
nnz |
5 |
||||
index |
0 |
||||
val |
1 |
2 |
-1 |
4 |
3 |
col_ind |
0 |
2 |
1 |
2 |
0 |
row_ptr |
0 |
2 |
4 |
5 |
Parent topic: Sparse BLAS