Eigen 由稀疏矩阵生成三元组(稀疏矩阵分块操作经常用到)
Eigen 由稀疏矩阵生成三元组(稀疏矩阵分块操作经常用到)
vector<Triplet<double>> BoundedDistortion::SparseToTriplet(SparseMatrix<double> A)
{
vector<Triplet<double>> A_Triplet;
for (int k = 0; k < A.outerSize(); ++k)
{
for (SparseMatrix<double>::InnerIterator it(A, k); it; ++it)
{
A_Triplet.push_back(Triplet<double>(it.row(), it.col(), it.value()));
cout << 1 + it.row() << "\t"; // row index
cout << 1 + it.col() << "\t"; // col index (here it is equal to k)
cout << it.value() << endl;
}
}
}