nchoosek.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 <vector>
  12. #include <Eigen/Core>
  13. namespace igl
  14. {
  15. /// Binomial coefficient. Like matlab's nchoosek.
  16. ///
  17. /// @param[in] n total number elements
  18. /// @param[in] k size of sub-set to consider
  19. /// @return number of k-size combinations out of the set [1,...,n]
  20. IGL_INLINE double nchoosek(const int n, const int k);
  21. /// All combinations . Like matlab's nchoosek.
  22. ///
  23. /// @param[in] V n-long vector of elements
  24. /// @param[in] k size of sub-set to consider
  25. /// @param[out] U nchoosek by k long matrix where each row is a unique k-size
  26. /// combination
  27. template < typename DerivedV, typename DerivedU>
  28. IGL_INLINE void nchoosek(
  29. const Eigen::MatrixBase<DerivedV> & V,
  30. const int k,
  31. Eigen::PlainObjectBase<DerivedU> & U);
  32. }
  33. #ifndef IGL_STATIC_LIBRARY
  34. #include "nchoosek.cpp"
  35. #endif
  36. #endif /* defined(IGL_NCHOOSEK) */