#include "max.h" #include "for_each.h" #include "find_zero.h" template IGL_INLINE void igl::max( const Eigen::SparseMatrix & A, const int dim, Eigen::PlainObjectBase & B, Eigen::PlainObjectBase & I) { const int n = A.cols(); const int m = A.rows(); B.resize(dim==1?n:m); B.setConstant(std::numeric_limits::lowest()); I.resize(dim==1?n:m); for_each(A,[&B,&I,&dim](int i, int j,const typename DerivedB::Scalar v) { if(dim == 2) { std::swap(i,j); } // Coded as if dim == 1, assuming swap for dim == 2 if(v > B(j)) { B(j) = v; I(j) = i; } }); Eigen::VectorXi Z; find_zero(A,dim,Z); for(int j = 0;j B(j)) { B(j) = 0; I(j) = Z(j); } } } template IGL_INLINE void igl::max( const Eigen::DenseBase & X, const int dim, Eigen::PlainObjectBase & Y, Eigen::PlainObjectBase & I) { assert(dim==1||dim==2); // output size int n = (dim==1?X.cols():X.rows()); // resize output Y.resize(n); I.resize(n); // loop over dimension opposite of dim for(int j = 0;j, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::max, Eigen::Matrix >(Eigen::SparseMatrix const&, int, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); #endif