Compressed Sparse Row (CSR): How do you store empty rows?

Take a look at The Wikipedia page. The IA vector (or as you call it "row"), is defined as:

The array IA is of length m + 1. It is defined by this recursive definition:

  • IA[0] = 0
  • IA[i] = IA[i − 1] + (number of nonzero elements on the (i − 1)-th row in the original matrix)
  • Thus, the first m elements of IA store the index into A of the first nonzero element in each row of M, and the last element IA[m] stores NNZ, the number of elements in A, which can be also thought of as the index in A of first element of a phantom row just beyond the end of the matrix M. The values of the i-th row of the original matrix is read from the elements A[IA[i]] to A[IA[i + 1] − 1] (inclusive on both ends), i.e. from the start of one row to the last index just before the start of the next.

Thus, in Matrix 1:

row = [0 1 2 3]

in Matrix 2:

row = [0 3 3 3]

in Matrix 3

row = [0 0 3 3]