libigl v2.5.0
Loading...
Searching...
No Matches
for_each.h
Go to the documentation of this file.
1#ifndef IGL_FOR_EACH_H
2#define IGL_FOR_EACH_H
3#include "igl_inline.h"
4#include <Eigen/Core>
5#include <Eigen/Sparse>
6namespace igl
7{
17 template <typename AType, typename Func>
18 inline void for_each(
19 const Eigen::SparseMatrix<AType> & A,
20 const Func & func);
22 template <typename DerivedA, typename Func>
23 inline void for_each(
24 const Eigen::DenseBase<DerivedA> & A,
25 const Func & func);
26}
27
28// Implementation
29
30template <typename AType, typename Func>
31inline void igl::for_each(
32 const Eigen::SparseMatrix<AType> & A,
33 const Func & func)
34{
35 // Can **not** use parallel for because this must be _in order_
36 // Iterate over outside
37 for(int k=0; k<A.outerSize(); ++k)
38 {
39 // Iterate over inside
40 for(typename Eigen::SparseMatrix<AType>::InnerIterator it (A,k); it; ++it)
41 {
42 func(it.row(),it.col(),it.value());
43 }
44 }
45}
46
47template <typename DerivedA, typename Func>
48inline void igl::for_each(
49 const Eigen::DenseBase<DerivedA> & A,
50 const Func & func)
51{
52 // Can **not** use parallel for because this must be _in order_
53 if(A.IsRowMajor)
54 {
55 for(typename DerivedA::Index i = 0;i<A.rows();i++)
56 {
57 for(typename DerivedA::Index j = 0;j<A.cols();j++)
58 {
59 func(i,j,A(i,j));
60 }
61 }
62 }else
63 {
64 for(typename DerivedA::Index j = 0;j<A.cols();j++)
65 {
66 for(typename DerivedA::Index i = 0;i<A.rows();i++)
67 {
68 func(i,j,A(i,j));
69 }
70 }
71 }
72
73}
74
75//#ifndef IGL_STATIC_LIBRARY
76//# include "for_each.cpp"
77//#endif
78#endif
Definition AABB.h:17
void for_each(const Eigen::SparseMatrix< AType > &A, const Func &func)
FOR_EACH Call a given function for each non-zero (i.e., explicit value might actually be ==0) in a Sp...
Definition for_each.h:31