sum.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
  12. #include <Eigen/Sparse>
  13. namespace igl
  14. {
  15. // Note: If your looking for dense matrix matlab like sum for eigen matrics
  16. // just use:
  17. // M.colwise().sum() or M.rowwise().sum()
  18. //
  19. // Sum the columns or rows of a sparse matrix
  20. // Templates:
  21. // T should be a eigen sparse matrix primitive type like int or double
  22. // Inputs:
  23. // X m by n sparse matrix
  24. // dim dimension along which to sum (1 or 2)
  25. // Output:
  26. // S n-long sparse vector (if dim == 1)
  27. // or
  28. // S m-long sparse vector (if dim == 2)
  29. template <typename T>
  30. IGL_INLINE void sum(
  31. const Eigen::SparseMatrix<T>& X,
  32. const int dim,
  33. Eigen::SparseVector<T>& S);
  34. }
  35. #ifndef IGL_STATIC_LIBRARY
  36. # include "sum.cpp"
  37. #endif
  38. #endif