Rate This Document
Findability
Accuracy
Completeness
Readability

Data Storage

Compressed Storage Format for Sparse Vectors

Only non-zero elements in a sparse matrix are stored. Suppose sparse matrix a has nz non-zero elements: a(k1), a(k2), ..., a(knz)

Two arrays are used to store the information about matrix a:

x(1)=a(k1), x(2)=a(k2), ..., x(nz)=a(knz)

indx(1)=k1, indx(2)=k2, ..., indx(nz)=knz

The compressed storage format is memory-saving and time-efficient.

Full-Storage Format for Vectors

All elements in a sparse matrix are stored.

Sparse Matrix Storage Format

The compressed sparse row (CSR) format is specified by four arrays: value, column, pointerB, and pointerE,

as described in Table 1.

Table 1 Storage arrays of sparse matrix A in CSR format

Parameter

Description

value

  • Non-zero elements in matrix A, stored in row-major order
  • The array length is equal to the number of non-zero elements in matrix A.

column

  • Number of the column in matrix A that contains the i-th value in the value array
  • The array length is equal to the number of non-zero elements in matrix A.

pointerB

  • For one-based indexing, pointerB(j)-pointerB(1)+1 indicates the index of the element in the value array that is the first non-zero element in the jth row of matrix A.
  • For zero-based indexing, pointerB(j)-pointerB(0) indicates the index of the element in the value array that is the first non-zero element in the jth row of matrix A.
  • The array length is equal to the number of rows of matrix A.

pointerE

  • For one-based indexing, pointerE(j)-pointerB(1) indicates the index of the element in the value array that is the last non-zero element in the jth row of matrix A.
  • For zero-based indexing, pointerE(j)-pointerB(0)-1 indicates the index of the element in the value array that is the last non-zero element in the jth row of matrix A.
  • The array length is equal to the number of rows of matrix A.

Matrix A can be represented in CSR format as in Table 2.

Table 2 Matrix A in CSR format

Matrix

Indexing Method

CSR Format

One-based indexing

value = [2, -3, 7, 1, -6, 8, -4, 5, 9]

column = [1, 2, 4, 3, 4, 1, 3, 4, 1]

pointerB = [1, 4, 6, 9]

pointerE = [4, 6, 9, 10]

Zero-based indexing

value = [2, -3, 7, 1, -6, 8, -4, 5, 9]

column = [0, 1, 3, 2, 3, 0, 2, 3, 0]

pointerB = [0, 3, 5, 8]

pointerE = [3, 5, 8, 9]

The compressed sparse column (CSC) format is specified by four arrays: value, column, pointerB, and pointerE,

as described in Table 3.

Table 3 Storage arrays of sparse matrix A in CSC format

Parameter

Description

value

  • Non-zero elements in matrix A, stored in column-major order
  • The array length is equal to the number of non-zero elements in matrix A.

column

  • Number of the row in matrix A that contains the i-th value in the value array
  • The array length is equal to the number of non-zero elements in matrix A.

pointerB

  • For one-based indexing, pointerB(j)-pointerB(1)+1 indicates the index of the element in the value array that is the first non-zero element in the jth column of matrix A.
  • For zero-based indexing, pointerB(j)-pointerB(0) indicates the index of the element in the value array that is the first non-zero element in the jth column of matrix A.
  • The array length is equal to the number of columns of matrix A.

pointerE

  • For one-based indexing, pointerE(j)-pointerB(1) indicates the index of the element in the value array that is the last non-zero element in the jth column of matrix A.
  • For zero-based indexing, pointerE(j)-pointerB(0)-1 indicates the index of the element in the value array that is the last non-zero element in the jth column of matrix A.
  • The array length is equal to the number of columns of matrix A.

Matrix A can be represented in CSC format as in Table 4.

Table 4 Matrix A in CSC format

Matrix

Indexing Method

CSC Format

One-based indexing

value = [2, 8, 9, -3, 1, -4, 7, -6, 5]

column = [1, 3, 4, 1, 2, 3, 1, 2, 3]

pointerB = [1, 4, 5, 7]

pointerE = [4, 5, 7, 10]

Zero-based indexing

value = [2, 8, 9, -3, 1, -4, 7, -6, 5]

column = [0, 2, 3, 0, 1, 2, 0, 1, 2]

pointerB = [0, 3, 4, 6]

pointerE = [3, 4, 6, 9]