关于Eigen的稀疏矩阵的介绍:原文链接
1.SparseMatrix的格式
SparseMatrix主要包含以下4个数组:
- Values: stores the coefficient values of the non-zeros.
- InnerIndices: stores the row (resp. column) indices of the non-zeros.
- OuterStarts: stores for each column (resp. row) the index of the first non-zero in the previous two arrays.
- InnerNNZs: stores the number of non-zeros of each column (resp. row). The word inner refers to an inner vector that is a column for a column-major matrix, or a row for a row-major matrix. The word outer refers to the other direction.
- Values为稀疏矩阵中所有非0元素的值
- InnerIndices为非0元素的行索引(列主序存储为行的索引,行主-序存储为列的索引)。
- OuterStarts结合文档中给出的公式:
InnerNNZs[j] == OuterStarts[j+1] - OuterStarts[j]
自己将OuterStarts理解为每列第一个非0元素在Values的索引(行主序存储则为每行第一个非0元素在Values的索引),因此OuterStarts的后一个元素相减为即为前一列的非0元素的个数。OuterStarts数组元素的个数=列数+1,最后一个元素表明了最后一列的非0元素个数。 - InnerNNZs为每一列非0元素的个数(行主序存储为每一行 )。
仍以文档中的矩阵为例:
↓ 0 1 2 3 4 0 0 3 0 0 0 1 22 0 0 0 17 2 7 5 0 1 0 3 0 0 0 0 0 4 0 0 14 0 8 \begin{array}{c|ccccc} \downarrow &0 &1 &2 &3 &4 \\ \hline 0 &0 &3 &0 &0 &0 \\ 1 &22 &0 &0 &0 &17 \\ 2 &7 &5 &0 &1 &0 \\ 3 &0 &0 &0 &0 &0 \\ 4 &0 &0 &14 &0 &8 \end{array} ↓0123400227001305

文章详细介绍了Eigen库中用于存储稀疏矩阵的SparseMatrix类,包括其四种主要数组:Values、InnerIndices、OuterStarts和InnerNNZs的作用和理解。特别地,解释了压缩列存储(CCS)和压缩行存储(CRS)模式,并指出Eigen运算通常产生压缩的稀疏矩阵。此外,还列举了SparseMatrix的一些关键成员函数,如nonZeros()、outerSize()和innerSize()等。
最低0.47元/天 解锁文章
7855

被折叠的 条评论
为什么被折叠?



