redux.cpp 733 B

1234567891011121314151617181920212223242526272829303132
  1. #include "redux.h"
  2. #include "for_each.h"
  3. template <typename AType, typename Func, typename DerivedB>
  4. IGL_INLINE void igl::redux(
  5. const Eigen::SparseMatrix<AType> & A,
  6. const int dim,
  7. const Func & func,
  8. Eigen::PlainObjectBase<DerivedB> & B)
  9. {
  10. assert((dim == 1 || dim == 2) && "dim must be 2 or 1");
  11. // Get size of input
  12. int m = A.rows();
  13. int n = A.cols();
  14. // resize output
  15. B = DerivedB::Zero(dim==1?n:m);
  16. const auto func_wrap = [&func,&B,&dim](const int i, const int j, const int v)
  17. {
  18. if(dim == 1)
  19. {
  20. B(j) = i == 0? v : func(B(j),v);
  21. }else
  22. {
  23. B(i) = j == 0? v : func(B(i),v);
  24. }
  25. };
  26. for_each(A,func_wrap);
  27. }
  28. #ifdef IGL_STATIC_LIBRARY
  29. // Explicit template specialization
  30. #endif