#include "slice_into.h" // Bug in unsupported/Eigen/SparseExtra needs iostream first #include #include template IGL_INLINE void igl::slice_into( const Eigen::SparseMatrix& X, const Eigen::Matrix & R, const Eigen::Matrix & C, Eigen::SparseMatrix& Y) { int xm = X.rows(); int xn = X.cols(); assert(R.size() == xm); assert(C.size() == xn); #ifndef NDEBUG int ym = Y.size(); int yn = Y.size(); assert(R.minCoeff() >= 0); assert(R.maxCoeff() < ym); assert(C.minCoeff() >= 0); assert(C.maxCoeff() < yn); #endif // create temporary dynamic sparse matrix Eigen::DynamicSparseMatrix dyn_Y(Y); // Iterate over outside for(int k=0; k::InnerIterator it (X,k); it; ++it) { dyn_Y.coeffRef(R(it.row()),C(it.col())) = it.value(); } } Y = Eigen::SparseMatrix(dyn_Y); } template IGL_INLINE void igl::slice_into( const Eigen::PlainObjectBase & X, const Eigen::Matrix & R, const Eigen::Matrix & C, Eigen::PlainObjectBase & Y) { int xm = X.rows(); int xn = X.cols(); assert(R.size() == xm); assert(C.size() == xn); #ifndef NDEBUG int ym = Y.size(); int yn = Y.size(); assert(R.minCoeff() >= 0); assert(R.maxCoeff() < ym); assert(C.minCoeff() >= 0); assert(C.maxCoeff() < yn); #endif // Build reindexing maps for columns and rows, -1 means not in map Eigen::Matrix RI; RI.resize(xm); for(int i = 0;i IGL_INLINE void igl::slice_into( const Eigen::PlainObjectBase & X, const Eigen::Matrix & R, Eigen::PlainObjectBase & Y) { // phony column indices Eigen::Matrix C; C.resize(1); C(0) = 0; return igl::slice_into(X,R,C,Y); } #ifndef IGL_HEADER_ONLY // Explicit template specialization // generated by autoexplicit.sh template void igl::slice_into >(Eigen::PlainObjectBase > const&, Eigen::Matrix const&, Eigen::Matrix const&, Eigen::PlainObjectBase >&); template void igl::slice_into >(Eigen::PlainObjectBase > const&, Eigen::Matrix const&, Eigen::PlainObjectBase >&); #endif