redux.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #ifndef IGL_REDUX_H
  2. #define IGL_REDUX_H
  3. #include "igl_inline.h"
  4. #include <Eigen/Core>
  5. #include <Eigen/Sparse>
  6. namespace igl
  7. {
  8. // REDUX Perform reductions on the rows or columns of a SparseMatrix. This is
  9. // _similar_ to DenseBase::redux, but different in two important ways:
  10. // 1. (unstored) Zeros are **not** "visited", however if the first element
  11. // in the column/row does not appear in the first row/column then the
  12. // reduction is assumed to start with zero. In this way, "any", "all",
  13. // "count"(non-zeros) work as expected. This means it is **not** possible
  14. // to use this to count (implicit) zeros.
  15. // 2. This redux is more powerful in the sense that A and B may have
  16. // different types. This makes it possible to count the number of
  17. // non-zeros in a SparseMatrix<bool> A into a VectorXi B.
  18. //
  19. // Inputs:
  20. // A m by n sparse matrix
  21. // dim dimension along which to sum (1 or 2)
  22. // func function handle with the prototype `X(Y a, I i, J j, Z b)` where a
  23. // is the running value, b is A(i,j)
  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 AType, typename Func, typename DerivedB>
  29. IGL_INLINE void redux(
  30. const Eigen::SparseMatrix<AType> & A,
  31. const int dim,
  32. const Func & func,
  33. Eigen::PlainObjectBase<DerivedB> & B);
  34. }
  35. #ifndef IGL_STATIC_LIBRARY
  36. # include "redux.cpp"
  37. #endif
  38. #endif