Commit 5b878433 authored by David Bommes's avatar David Bommes
Browse files

handle csc matrices in gmm_to_eigen conversion

git-svn-id: http://www.openflipper.org/svnrepo/CoMISo/trunk@229 1355f012-dd97-4b2f-ae87-10fa9f823a57
parent 8aa73b2b
......@@ -745,6 +745,38 @@ void gmm_to_eigen( const gmm::row_matrix<GMM_VectorT>& _G, EIGEN_MatrixT& _E)
#endif
}
// convert a gmm col-sparse matrix into an eigen sparse matrix
template<class GMM_RealT, class EIGEN_MatrixT>
void gmm_to_eigen( const gmm::csc_matrix<GMM_RealT,0>& _G, EIGEN_MatrixT& _E)
{
#ifdef COMISO_EIGEN3_AVAILABLE
typedef typename EIGEN_MatrixT::Scalar Scalar;
typedef typename gmm::csc_matrix<GMM_RealT,0> GMM_MatrixT;
typedef typename gmm::linalg_traits<GMM_MatrixT>::const_sub_col_type ColT;
typedef typename gmm::linalg_traits<ColT>::const_iterator CIter;
// build matrix triplets
typedef Eigen::Triplet< Scalar > Triplet;
std::vector< Triplet > triplets;
triplets.reserve(gmm::nnz(_G));
for(unsigned int i=0; i<gmm::mat_ncols(_G); ++i)
{
ColT col = mat_const_col( _G, i );
CIter it = gmm::vect_const_begin( col );
CIter ite = gmm::vect_const_end( col );
for ( ; it!=ite; ++it )
triplets.push_back( Triplet( it.index(), i, *it));
}
// generate eigen matrix
_E = EIGEN_MatrixT( gmm::mat_nrows(_G), gmm::mat_ncols(_G));
_E.setFromTriplets( triplets.begin(), triplets.end());
#endif
}
//=============================================================================
} // namespace COMISO
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment