[英]efficiently updating inplace certain blocks of a large sparse matrix in Eigen?
Suppose that I have a large sparse matrix with the following pattern:假设我有一个具有以下模式的大型稀疏矩阵:
As instructed in the document , i've initialized the above matrix by按照文档中的说明,我已通过以下方式初始化了上述矩阵
In later part of the program, it's natural to reuse the matrix and only updates the A, B blocks inplace.在程序的后面部分,很自然地重用矩阵并且只更新 A、B 块。 Possible ways are:可能的方法是:
coeffRef
, would introduce binary search so not preferred here.通过coeffRef
访问现有条目会引入二进制搜索,因此这里不推荐使用。However, it seems a bit unnecessary to iterate over all nonzero entries since most part of the sparse matrix stays the same.但是,似乎没有必要遍历所有非零条目,因为稀疏矩阵的大部分都保持不变。
Is it possible to update A, B inplace without iterating over all nonzeros in the matrix?是否可以在不迭代矩阵中的所有非零值的情况下就地更新 A、B?
From what I can tell, the InnerIterator
can be used used for this and runs in constant time.据我所知, InnerIterator
可用于此并在恒定时间内运行。
Eigen::Index col = 1;
Eigen::Index offset_in_col = 1;
using SparseMatrixD = Eigen::SparseMatrix<double>;
SparseMatrixD mat = ...;
SparseMatrixD::InnerIterator i =
SparseMatrixD::InnerIterator(mat, col) + offset_in_col;
assert(i.row() == 1);
assert(i.col() == 1);
assert(i.value() == C);
This should access the value C. All you need to know is how many nonzero elements are per column (or inner dimension in general).这应该访问值 C。您只需要知道每列(或通常的内部维度)有多少非零元素。 You don't need to know how many nonzero columns (outer dimensions) are stored because that array ( SparseMatrix.outerIndexPtr()
) has one entry per column.您不需要知道存储了多少非零列(外部维度),因为该数组( SparseMatrix.outerIndexPtr()
)每列有一个条目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.