randperm.cpp 974 B

123456789101112131415161718192021222324252627
  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. #include "randperm.h"
  9. #include "colon.h"
  10. #include <algorithm>
  11. template <typename DerivedI>
  12. IGL_INLINE void igl::randperm(
  13. const int n,
  14. Eigen::PlainObjectBase<DerivedI> & I)
  15. {
  16. Eigen::VectorXi II;
  17. igl::colon(0,1,n-1,II);
  18. I = II;
  19. std::random_shuffle(I.data(),I.data()+n);
  20. }
  21. #ifdef IGL_STATIC_LIBRARY
  22. // Explicit template instantiation
  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. template void igl::randperm<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  25. #endif