Block operations for sparse matrices - Eigen Toolbox - C++
#include "Eigen/Dense"
#include "Eigen/Sparse"
#include <iostream>
using namespace std;
using namespace Eigen;
int main()
{
MatrixXd silly(6, 3);
silly << 0, 1, 2,
0, 3, 0,
2, 0, 0,
3, 2, 1,
0, 1, 0,
2, 0, 0;
SparseMatrix<double> sparse_silly,temp;
sparse_silly= Eigen::SparseMatrix<double>(6, 3);
temp = Eigen::SparseMatrix<double>(6, 3);
sparse_silly = silly.sparseView();
std::cout << "Whole Matrix" << std::endl;
std::cout << sparse_silly << std::endl;
temp.block(0, 0, 2, 2)=sparse_silly.block(0, 0, 2, 2);
std::cout << "block of matrix" << std::endl;
std::cout << temp.block(0, 0, 2, 2) << std::endl;
getchar();
return 0;
}
在上面的代码中,使用Eigen工具箱时稀疏矩阵的块操作无法正常工作。我想将一个sparse_silly中的块分配给temp矩阵中的一个块。输出打印的temp矩阵为零。如果我在概念上遗漏了什么,有人能帮助我吗?最近的文档说稀疏矩阵有块操作。