25 #ifndef EIGEN_VISITOR_H
26 #define EIGEN_VISITOR_H
32 template<
typename Visitor,
typename Derived,
int UnrollCount>
36 col = (UnrollCount-1) / Derived::RowsAtCompileTime,
37 row = (UnrollCount-1) % Derived::RowsAtCompileTime
40 static inline void run(
const Derived &mat, Visitor& visitor)
42 visitor_impl<Visitor, Derived, UnrollCount-1>::run(mat, visitor);
47 template<
typename Visitor,
typename Derived>
48 struct visitor_impl<Visitor, Derived, 1>
50 static inline void run(
const Derived &mat, Visitor& visitor)
52 return visitor.init(mat.coeff(0, 0), 0, 0);
56 template<
typename Visitor,
typename Derived>
57 struct visitor_impl<Visitor, Derived,
Dynamic>
59 typedef typename Derived::Index Index;
60 static inline void run(
const Derived& mat, Visitor& visitor)
62 visitor.init(mat.coeff(0,0), 0, 0);
63 for(Index i = 1; i < mat.rows(); ++i)
64 visitor(mat.coeff(i, 0), i, 0);
65 for(Index j = 1; j < mat.cols(); ++j)
66 for(Index i = 0; i < mat.rows(); ++i)
67 visitor(mat.coeff(i, j), i, j);
90 template<
typename Derived>
91 template<
typename Visitor>
94 enum { unroll = SizeAtCompileTime !=
Dynamic
96 && (SizeAtCompileTime == 1 || internal::functor_traits<Visitor>::Cost !=
Dynamic)
97 && SizeAtCompileTime * CoeffReadCost + (SizeAtCompileTime-1) * internal::functor_traits<Visitor>::Cost
99 return internal::visitor_impl<Visitor, Derived,
101 >::run(derived(), visitor);
109 template <
typename Derived>
112 typedef typename Derived::Index Index;
113 typedef typename Derived::Scalar Scalar;
116 inline void init(
const Scalar& value, Index i, Index j)
129 template <
typename Derived>
130 struct min_coeff_visitor : coeff_visitor<Derived>
132 typedef typename Derived::Index Index;
133 typedef typename Derived::Scalar Scalar;
134 void operator() (
const Scalar& value, Index i, Index j)
136 if(value < this->res)
145 template<
typename Scalar>
146 struct functor_traits<min_coeff_visitor<Scalar> > {
157 template <
typename Derived>
158 struct max_coeff_visitor : coeff_visitor<Derived>
160 typedef typename Derived::Index Index;
161 typedef typename Derived::Scalar Scalar;
162 void operator() (
const Scalar& value, Index i, Index j)
164 if(value > this->res)
173 template<
typename Scalar>
174 struct functor_traits<max_coeff_visitor<Scalar> > {
187 template<
typename Derived>
188 template<
typename IndexType>
189 typename internal::traits<Derived>::Scalar
192 internal::min_coeff_visitor<Derived> minVisitor;
193 this->visit(minVisitor);
194 *row = minVisitor.row;
195 if (col) *col = minVisitor.col;
196 return minVisitor.res;
204 template<
typename Derived>
205 template<
typename IndexType>
206 typename internal::traits<Derived>::Scalar
210 internal::min_coeff_visitor<Derived> minVisitor;
211 this->visit(minVisitor);
212 *index = (RowsAtCompileTime==1) ? minVisitor.col : minVisitor.row;
213 return minVisitor.res;
221 template<
typename Derived>
222 template<
typename IndexType>
223 typename internal::traits<Derived>::Scalar
226 internal::max_coeff_visitor<Derived> maxVisitor;
227 this->visit(maxVisitor);
228 *row = maxVisitor.row;
229 if (col) *col = maxVisitor.col;
230 return maxVisitor.res;
238 template<
typename Derived>
239 template<
typename IndexType>
240 typename internal::traits<Derived>::Scalar
244 internal::max_coeff_visitor<Derived> maxVisitor;
245 this->visit(maxVisitor);
246 *index = (RowsAtCompileTime==1) ? maxVisitor.col : maxVisitor.row;
247 return maxVisitor.res;
252 #endif // EIGEN_VISITOR_H