【发布时间】:2015-07-22 00:56:18
【问题描述】:
我有一堆 (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。
我是这个图书馆的新手。任何帮助将不胜感激。
【问题讨论】:
-
它甚至不能为我编译。我不认为稀疏的
block可以在=的左侧。
标签: c++ matrix linear-algebra sparse-matrix eigen