我有一堆大小为(n*n)的稀疏矩阵,它们分别称为M1、M2... Mj。
我想要创建一个大的块对角稀疏矩阵,它看起来像这样:
|M1 0 0 . . . |
|0 M2 0 . . . |
|. . . . . . |
|. . . Mj-1 0|
|0 0 0 ... Mj|
我尝试了以下操作:
Eigen::SparseMatrix<double> MatBLK(j*n,j*n);
MatBLK.reserve(Eigen::VectorXd::Constant(j*n,3);
//I know that there are at most 3 nonzero elements per row
MatBLK.topLeftCorner(n,n) = M1.topLeftCorner(n,n);
MatBLK.block(n,n,n,n) = M2.topLeftCorner(n,n);
.
.
MatBLK(bottomRightCorner(n,n)) = Mj.topLeftCorner(n,n);
MatBLK.makeCompressed();
这种方法不起作用。较小矩阵中的值未复制到较大的块矩阵中。该函数:
MatBLK.nonZeros()
返回0。
我是新手,对这个库不太熟悉。任何帮助将不胜感激。