#include "diag.h" #include "verbose.h" template IGL_INLINE void igl::diag( const Eigen::SparseMatrix& X, Eigen::SparseVector& V) { // Get size of input int m = X.rows(); int n = X.cols(); V = Eigen::SparseVector((m>n?n:m)); // Iterate over outside for(int k=0; k::InnerIterator it (X,k); it; ++it) { if(it.col() == it.row()) { V.coeffRef(it.col()) += it.value(); } } } } template IGL_INLINE void igl::diag( const Eigen::SparseVector& V, Eigen::SparseMatrix& X) { // clear and resize output Eigen::DynamicSparseMatrix dyn_X(V.size(),V.size()); // loop over non-zeros for(typename Eigen::SparseVector::InnerIterator it(V); it; ++it) { dyn_X.coeffRef(it.index(),it.index()) += it.value(); } X = Eigen::SparseMatrix(dyn_X); } #ifndef IGL_HEADER_ONLY // Explicit template specialization #endif