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)
29 visitor(mat.coeff(row, col), row, col);
33 template<
typename Visitor,
typename Derived>
37 static inline void run(
const Derived &mat, Visitor& visitor)
39 return visitor.init(mat.coeff(0, 0), 0, 0);
44 template<
typename Visitor,
typename Derived>
47 static inline void run(
const Derived &, Visitor& )
51 template<
typename Visitor,
typename Derived>
55 static inline void run(
const Derived& mat, Visitor& visitor)
57 visitor.init(mat.coeff(0,0), 0, 0);
58 for(
Index i = 1; i < mat.rows(); ++i)
59 visitor(mat.coeff(i, 0), i, 0);
60 for(
Index j = 1; j < mat.cols(); ++j)
61 for(
Index i = 0; i < mat.rows(); ++i)
62 visitor(mat.coeff(i, j), i, j);
67 template<
typename XprType>
74 typedef typename XprType::Scalar Scalar;
75 typedef typename XprType::CoeffReturnType CoeffReturnType;
78 RowsAtCompileTime = XprType::RowsAtCompileTime,
82 EIGEN_DEVICE_FUNC
Index rows()
const {
return m_xpr.rows(); }
83 EIGEN_DEVICE_FUNC
Index cols()
const {
return m_xpr.cols(); }
84 EIGEN_DEVICE_FUNC
Index size()
const {
return m_xpr.size(); }
86 EIGEN_DEVICE_FUNC CoeffReturnType coeff(
Index row,
Index col)
const
87 {
return m_evaluator.coeff(row, col); }
114 template<
typename Derived>
115 template<
typename Visitor>
123 ThisEvaluator thisEval(derived());
126 unroll = SizeAtCompileTime !=
Dynamic
137 template <
typename Derived>
143 typedef typename Derived::Scalar Scalar;
147 inline void init(
const Scalar& value,
Index i,
Index j)
160 template <
typename Derived>
163 typedef typename Derived::Scalar Scalar;
165 void operator() (
const Scalar& value,
Index i,
Index j)
167 if(value < this->res)
176 template<
typename Scalar>
188 template <
typename Derived>
191 typedef typename Derived::Scalar Scalar;
193 void operator() (
const Scalar& value,
Index i,
Index j)
195 if(value > this->res)
204 template<
typename Scalar>
222 template<
typename Derived>
223 template<
typename IndexType>
228 eigen_assert(this->rows()>0 && this->cols()>0 &&
"you are using an empty matrix");
231 this->visit(minVisitor);
232 *rowId = minVisitor.row;
233 if (colId) *colId = minVisitor.col;
234 return minVisitor.res;
245 template<
typename Derived>
246 template<
typename IndexType>
251 eigen_assert(this->rows()>0 && this->cols()>0 &&
"you are using an empty matrix");
253 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
255 this->visit(minVisitor);
256 *index = IndexType((RowsAtCompileTime==1) ? minVisitor.col : minVisitor.row);
257 return minVisitor.res;
269 template<
typename Derived>
270 template<
typename IndexType>
275 eigen_assert(this->rows()>0 && this->cols()>0 &&
"you are using an empty matrix");
278 this->visit(maxVisitor);
279 *rowPtr = maxVisitor.row;
280 if (colPtr) *colPtr = maxVisitor.col;
281 return maxVisitor.res;
292 template<
typename Derived>
293 template<
typename IndexType>
298 eigen_assert(this->rows()>0 && this->cols()>0 &&
"you are using an empty matrix");
300 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
302 this->visit(maxVisitor);
303 *index = (RowsAtCompileTime==1) ? maxVisitor.col : maxVisitor.row;
304 return maxVisitor.res;
309 #endif // EIGEN_VISITOR_H