Sparse Matrix Layout and Matrix–Vector Products
Compute one sparse row from compressed index arrays and explain how traversal order affects locality and construction.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Store nonzeros and row boundaries
Compressed sparse row storage keeps a value array, a column-index array of matching length, and a row-pointer array. The interval between consecutive row pointers gives that row’s nonzeros. If row zero stores column \(1\) with value \(4\) and column \(3\) with value \(-2\), the product entry is \(4x_1-2x_3\). An empty row has equal pointers and contributes zero. The total arithmetic is proportional to the number of stored entries plus row output work.
The best orientation depends on the operation
CSR streams values and indices when multiplying by a vector, while accesses into the vector can be irregular. Column-oriented storage makes transposed traversal simpler. Appending arbitrary new entries into a compressed region may shift a large suffix, so construction often accumulates coordinates before sorting and compressing. Cache analysis explains locality of indirect reads. Conjugate gradient repeatedly applies the sparse operator and thus magnifies its layout costs.[1][2]