有效地更新特定特定稀疏基质的某些块的内置块?

发布于 2025-02-07 09:56:12 字数 706 浏览 3 评论 0原文

假设我的稀疏矩阵具有以下模式:

  • 每列的非齐射率及其位置仅固定,
  • 仅矩阵块A和b会改变,其余矩阵保持静态; (A块A和B本身在固定的非零位置也很稀疏)

,我已经通过

  • 的每个列的确切数量
  • 保留“列列稀疏矩阵插入列”列
  • 最小行索引的列插入列

插入程序后面的 矩阵,仅更新A,B块Inploph。可能的方法是:

  1. 通过coeffref访问现有条目,将引入二进制搜索,因此在这里不受欢迎。
  2. 如有记录的在这里

似乎有点,它似乎有点 不需要在所有非零条目上进行迭代,因为稀疏矩阵的大部分时间都保持不变。

是否可以在矩阵中的所有非Zeros上进行迭代?

Suppose that I have a large sparse matrix with the following pattern:

  • the number of nonzeros per column and their locations are fixed
  • only matrix block A and B will change and the rest of the matrix stays static; (blocks A and B themselves are also sparse with fixed nonzero locations)

As instructed in the document, i've initialized the above matrix by

  • reserving the exact number of nonzeros per column for the column major sparse matrix
  • inserting column by column
  • inserting from the smallest row index per column

In later part of the program, it's natural to reuse the matrix and only updates the A, B blocks inplace. Possible ways are:

  1. accessing existing entries by coeffRef, would introduce binary search so not preferred here.
  2. iterating over the outer and inner dimensions as documented here

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卸妝后依然美 2025-02-14 09:56:12

据我所知,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);

这应该访问值C。您需要知道的只是每个列的非零元素有多少个(或一般内在维度)。您不需要知道存储多少个非零列(外部维度),因为该数组(sparsematrix.outerindexptr())每列有一个条目。

From what I can tell, the InnerIterator can be used used for this and runs in constant time.

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). You don't need to know how many nonzero columns (outer dimensions) are stored because that array (SparseMatrix.outerIndexPtr()) has one entry per column.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文