Sparse Storage Formats¶
Compressed Sparse Row (CSR)¶
There are a variety of matrix storage formats available for representing
the sparse matrix. One of the most popular is the CSR format that is
represented by three arrays: row_ptr, col_ind and val, and
the index parameter.
CSR Matrix Elements  | 
Description  | 
|---|---|
  | 
Number of rows in the sparse matrix.  | 
  | 
Number of columns in the sparse matrix.  | 
  | 
Parameter that is used to specify whether the matrix has zero or one-based indexing.  | 
  | 
An array that contains the non-zero elements of the sparse matrix stored row by row.  | 
  | 
An integer array of column indices for non-zero elements stored in the   | 
  | 
An integer array of size equal to   | 
Examples of CSR format¶
A sparse matrix can be represented in a CSR format in the following ways:
Case 1:¶
Assuming zero-based indexing and a real square matrix.

  | 
3  | 
||||
  | 
3  | 
||||
  | 
0  | 
||||
  | 
0  | 
2  | 
4  | 
5  | 
|
  | 
0  | 
2  | 
1  | 
2  | 
0  | 
  | 
1.0  | 
2.0  | 
-1.0  | 
4.0  | 
3.0  | 
Case 2:¶
Assuming one-based indexing and real rectangular matrix with an empty row.

  | 
4  | 
||||||
  | 
5  | 
||||||
  | 
1  | 
||||||
  | 
1  | 
3  | 
6  | 
6  | 
8  | 
||
  | 
1  | 
3  | 
2  | 
3  | 
5  | 
1  | 
4  | 
  | 
1.0  | 
2.0  | 
-1.0  | 
4.0  | 
1.0  | 
3.0  | 
1.0  |