I wonder is there any good way to extract blocks/ROIs from Eigen::SparseMatrix? More precisely, what I want to extract is inner vectors.
What I want to do is like:
typedef Eigen::SparseMatrix<double,Eigen::RowMajor> SpMat;
// Prepare some sparse matrix
SpMat spmat;
// Extract lines from it
const SpMat& row_i = spmat.innerVector(i);
const SpMat& row_j = spmat.innerVector(j);
// Some calculation with row_i and row_j...
As I tested, the data of row_i
and row_j
is copied (!!) from spmat
.
However, obviously, it is inefficient.
The data (esp. row_i.m_data.m_values
& row_i.m_data.m_indices
) of inner vectors is continuous part of original data (spmat.m_data.m_values
& spmat.m_data.m_indices
resp.), so there should be smarter way.
I may be able to implement new method to do this, but it require me a tough digging into the source code. So I don't want to.
Any help is grateful! Thanks in advance.