mat_max.cpp 986 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. typename Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic>::Index PHONY;
  19. typename Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic>::Index i;
  20. T 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. template void igl::mat_max<double>(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, int, Eigen::Matrix<double, -1, 1, 0, -1, 1>&, Eigen::Matrix<int, -1, 1, 0, -1, 1>&);
  35. #endif