randperm.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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. //template <typename DerivedI>
  22. //IGL_INLINE Eigen::PlainObjectBase<DerivedI> igl::randperm( const int n)
  23. //{
  24. // Eigen::PlainObjectBase<DerivedI> I;
  25. // randperm(n,I);
  26. // return I;
  27. //}
  28. #ifdef IGL_STATIC_LIBRARY
  29. // Explicit template specialization
  30. template void igl::randperm<Eigen::Matrix<int, -1, 1, 0, -1, 1> >(int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  31. //template Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > igl::randperm<Eigen::Matrix<int, -1, 1, 0, -1, 1> >(int);
  32. #endif