mat_min.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef IGL_MAT_MIN_H
  2. #define IGL_MAT_MIN_H
  3. #include "igl_inline.h"
  4. #include <Eigen/Dense>
  5. namespace igl
  6. {
  7. // Ideally this becomes a super overloaded function supporting everything
  8. // that matlab's min supports
  9. // Min function for matrices to act like matlab's min function. Specifically
  10. // like [Y,I] = min(X,[],dim);
  11. //
  12. // Templates:
  13. // T should be a eigen matrix primitive type like int or double
  14. // Inputs:
  15. // X m by n matrix
  16. // dim dimension along which to take min
  17. // Outputs:
  18. // Y n-long sparse vector (if dim == 1)
  19. // or
  20. // Y m-long sparse vector (if dim == 2)
  21. // I vector the same size as Y containing the indices along dim of minimum
  22. // entries
  23. //
  24. // See also: mat_max
  25. template <typename T>
  26. IGL_INLINE void mat_min(
  27. const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & X,
  28. const int dim,
  29. Eigen::Matrix<T,Eigen::Dynamic,1> & Y,
  30. Eigen::Matrix<int,Eigen::Dynamic,1> & I);
  31. // Use Y = X.colwise().minCoeff() instead
  32. //// In-line wrapper
  33. //template <typename T>
  34. //IGL_INLINE Eigen::Matrix<T,Eigen::Dynamic,1> mat_min(
  35. // const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & X,
  36. // const int dim);
  37. }
  38. #ifdef IGL_HEADER_ONLY
  39. # include "mat_min.cpp"
  40. #endif
  41. #endif