for_each.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "for_each.h"
  2. template <typename AType, typename Func>
  3. IGL_INLINE void igl::for_each(
  4. const Eigen::SparseMatrix<AType> & A,
  5. const Func & func)
  6. {
  7. // Can **not** use parallel for because this must be _in order_
  8. // Iterate over outside
  9. for(int k=0; k<A.outerSize(); ++k)
  10. {
  11. // Iterate over inside
  12. for(typename Eigen::SparseMatrix<AType>::InnerIterator it (A,k); it; ++it)
  13. {
  14. func(it.row(),it.col(),it.value());
  15. }
  16. }
  17. }
  18. template <typename DerivedA, typename Func>
  19. IGL_INLINE void igl::for_each(
  20. const Eigen::DenseBase<DerivedA> & A,
  21. const Func & func)
  22. {
  23. // Can **not** use parallel for because this must be _in order_
  24. if(A.IsRowMajor)
  25. {
  26. for(typename DerivedA::Index i = 0;i<A.rows();i++)
  27. {
  28. for(typename DerivedA::Index j = 0;j<A.cols();j++)
  29. {
  30. func(i,j,A(i,j));
  31. }
  32. }
  33. }else
  34. {
  35. for(typename DerivedA::Index j = 0;j<A.cols();j++)
  36. {
  37. for(typename DerivedA::Index i = 0;i<A.rows();i++)
  38. {
  39. func(i,j,A(i,j));
  40. }
  41. }
  42. }
  43. }
  44. #include <functional>