Compressed row storage

from Wikipedia, the free encyclopedia

Compressed Row Storage (CRS) or Compressed Sparse Row (CSR) is a frequently used method for storing sparse matrices . In numerical mathematics , this is used to describe a matrix in which so many entries consist of zeros that it is worthwhile to take advantage of this.

With the CRS method, only the non-zero entries of a matrix are stored: In the form of an array , i.e. at successive locations in the memory. The information required for mapping between positions in the matrix and the array is stored in two further arrays and . The index of its column is stored in for each entry . It therefore includes as many elements as . The values ​​in determine which values belong to which row.

The formal relationship between the matrix and its representation using CRS is:

Example:
(The blue numbers indicate the rows and the green numbers the columns of the matrix . As usual in many computer languages, the indices begin with 0.)

In this example, the following values ​​are stored in the three vectors:

Both and contain 7 elements, this always corresponds to the number of non-zero elements in . has 5 elements; the number of elements is always 1 greater than the number of lines of . Element 0 has the value 0, the last element indicates the size of , in this case 7.

Line 1 of the matrix is ​​reconstructed from the compressed memory form as follows: Elements 1 and 2 of the vector indicate that the following line begins at position 2 of the vectors and row 1 and position 4. Line 1 has two elements different from 0. Their column indices are in positions 2 and 3 of , their values ​​in the corresponding positions in : 11 in column 2 and 13 in column 4.

literature