sum.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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_SUM_H
  9. #define IGL_SUM_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Sparse>
  12. namespace igl
  13. {
  14. /// Sum the columns or rows of a sparse matrix
  15. ///
  16. /// @tparam should be a eigen sparse matrix primitive type like int or double
  17. /// @param[in] X m by n sparse matrix
  18. /// @param[in] dim dimension along which to sum (1 or 2)
  19. /// @param[out] S n-long sparse vector (if dim == 1)
  20. /// or m-long sparse vector (if dim == 2)
  21. ///
  22. /// \note If your looking for dense matrix matlab like sum for eigen matrics
  23. /// just use:
  24. ///
  25. /// M.colwise().sum() or M.rowwise().sum()
  26. ///
  27. template <typename T>
  28. IGL_INLINE void sum(
  29. const Eigen::SparseMatrix<T>& X,
  30. const int dim,
  31. Eigen::SparseVector<T>& S);
  32. /// \overload
  33. /// \brief Sum is "conducted" in the type of DerivedB::Scalar
  34. /// @tparam AType should be a eigen sparse matrix primitive type like int or double
  35. /// @tparam DerivedB should be a eigen dense matrix primitive type like int or double
  36. template <typename AType, typename DerivedB>
  37. IGL_INLINE void sum(
  38. const Eigen::SparseMatrix<AType> & A,
  39. const int dim,
  40. Eigen::PlainObjectBase<DerivedB>& B);
  41. }
  42. #ifndef IGL_STATIC_LIBRARY
  43. # include "sum.cpp"
  44. #endif
  45. #endif