randperm.cpp 661 B

123456789101112131415161718192021222324252627
  1. #include "randperm.h"
  2. #include "colon.h"
  3. #include <algorithm>
  4. template <typename DerivedI>
  5. IGL_INLINE void igl::randperm(
  6. const int n,
  7. Eigen::PlainObjectBase<DerivedI> & I)
  8. {
  9. Eigen::VectorXi II;
  10. igl::colon(0,1,n-1,II);
  11. I = II;
  12. std::random_shuffle(I.data(),I.data()+n);
  13. }
  14. template <typename DerivedI>
  15. IGL_INLINE Eigen::PlainObjectBase<DerivedI> igl::randperm( const int n)
  16. {
  17. Eigen::PlainObjectBase<DerivedI> I;
  18. randperm(n,I);
  19. return I;
  20. }
  21. #ifndef IGL_HEADER_ONLY
  22. // Explicit template specialization
  23. template void igl::randperm<Eigen::Matrix<int, -1, 1, 0, -1, 1> >(int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  24. #endif