Can the following 3x3
sparse matrix be stored using CSR
format in the Intel MKL library?
A = [ 0 0 1
0 0 0
3 1 4];
valuesA = {1, 3, 1, 4};
columnsA = {2, 0, 1, 2};
rowIndexA = {0, 1, 3};
How this can be differentiated from the following 2x3
matrix?
B = [ 0 0 1
3 1 4];
valuesB = {1, 3, 1, 4};
columnsB = {2, 0, 1, 2};
rowIndexB = {0, 1, 3};
The reason, I have a row full of zero is matrix-indexing. This all-zero-row can happen anywhere in the matrix A
. The matrix A
is actually a sub-matrix of a bigger sparse matrix, which will be used in a system of equations Ax = b
. Could someone kindly give me some insight?
If the row is empty, just repeat the corresponding value in rowIndexA
.
For the matrix
0 0 1
0 0 0
3 1 4
the correct representation is:
valuesA = {1, 3, 1, 4};
columnsA = {2, 0, 1, 2};
rowIndexA = {0, 1, 1, 4};
// ^^^^ repeat 1
The last value in rowIndexA
should be equal to the number of elements, i.e. 4
in your case. Then you get the correct number of elements in each row: 1 - 0 = 1
in the first row, 1 - 1 = 0
in the second one and 4 - 1 = 3
in the last one.