nchoosek.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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::PlainObjectBase<DerivedV> & V,
  33. const int k,
  34. Eigen::PlainObjectBase<DerivedU> & U);
  35. // This version has a strange interface and confusing parameters. It seems to
  36. // reproduce matlab's
  37. //
  38. // nchoosek(3:5,2)
  39. //
  40. // Then one should use
  41. //
  42. // igl::nchoosek(3,2,6,res);
  43. //
  44. IGL_INLINE
  45. IGL_DEPRECATED(
  46. void nchoosek(
  47. int offset,
  48. int k,
  49. int N,
  50. std::vector<std::vector<int> > &allCombs));
  51. }
  52. #ifndef IGL_STATIC_LIBRARY
  53. #include "nchoosek.cpp"
  54. #endif
  55. #endif /* defined(IGL_NCHOOSEK) */