count.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #ifndef IGL_COUNT_H
  9. #define IGL_COUNT_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Sparse>
  12. namespace igl
  13. {
  14. // Note: If your looking for dense matrix matlab like sum for eigen matrics
  15. // just use:
  16. // M.colwise().count() or M.rowwise().count()
  17. //
  18. // Count the number of non-zeros in the columns or rows of a sparse matrix
  19. //
  20. // Inputs:
  21. // X m by n sparse matrix
  22. // dim dimension along which to sum (1 or 2)
  23. // Output:
  24. // S n-long sparse vector (if dim == 1)
  25. // or
  26. // S m-long sparse vector (if dim == 2)
  27. template <typename XType, typename SType>
  28. IGL_INLINE void count(
  29. const Eigen::SparseMatrix<XType>& X,
  30. const int dim,
  31. Eigen::SparseVector<SType>& S);
  32. template <typename XType, typename DerivedS>
  33. IGL_INLINE void count(
  34. const Eigen::SparseMatrix<XType>& X,
  35. const int dim,
  36. Eigen::PlainObjectBase<DerivedS>& S);
  37. }
  38. #ifndef IGL_STATIC_LIBRARY
  39. # include "count.cpp"
  40. #endif
  41. #endif