count.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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. /// Count the number of non-zeros in the columns or rows of a sparse matrix
  15. ///
  16. /// @param[in] X m by n sparse matrix
  17. /// @param[in] dim dimension along which to sum (1 or 2)
  18. /// @param[out] S n-long _sparse_ vector (if dim == 1) or m-long sparse vector
  19. /// (if dim == 2)
  20. ///
  21. /// \note If your looking for dense matrix matlab like sum for eigen matrics
  22. /// just use:
  23. /// M.colwise().count() or M.rowwise().count()
  24. ///
  25. template <typename XType, typename SType>
  26. IGL_INLINE void count(
  27. const Eigen::SparseMatrix<XType>& X,
  28. const int dim,
  29. Eigen::SparseVector<SType>& S);
  30. /// \overload
  31. ///
  32. /// \brief Outputs a dense vector.
  33. template <typename XType, typename DerivedS>
  34. IGL_INLINE void count(
  35. const Eigen::SparseMatrix<XType>& X,
  36. const int dim,
  37. Eigen::PlainObjectBase<DerivedS>& S);
  38. }
  39. #ifndef IGL_STATIC_LIBRARY
  40. # include "count.cpp"
  41. #endif
  42. #endif