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.
num_rows |
Number of rows in the sparse matrix. |
num_cols |
Number of columns in the sparse matrix. |
index |
Parameter that is used to specify whether the matrix has zero or one-based indexing. |
val |
An array that contains the non-zero elements of the sparse matrix stored row by row. |
col_ind |
An integer array of column indices for non-zero elements stored in the val array, such that col_ind[i] is the column number (using zero- or one-based indexing) of the element of the sparse matrix stored in val[i]. |
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):
num_rows |
3 |
||||
num_cols |
3 |
||||
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