#ifndef IGL_MAT_MAX_H #define IGL_MAT_MAX_H #include namespace igl { // Ideally this becomes a super overloaded function supporting everything // that matlab's max supports // Max function for matrices to act like matlab's max function. Specifically // like [Y,I] = max(X,[],dim); // // Templates: // T should be a eigen matrix primitive type like int or double // Inputs: // X m by n matrix // dim dimension along which to take max // Outputs: // Y n-long sparse vector (if dim == 1) // or // Y m-long sparse vector (if dim == 2) // I vector the same size as Y containing the indices along dim of maximum // entries template inline void mat_max( const Eigen::Matrix & X, const int dim, Eigen::Matrix & Y, Eigen::Matrix & I); } // Implementation template inline void igl::mat_max( const Eigen::Matrix & X, const int dim, Eigen::Matrix & Y, Eigen::Matrix & 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