compressed sparse row representation

[[concept]]
Compressed Sparse Row (CSR) representation

ARn×m can become a set of 3 tensors/"lists". We get this representation by realizing that we can encode the row index in the COO representation a bit more efficiently.

Instead of writing out the row index for each element, we can collect the column indices for each row, put each of these collections together, and then have a pointer tell us where to start reading.

If A has z non-zero entries, then

  • the column tensor contains z entries. Each entry contains the column index for one of the non-zero elements, sorted by ascending row index.
  • row or pointer tensor contains n+1 entries
    • the first n entries contain the starting index for where the row's elements start in the column tensor
    • the last entry is z
  • value tensor contains z entries and contains the non-zero elements sorted by row then column index.
Example

A=[12026000191426190001407]

Pointer = [0 2 4 6]

index0123read start0246

Column = [0 2 2 3 0 1 1 3]

index01234567col indx02230113

Value = [12 16 19 14 26 19 14 7]

index01234567value122619142619147

Mentions

File
coordinate representation
sparse matrix representation
2025-02-12 graphs lecture 7
2025-02-17 graphs lecture 8