nchoosek.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Olga Diamanti, Alec Jacobson
  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_NCHOOSEK
  9. #define IGL_NCHOOSEK
  10. #include "igl_inline.h"
  11. #include "deprecated.h"
  12. #include <vector>
  13. #include <Eigen/Core>
  14. namespace igl
  15. {
  16. // NCHOOSEK Like matlab's nchoosek.
  17. //
  18. // Inputs:
  19. // n total number elements
  20. // k size of sub-set to consider
  21. // Returns number of k-size combinations out of the set [1,...,n]
  22. IGL_INLINE double nchoosek(const int n, const int k);
  23. //
  24. // Inputs:
  25. // V n-long vector of elements
  26. // k size of sub-set to consider
  27. // Outputs:
  28. // U nchoosek by k long matrix where each row is a unique k-size
  29. // combination
  30. template < typename DerivedV, typename DerivedU>
  31. IGL_INLINE void nchoosek(
  32. const Eigen::MatrixBase<DerivedV> & V,
  33. const int k,
  34. Eigen::PlainObjectBase<DerivedU> & U);
  35. }
  36. #ifndef IGL_STATIC_LIBRARY
  37. #include "nchoosek.cpp"
  38. #endif
  39. #endif /* defined(IGL_NCHOOSEK) */