10#ifndef EIGEN_VISITOR_H
11#define EIGEN_VISITOR_H
17template<
typename Visitor,
typename Derived,
int UnrollCount>
21 col = (UnrollCount-1) / Derived::RowsAtCompileTime,
22 row = (UnrollCount-1) % Derived::RowsAtCompileTime
25 static inline void run(
const Derived &mat, Visitor& visitor)
27 visitor_impl<Visitor, Derived, UnrollCount-1>::run(mat, visitor);
28 visitor(mat.coeff(row, col), row, col);
32template<
typename Visitor,
typename Derived>
33struct visitor_impl<Visitor, Derived, 1>
35 static inline void run(
const Derived &mat, Visitor& visitor)
37 return visitor.init(mat.coeff(0, 0), 0, 0);
41template<
typename Visitor,
typename Derived>
42struct visitor_impl<Visitor, Derived, Dynamic>
44 typedef typename Derived::Index Index;
45 static inline void run(
const Derived& mat, Visitor& visitor)
47 visitor.init(mat.coeff(0,0), 0, 0);
48 for(Index i = 1; i < mat.rows(); ++i)
49 visitor(mat.coeff(i, 0), i, 0);
50 for(Index j = 1; j < mat.cols(); ++j)
51 for(Index i = 0; i < mat.rows(); ++i)
52 visitor(mat.coeff(i, j), i, j);
75template<
typename Derived>
76template<
typename Visitor>
79 typedef typename internal::remove_all<typename Derived::Nested>::type ThisNested;
80 typename Derived::Nested thisNested(derived());
86 <= EIGEN_UNROLLING_LIMIT };
87 return internal::visitor_impl<Visitor, ThisNested,
89 >::run(thisNested, visitor);
97template <
typename Derived>
100 typedef typename Derived::Index Index;
101 typedef typename Derived::Scalar Scalar;
104 inline void init(
const Scalar& value, Index i, Index j)
117template <
typename Derived>
118struct min_coeff_visitor : coeff_visitor<Derived>
120 typedef typename Derived::Index Index;
121 typedef typename Derived::Scalar Scalar;
122 void operator() (
const Scalar& value, Index i, Index j)
124 if(value < this->res)
133template<
typename Scalar>
134struct functor_traits<min_coeff_visitor<Scalar> > {
136 Cost = NumTraits<Scalar>::AddCost
145template <
typename Derived>
146struct max_coeff_visitor : coeff_visitor<Derived>
148 typedef typename Derived::Index Index;
149 typedef typename Derived::Scalar Scalar;
150 void operator() (
const Scalar& value, Index i, Index j)
152 if(value > this->res)
161template<
typename Scalar>
162struct functor_traits<max_coeff_visitor<Scalar> > {
164 Cost = NumTraits<Scalar>::AddCost
175template<
typename Derived>
176template<
typename IndexType>
177typename internal::traits<Derived>::Scalar
180 internal::min_coeff_visitor<Derived> minVisitor;
181 this->
visit(minVisitor);
182 *rowId = minVisitor.row;
183 if (colId) *colId = minVisitor.col;
184 return minVisitor.res;
192template<
typename Derived>
193template<
typename IndexType>
194typename internal::traits<Derived>::Scalar
197 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
198 internal::min_coeff_visitor<Derived> minVisitor;
199 this->
visit(minVisitor);
201 return minVisitor.res;
209template<
typename Derived>
210template<
typename IndexType>
211typename internal::traits<Derived>::Scalar
214 internal::max_coeff_visitor<Derived> maxVisitor;
215 this->
visit(maxVisitor);
216 *rowPtr = maxVisitor.row;
217 if (colPtr) *colPtr = maxVisitor.col;
218 return maxVisitor.res;
226template<
typename Derived>
227template<
typename IndexType>
228typename internal::traits<Derived>::Scalar
231 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
232 internal::max_coeff_visitor<Derived> maxVisitor;
233 this->
visit(maxVisitor);
235 return maxVisitor.res;
void visit(Visitor &func) const
Definition Visitor.h:77
internal::traits< Derived >::Scalar maxCoeff() const
Definition Redux.h:349
internal::traits< Derived >::Scalar minCoeff() const
Definition Redux.h:339
@ CoeffReadCost
Definition DenseBase.h:172
@ RowsAtCompileTime
Definition DenseBase.h:102
@ SizeAtCompileTime
Definition DenseBase.h:115