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);
44 template<
typename Visitor,
typename Derived>
45 struct visitor_impl<Visitor, Derived, 0> {
47 static inline void run(
const Derived &, Visitor& )
51 template<
typename Visitor,
typename Derived>
52 struct visitor_impl<Visitor, Derived,
Dynamic>
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>
68 class visitor_evaluator
72 explicit visitor_evaluator(
const XprType &xpr) : m_evaluator(xpr), m_xpr(xpr) {}
74 typedef typename XprType::Scalar Scalar;
75 typedef typename XprType::CoeffReturnType CoeffReturnType;
78 RowsAtCompileTime = XprType::RowsAtCompileTime,
79 CoeffReadCost = internal::evaluator<XprType>::CoeffReadCost
82 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
Index rows() const EIGEN_NOEXCEPT {
return m_xpr.rows(); }
83 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
Index cols() const EIGEN_NOEXCEPT {
return m_xpr.cols(); }
84 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
Index size() const EIGEN_NOEXCEPT {
return m_xpr.size(); }
86 EIGEN_DEVICE_FUNC CoeffReturnType coeff(
Index row,
Index col)
const 87 {
return m_evaluator.coeff(row, col); }
90 internal::evaluator<XprType> m_evaluator;
114 template<
typename Derived>
115 template<
typename Visitor>
122 typedef typename internal::visitor_evaluator<Derived> ThisEvaluator;
123 ThisEvaluator thisEval(derived());
126 unroll = SizeAtCompileTime !=
Dynamic 127 && SizeAtCompileTime * int(ThisEvaluator::CoeffReadCost) + (SizeAtCompileTime-1) *
int(internal::functor_traits<Visitor>::Cost) <= EIGEN_UNROLLING_LIMIT
129 return internal::visitor_impl<Visitor, ThisEvaluator, unroll ? int(SizeAtCompileTime) : Dynamic>::run(thisEval, visitor);
137 template <
typename Derived>
142 coeff_visitor() : row(-1), col(-1), res(0) {}
143 typedef typename Derived::Scalar Scalar;
147 inline void init(
const Scalar& value,
Index i,
Index j)
160 template <
typename Derived,
int NaNPropagation>
161 struct min_coeff_visitor : coeff_visitor<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 Derived>
177 struct min_coeff_visitor<Derived, PropagateNumbers> : coeff_visitor<Derived>
179 typedef typename Derived::Scalar Scalar;
181 void operator() (
const Scalar& value,
Index i,
Index j)
183 if((numext::isnan)(this->res) || (!(numext::isnan)(value) && value < this->res))
192 template <
typename Derived>
193 struct min_coeff_visitor<Derived, PropagateNaN> : coeff_visitor<Derived>
195 typedef typename Derived::Scalar Scalar;
197 void operator() (
const Scalar& value,
Index i,
Index j)
199 if((numext::isnan)(value) || value < this->res)
208 template<
typename Scalar,
int NaNPropagation>
209 struct functor_traits<min_coeff_visitor<Scalar, NaNPropagation> > {
220 template <
typename Derived,
int NaNPropagation>
221 struct max_coeff_visitor : coeff_visitor<Derived>
223 typedef typename Derived::Scalar Scalar;
225 void operator() (
const Scalar& value,
Index i,
Index j)
227 if(value > this->res)
236 template <
typename Derived>
237 struct max_coeff_visitor<Derived, PropagateNumbers> : coeff_visitor<Derived>
239 typedef typename Derived::Scalar Scalar;
241 void operator() (
const Scalar& value,
Index i,
Index j)
243 if((numext::isnan)(this->res) || (!(numext::isnan)(value) && value > this->res))
252 template <
typename Derived>
253 struct max_coeff_visitor<Derived, PropagateNaN> : coeff_visitor<Derived>
255 typedef typename Derived::Scalar Scalar;
257 void operator() (
const Scalar& value,
Index i,
Index j)
259 if((numext::isnan)(value) || value > this->res)
268 template<
typename Scalar,
int NaNPropagation>
269 struct functor_traits<max_coeff_visitor<Scalar, NaNPropagation> > {
288 template<
typename Derived>
289 template<
int NaNPropagation,
typename IndexType>
291 typename internal::traits<Derived>::Scalar
294 eigen_assert(this->rows()>0 && this->cols()>0 &&
"you are using an empty matrix");
296 internal::min_coeff_visitor<Derived, NaNPropagation> minVisitor;
297 this->visit(minVisitor);
298 *rowId = minVisitor.row;
299 if (colId) *colId = minVisitor.col;
300 return minVisitor.res;
313 template<
typename Derived>
314 template<
int NaNPropagation,
typename IndexType>
316 typename internal::traits<Derived>::Scalar
319 eigen_assert(this->rows()>0 && this->cols()>0 &&
"you are using an empty matrix");
321 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
322 internal::min_coeff_visitor<Derived, NaNPropagation> minVisitor;
323 this->visit(minVisitor);
324 *index = IndexType((RowsAtCompileTime==1) ? minVisitor.col : minVisitor.row);
325 return minVisitor.res;
339 template<
typename Derived>
340 template<
int NaNPropagation,
typename IndexType>
342 typename internal::traits<Derived>::Scalar
345 eigen_assert(this->rows()>0 && this->cols()>0 &&
"you are using an empty matrix");
347 internal::max_coeff_visitor<Derived, NaNPropagation> maxVisitor;
348 this->visit(maxVisitor);
349 *rowPtr = maxVisitor.row;
350 if (colPtr) *colPtr = maxVisitor.col;
351 return maxVisitor.res;
364 template<
typename Derived>
365 template<
int NaNPropagation,
typename IndexType>
367 typename internal::traits<Derived>::Scalar
370 eigen_assert(this->rows()>0 && this->cols()>0 &&
"you are using an empty matrix");
372 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
373 internal::max_coeff_visitor<Derived, NaNPropagation> maxVisitor;
374 this->visit(maxVisitor);
375 *index = (RowsAtCompileTime==1) ? maxVisitor.col : maxVisitor.row;
376 return maxVisitor.res;
381 #endif // EIGEN_VISITOR_H Namespace containing all symbols from the Eigen library.
Definition: Core:141
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:232
void visit(Visitor &func) const
Definition: Visitor.h:117
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Definition: Eigen_Colamd.h:50
const int Dynamic
Definition: Constants.h:22
internal::traits< Derived >::Scalar minCoeff() const
Definition: Redux.h:431
internal::traits< Derived >::Scalar maxCoeff() const
Definition: Redux.h:446