Commit 8aa73b2b authored by David Bommes's avatar David Bommes
Browse files

- fixed conversion between gmm and eigen (column vs. row matrices)

- implemented falback of Cholmod to EigenLDLT if cholmod is not available

git-svn-id: http://www.openflipper.org/svnrepo/CoMISo/trunk@228 1355f012-dd97-4b2f-ae87-10fa9f823a57
parent 190524c3
......@@ -118,6 +118,16 @@ private:
#include "CholmodSolverT.cc"
#endif
//=============================================================================
#else // COMISO_SUITESPARSE_AVAILABLE
#include<CoMISo/Solver/EigenLDLTSolver.hh>
//#warning "CholmodSolver not available, fallback to EigenLDLTSolver..."
namespace COMISO
{
typedef EigenLDLTSolver CholmodSolver;
} // namespace COMISO
#endif // COMISO_SUITESPARSE_AVAILABLE
//=============================================================================
#endif // COMISO_CHOLMOD_SOLVER_HH defined
......
......@@ -644,6 +644,7 @@ void eigen_to_cholmod_dense( const MatrixT& _A, cholmod_dense* &_AC, cholmod_com
}*/
/*
// convert a gmm col-sparse matrix into an eigen sparse matrix
template<class GMM_MatrixT, class EIGEN_MatrixT>
void gmm_to_eigen( const GMM_MatrixT& _G, EIGEN_MatrixT& _E)
......@@ -667,6 +668,7 @@ void gmm_to_eigen( const GMM_MatrixT& _G, EIGEN_MatrixT& _E)
CIter ite = gmm::vect_const_end( col );
for ( ; it!=ite; ++it )
triplets.push_back( Triplet( it.index(), i, *it));
}
// generate eigen matrix
......@@ -674,6 +676,75 @@ void gmm_to_eigen( const GMM_MatrixT& _G, EIGEN_MatrixT& _E)
_E.setFromTriplets( triplets.begin(), triplets.end());
#endif
}
*/
// convert a gmm col-sparse matrix into an eigen sparse matrix
template<class GMM_VectorT, class EIGEN_MatrixT>
void gmm_to_eigen( const gmm::col_matrix<GMM_VectorT>& _G, EIGEN_MatrixT& _E)
{
#ifdef COMISO_EIGEN3_AVAILABLE
typedef typename EIGEN_MatrixT::Scalar Scalar;
typedef typename gmm::col_matrix<GMM_VectorT> 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
}
// convert a gmm row-sparse matrix into an eigen sparse matrix
template<class GMM_VectorT, class EIGEN_MatrixT>
void gmm_to_eigen( const gmm::row_matrix<GMM_VectorT>& _G, EIGEN_MatrixT& _E)
{
#ifdef COMISO_EIGEN3_AVAILABLE
typedef typename EIGEN_MatrixT::Scalar Scalar;
typedef typename gmm::row_matrix<GMM_VectorT> GMM_MatrixT;
typedef typename gmm::linalg_traits<GMM_MatrixT>::const_sub_row_type RowT;
typedef typename gmm::linalg_traits<RowT>::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_nrows(_G); ++i)
{
RowT row = mat_const_row( _G, i );
CIter it = gmm::vect_const_begin( row );
CIter ite = gmm::vect_const_end( row );
for ( ; it!=ite; ++it )
triplets.push_back( Triplet( i, it.index(), *it));
}
// generate eigen matrix
_E = EIGEN_MatrixT( gmm::mat_nrows(_G), gmm::mat_ncols(_G));
_E.setFromTriplets( triplets.begin(), triplets.end());
#endif
}
//=============================================================================
} // namespace COMISO
......
Supports Markdown
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