sum.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 <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_SUM_H
  9. #define IGL_SUM_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().sum() or M.rowwise().sum()
  17. //
  18. // Sum the columns or rows of a sparse matrix
  19. // Templates:
  20. // T should be a eigen sparse matrix primitive type like int or double
  21. // Inputs:
  22. // X m by n sparse matrix
  23. // dim dimension along which to sum (1 or 2)
  24. // Output:
  25. // S n-long sparse vector (if dim == 1)
  26. // or
  27. // S m-long sparse vector (if dim == 2)
  28. template <typename T>
  29. IGL_INLINE void sum(
  30. const Eigen::SparseMatrix<T>& X,
  31. const int dim,
  32. Eigen::SparseVector<T>& S);
  33. // Sum is "conducted" in the type of DerivedB::Scalar
  34. template <typename AType, typename DerivedB>
  35. IGL_INLINE void sum(
  36. const Eigen::SparseMatrix<AType> & A,
  37. const int dim,
  38. Eigen::PlainObjectBase<DerivedB>& B);
  39. }
  40. #ifndef IGL_STATIC_LIBRARY
  41. # include "sum.cpp"
  42. #endif
  43. #endif