mat_max.cpp 701 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "mat_max.h"
  2. template <typename T>
  3. IGL_INLINE void igl::mat_max(
  4. const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & X,
  5. const int dim,
  6. Eigen::Matrix<T,Eigen::Dynamic,1> & Y,
  7. Eigen::Matrix<int,Eigen::Dynamic,1> & I)
  8. {
  9. assert(dim==1||dim==2);
  10. // output size
  11. int n = (dim==1?X.cols():X.rows());
  12. // resize output
  13. Y.resize(n);
  14. I.resize(n);
  15. // loop over dimension opposite of dim
  16. for(int j = 0;j<n;j++)
  17. {
  18. int PHONY;
  19. int i;
  20. int m;
  21. if(dim==1)
  22. {
  23. m = X.col(j).maxCoeff(&i,&PHONY);
  24. }else
  25. {
  26. m = X.row(j).maxCoeff(&PHONY,&i);
  27. }
  28. Y(j) = m;
  29. I(j) = i;
  30. }
  31. }
  32. #ifndef IGL_HEADER_ONLY
  33. // Explicit template specialization
  34. #endif