mat_min.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_MAT_MIN_H
  9. #define IGL_MAT_MIN_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Dense>
  12. namespace igl
  13. {
  14. // Ideally this becomes a super overloaded function supporting everything
  15. // that matlab's min supports
  16. // Min function for matrices to act like matlab's min function. Specifically
  17. // like [Y,I] = min(X,[],dim);
  18. //
  19. // Templates:
  20. // T should be a eigen matrix primitive type like int or double
  21. // Inputs:
  22. // X m by n matrix
  23. // dim dimension along which to take min
  24. // Outputs:
  25. // Y n-long sparse vector (if dim == 1)
  26. // or
  27. // Y m-long sparse vector (if dim == 2)
  28. // I vector the same size as Y containing the indices along dim of minimum
  29. // entries
  30. //
  31. // See also: mat_max
  32. template <typename T>
  33. IGL_INLINE void mat_min(
  34. const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & X,
  35. const int dim,
  36. Eigen::Matrix<T,Eigen::Dynamic,1> & Y,
  37. Eigen::Matrix<int,Eigen::Dynamic,1> & I);
  38. // Use Y = X.colwise().minCoeff() instead
  39. //// In-line wrapper
  40. //template <typename T>
  41. //IGL_INLINE Eigen::Matrix<T,Eigen::Dynamic,1> mat_min(
  42. // const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & X,
  43. // const int dim);
  44. }
  45. #ifndef IGL_STATIC_LIBRARY
  46. # include "mat_min.cpp"
  47. #endif
  48. #endif