10 #ifndef EIGEN_VISITOR_H 11 #define EIGEN_VISITOR_H 17 template<
typename Visitor,
typename Derived,
int UnrollCount>
21 col = (UnrollCount-1) / Derived::RowsAtCompileTime,
22 row = (UnrollCount-1) % Derived::RowsAtCompileTime
26 static inline void run(
const Derived &mat, Visitor& visitor)
28 visitor_impl<Visitor, Derived, UnrollCount-1>::run(mat, visitor);
29 visitor(mat.coeff(row, col), row, col);
33 template<
typename Visitor,
typename Derived>
34 struct visitor_impl<Visitor, Derived, 1>
37 static inline void run(
const Derived &mat, Visitor& visitor)
39 return visitor.init(mat.coeff(0, 0), 0, 0);
43 template<
typename Visitor,
typename Derived>
44 struct visitor_impl<Visitor, Derived,
Dynamic>
47 static inline void run(
const Derived& mat, Visitor& visitor)
49 visitor.init(mat.coeff(0,0), 0, 0);
50 for(
Index i = 1; i < mat.rows(); ++i)
51 visitor(mat.coeff(i, 0), i, 0);
52 for(
Index j = 1; j < mat.cols(); ++j)
53 for(
Index i = 0; i < mat.rows(); ++i)
54 visitor(mat.coeff(i, j), i, j);
59 template<
typename XprType>
60 class visitor_evaluator
64 explicit visitor_evaluator(
const XprType &xpr) : m_evaluator(xpr), m_xpr(xpr) {}
66 typedef typename XprType::Scalar Scalar;
67 typedef typename XprType::CoeffReturnType CoeffReturnType;
70 RowsAtCompileTime = XprType::RowsAtCompileTime,
71 CoeffReadCost = internal::evaluator<XprType>::CoeffReadCost
74 EIGEN_DEVICE_FUNC
Index rows()
const {
return m_xpr.rows(); }
75 EIGEN_DEVICE_FUNC
Index cols()
const {
return m_xpr.cols(); }
76 EIGEN_DEVICE_FUNC
Index size()
const {
return m_xpr.size(); }
78 EIGEN_DEVICE_FUNC CoeffReturnType coeff(
Index row,
Index col)
const 79 {
return m_evaluator.coeff(row, col); }
82 internal::evaluator<XprType> m_evaluator;
104 template<
typename Derived>
105 template<
typename Visitor>
109 typedef typename internal::visitor_evaluator<Derived> ThisEvaluator;
110 ThisEvaluator thisEval(derived());
113 unroll = SizeAtCompileTime !=
Dynamic 114 && SizeAtCompileTime * ThisEvaluator::CoeffReadCost + (SizeAtCompileTime-1) * internal::functor_traits<Visitor>::Cost <= EIGEN_UNROLLING_LIMIT
116 return internal::visitor_impl<Visitor, ThisEvaluator, unroll ? int(SizeAtCompileTime) : Dynamic>::run(thisEval, visitor);
124 template <
typename Derived>
127 typedef typename Derived::Scalar Scalar;
131 inline void init(
const Scalar& value,
Index i,
Index j)
144 template <
typename Derived>
145 struct min_coeff_visitor : coeff_visitor<Derived>
147 typedef typename Derived::Scalar Scalar;
149 void operator() (
const Scalar& value,
Index i,
Index j)
151 if(value < this->res)
160 template<
typename Scalar>
161 struct functor_traits<min_coeff_visitor<Scalar> > {
172 template <
typename Derived>
173 struct max_coeff_visitor : coeff_visitor<Derived>
175 typedef typename Derived::Scalar Scalar;
177 void operator() (
const Scalar& value,
Index i,
Index j)
179 if(value > this->res)
188 template<
typename Scalar>
189 struct functor_traits<max_coeff_visitor<Scalar> > {
203 template<
typename Derived>
204 template<
typename IndexType>
206 typename internal::traits<Derived>::Scalar
209 internal::min_coeff_visitor<Derived> minVisitor;
210 this->visit(minVisitor);
211 *rowId = minVisitor.row;
212 if (colId) *colId = minVisitor.col;
213 return minVisitor.res;
221 template<
typename Derived>
222 template<
typename IndexType>
224 typename internal::traits<Derived>::Scalar
227 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
228 internal::min_coeff_visitor<Derived> minVisitor;
229 this->visit(minVisitor);
230 *index = IndexType((RowsAtCompileTime==1) ? minVisitor.col : minVisitor.row);
231 return minVisitor.res;
240 template<
typename Derived>
241 template<
typename IndexType>
243 typename internal::traits<Derived>::Scalar
246 internal::max_coeff_visitor<Derived> maxVisitor;
247 this->visit(maxVisitor);
248 *rowPtr = maxVisitor.row;
249 if (colPtr) *colPtr = maxVisitor.col;
250 return maxVisitor.res;
258 template<
typename Derived>
259 template<
typename IndexType>
261 typename internal::traits<Derived>::Scalar
264 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
265 internal::max_coeff_visitor<Derived> maxVisitor;
266 this->visit(maxVisitor);
267 *index = (RowsAtCompileTime==1) ? maxVisitor.col : maxVisitor.row;
268 return maxVisitor.res;
273 #endif // EIGEN_VISITOR_H Namespace containing all symbols from the Eigen library.
Definition: Core:287
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:150
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:38
void visit(Visitor &func) const
Definition: Visitor.h:107
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Definition: Eigen_Colamd.h:50
internal::traits< Derived >::Scalar maxCoeff() const
Definition: Redux.h:436
const int Dynamic
Definition: Constants.h:21
internal::traits< Derived >::Scalar minCoeff() const
Definition: Redux.h:426