|
@@ -16,15 +16,63 @@ namespace igl
|
|
|
//
|
|
|
// See also: std::for_each
|
|
|
template <typename AType, typename Func>
|
|
|
- IGL_INLINE void for_each(
|
|
|
+ inline void for_each(
|
|
|
const Eigen::SparseMatrix<AType> & A,
|
|
|
const Func & func);
|
|
|
template <typename DerivedA, typename Func>
|
|
|
- IGL_INLINE void for_each(
|
|
|
+ inline void for_each(
|
|
|
const Eigen::DenseBase<DerivedA> & A,
|
|
|
const Func & func);
|
|
|
}
|
|
|
-#ifndef IGL_STATIC_LIBRARY
|
|
|
-# include "for_each.cpp"
|
|
|
-#endif
|
|
|
+
|
|
|
+// Implementation
|
|
|
+
|
|
|
+template <typename AType, typename Func>
|
|
|
+inline void igl::for_each(
|
|
|
+ const Eigen::SparseMatrix<AType> & A,
|
|
|
+ const Func & func)
|
|
|
+{
|
|
|
+ // Can **not** use parallel for because this must be _in order_
|
|
|
+ // Iterate over outside
|
|
|
+ for(int k=0; k<A.outerSize(); ++k)
|
|
|
+ {
|
|
|
+ // Iterate over inside
|
|
|
+ for(typename Eigen::SparseMatrix<AType>::InnerIterator it (A,k); it; ++it)
|
|
|
+ {
|
|
|
+ func(it.row(),it.col(),it.value());
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+template <typename DerivedA, typename Func>
|
|
|
+inline void igl::for_each(
|
|
|
+ const Eigen::DenseBase<DerivedA> & A,
|
|
|
+ const Func & func)
|
|
|
+{
|
|
|
+ // Can **not** use parallel for because this must be _in order_
|
|
|
+ if(A.IsRowMajor)
|
|
|
+ {
|
|
|
+ for(typename DerivedA::Index i = 0;i<A.rows();i++)
|
|
|
+ {
|
|
|
+ for(typename DerivedA::Index j = 0;j<A.cols();j++)
|
|
|
+ {
|
|
|
+ func(i,j,A(i,j));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ for(typename DerivedA::Index j = 0;j<A.cols();j++)
|
|
|
+ {
|
|
|
+ for(typename DerivedA::Index i = 0;i<A.rows();i++)
|
|
|
+ {
|
|
|
+ func(i,j,A(i,j));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+//#ifndef IGL_STATIC_LIBRARY
|
|
|
+//# include "for_each.cpp"
|
|
|
+//#endif
|
|
|
#endif
|