秩亏矩阵的压缩列格式示例



这是我第一次处理列压缩存储(CCS)格式来存储矩阵。在谷歌上搜索了一点之后,如果我是对的,在一个有n个非零元素的矩阵中,CCS如下:

-we define a vector A_v of dimensions n x 1 storing the n non-zero elements 
of the matrix
- we define a second vector A_ir of dimensions n x 1 storing the rows of the 
non-zero elements of the matrix
-we finally define a third vector A_jc whose elements are the indices of the 
elements of A_v which corresponds to the beginning of new column, plus a 
final value which is by convention equal t0 n+1, and identifies the end of 
the matrix (pointing theoretically to a virtual extra-column). 

例如,如果

M = [1 0 4 0 0;
0 3 5 2 0;
2 0 0 4 6;
0 0 7 0 8]

我们得到

A_v = [1 2 3 4 5 7 2 4 6 8];
A_ir = [1 3 2 1 2 4 2 3 3 4];
A_jc = [1 3 4 7 9 11];

我的问题是

I) 我写的是正确的,还是我误解了什么?

II) 如果我想用一些列表示一个矩阵,这些列是零,例如,该怎么办

M2 = [0 1 0 0 4 0 0; 
0 0 3 0 5 2 0;
0 2 0 0 0 4 6;
0 0 0 0 7 0 8]

M2在CCS中的表示难道不与M的表示相同吗?

谢谢你的帮助!

I)我写的是正确的,还是我误解了什么?

你完全正确。但是,如果使用C或C++库,则必须注意偏移量和索引应从0开始。在这里,我想您已经阅读了一些Fortran文档,其中的索引从1开始。需要明确的是,下面是C版本,它只是简单地转换Fortran风格的正确答案的索引:

A_v  = unmodified
A_ir = [0 2 1 0 1 3 1 2 2 4] (in short [1 3 2 1 2 4 2 3 3 4] - 1)
A_jc = [0 2 3 6 8 10] (in short [1 3 4 7 9 11] - 1)

II)如果我想用一些列来表示一个矩阵零,例如,M2=[0 1 0 0 4 0;0 0 3 0 5 2 0;0 2 0 0 4 6;0 0 0 0 7 0 8]

M2在CCS中的表示难道不与M的表示相同吗?

如果有一个空列,只需在偏移量表a_jc中添加一个新条目。由于此列不包含任何元素,因此此新条目值只是上一个条目的值。例如,对于M2(索引从0开始),您有:

A_v  = unmodified
A_ir = unmodified
A_jc = [0 0 2 3 6 8 10]   (to be compared to [0 2 3 6 8 10])

因此,这两种表示是不同的。


如果你刚开始学习稀疏矩阵,这里有一本非常免费的书:http://www-users.cs.umn.edu/~saad/IterMethBook_2ndEd.pdf

最新更新