[英]Multiplying sparse sub-matrices in Eigen
I am trying to multiply sub-matrices such as blocks, columns, and rows of Eigen::SparseMatrix. 我试图乘以子矩阵,如Eigen :: SparseMatrix的块,列和行。 However, whenever multiple sub-matrices are involved my program crashes (and gdb with it).
但是,每当涉及多个子矩阵时,我的程序崩溃(和gdb一起崩溃)。 I am working with Eigen 3.2.1.
我正在使用Eigen 3.2.1。
Here an example: 这是一个例子:
const unsigned m = 3, d = 1;
SparseMatrix<double> H(3*m,3*m);
H.setIdentity();
SparseMatrix<double> G(m,d);
G.coeffRef(0,0) = 1;
// this works
SparseMatrix<double> H_00 = H.block(0,0,m,m);
double val = SparseMatrix<double>(G.col(0).transpose() * H_00 * G.col(0)).coeffRef(0,0);
// this crashes
val = SparseMatrix<double>(G.col(0).transpose() * H.block(0,0,m,m) * G.col(0)).coeffRef(0,0);
Is there a way of avoiding the costly ( m
and d
>> 1000) construction of H_00? 有没有办法避免昂贵的(
m
和d
>> 1000)H_00的构造?
I checked out the 3.2.1 version of Eigen and this appears to be related to this Eigen bug: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=875 我检查了Eigen的3.2.1版本,这似乎与这个Eigen bug有关: http ://eigen.tuxfamily.org/bz/show_bug.cgi?id = 875
What happens is that a function (named SparseMatrixBase::nonZeros()
) internally is called recursively Unfortunately, this was not properly fixed in the 3.2 branch (with version 3.2.10 your example does not compile). 会发生什么是内部函数(名为
SparseMatrixBase::nonZeros()
)递归调用不幸的是,这在3.2分支中没有正确修复(版本3.2.10你的例子不能编译)。 It does work with the latest 3.3 version of Eigen, however (3.3rc1 at the moment) -- which answers your question: Yes, upgrade to Eigen 3.3rc1 (or newer) 它确实适用于最新的3.3版本的Eigen,但是(目前为3.3rc1) - 它回答了你的问题:是的,升级到Eigen 3.3rc1(或更新)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.