sortrows.h 949 B

12345678910111213141516171819202122232425262728293031323334
  1. #ifndef IGL_SORTROWS_H
  2. #define IGL_SORTROWS_H
  3. #include "igl_inline.h"
  4. #include <vector>
  5. #include <Eigen/Core>
  6. namespace igl
  7. {
  8. // Act like matlab's [Y,I] = sortrows(X)
  9. //
  10. // Templates:
  11. // DerivedX derived scalar type, e.g. MatrixXi or MatrixXd
  12. // DerivedIX derived integer type, e.g. MatrixXi
  13. // Inputs:
  14. // X m by n matrix whose entries are to be sorted
  15. // ascending sort ascending (true, matlab default) or descending (false)
  16. // Outputs:
  17. // Y m by n matrix whose entries are sorted
  18. // IX m by n matrix of indices so that if dim = 1, then in matlab notation
  19. // for j = 1:n, Y(:,j) = X(I(:,j),j); end
  20. template <typename DerivedX, typename DerivedIX>
  21. IGL_INLINE void sortrows(
  22. const Eigen::PlainObjectBase<DerivedX>& X,
  23. const bool ascending,
  24. Eigen::PlainObjectBase<DerivedX>& Y,
  25. Eigen::PlainObjectBase<DerivedIX>& IX);
  26. }
  27. #ifdef IGL_HEADER_ONLY
  28. # include "sortrows.cpp"
  29. #endif
  30. #endif