Visitor.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_VISITOR_H
11 #define EIGEN_VISITOR_H
12 
13 namespace Eigen {
14 
15 namespace internal {
16 
17 template<typename Visitor, typename Derived, int UnrollCount>
19 {
20  enum {
21  col = (UnrollCount-1) / Derived::RowsAtCompileTime,
22  row = (UnrollCount-1) % Derived::RowsAtCompileTime
23  };
24 
25  EIGEN_DEVICE_FUNC
26  static inline void run(const Derived &mat, Visitor& visitor)
27  {
29  visitor(mat.coeff(row, col), row, col);
30  }
31 };
32 
33 template<typename Visitor, typename Derived>
34 struct visitor_impl<Visitor, Derived, 1>
35 {
36  EIGEN_DEVICE_FUNC
37  static inline void run(const Derived &mat, Visitor& visitor)
38  {
39  return visitor.init(mat.coeff(0, 0), 0, 0);
40  }
41 };
42 
43 template<typename Visitor, typename Derived>
44 struct visitor_impl<Visitor, Derived, Dynamic>
45 {
46  EIGEN_DEVICE_FUNC
47  static inline void run(const Derived& mat, Visitor& visitor)
48  {
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);
55  }
56 };
57 
58 // evaluator adaptor
59 template<typename XprType>
61 {
62 public:
63  EIGEN_DEVICE_FUNC
64  explicit visitor_evaluator(const XprType &xpr) : m_evaluator(xpr), m_xpr(xpr) {}
65 
66  typedef typename XprType::Scalar Scalar;
67  typedef typename XprType::CoeffReturnType CoeffReturnType;
68 
69  enum {
70  RowsAtCompileTime = XprType::RowsAtCompileTime,
72  };
73 
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(); }
77 
78  EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col) const
79  { return m_evaluator.coeff(row, col); }
80 
81 protected:
83  const XprType &m_xpr;
84 };
85 } // end namespace internal
86 
104 template<typename Derived>
105 template<typename Visitor>
106 EIGEN_DEVICE_FUNC
107 void DenseBase<Derived>::visit(Visitor& visitor) const
108 {
109  typedef typename internal::visitor_evaluator<Derived> ThisEvaluator;
110  ThisEvaluator thisEval(derived());
111 
112  enum {
113  unroll = SizeAtCompileTime != Dynamic
114  && SizeAtCompileTime * ThisEvaluator::CoeffReadCost + (SizeAtCompileTime-1) * internal::functor_traits<Visitor>::Cost <= EIGEN_UNROLLING_LIMIT
115  };
116  return internal::visitor_impl<Visitor, ThisEvaluator, unroll ? int(SizeAtCompileTime) : Dynamic>::run(thisEval, visitor);
117 }
118 
119 namespace internal {
120 
124 template <typename Derived>
126 {
127  typedef typename Derived::Scalar Scalar;
130  EIGEN_DEVICE_FUNC
131  inline void init(const Scalar& value, Index i, Index j)
132  {
133  res = value;
134  row = i;
135  col = j;
136  }
137 };
138 
144 template <typename Derived>
146 {
147  typedef typename Derived::Scalar Scalar;
148  EIGEN_DEVICE_FUNC
149  void operator() (const Scalar& value, Index i, Index j)
150  {
151  if(value < this->res)
152  {
153  this->res = value;
154  this->row = i;
155  this->col = j;
156  }
157  }
158 };
159 
160 template<typename Scalar>
162  enum {
164  };
165 };
166 
172 template <typename Derived>
174 {
175  typedef typename Derived::Scalar Scalar;
176  EIGEN_DEVICE_FUNC
177  void operator() (const Scalar& value, Index i, Index j)
178  {
179  if(value > this->res)
180  {
181  this->res = value;
182  this->row = i;
183  this->col = j;
184  }
185  }
186 };
187 
188 template<typename Scalar>
190  enum {
192  };
193 };
194 
195 } // end namespace internal
196 
203 template<typename Derived>
204 template<typename IndexType>
205 EIGEN_DEVICE_FUNC
207 DenseBase<Derived>::minCoeff(IndexType* rowId, IndexType* colId) const
208 {
210  this->visit(minVisitor);
211  *rowId = minVisitor.row;
212  if (colId) *colId = minVisitor.col;
213  return minVisitor.res;
214 }
215 
221 template<typename Derived>
222 template<typename IndexType>
223 EIGEN_DEVICE_FUNC
225 DenseBase<Derived>::minCoeff(IndexType* index) const
226 {
229  this->visit(minVisitor);
230  *index = IndexType((RowsAtCompileTime==1) ? minVisitor.col : minVisitor.row);
231  return minVisitor.res;
232 }
233 
240 template<typename Derived>
241 template<typename IndexType>
242 EIGEN_DEVICE_FUNC
244 DenseBase<Derived>::maxCoeff(IndexType* rowPtr, IndexType* colPtr) const
245 {
247  this->visit(maxVisitor);
248  *rowPtr = maxVisitor.row;
249  if (colPtr) *colPtr = maxVisitor.col;
250  return maxVisitor.res;
251 }
252 
258 template<typename Derived>
259 template<typename IndexType>
260 EIGEN_DEVICE_FUNC
262 DenseBase<Derived>::maxCoeff(IndexType* index) const
263 {
266  this->visit(maxVisitor);
267  *index = (RowsAtCompileTime==1) ? maxVisitor.col : maxVisitor.row;
268  return maxVisitor.res;
269 }
270 
271 } // end namespace Eigen
272 
273 #endif // EIGEN_VISITOR_H
Eigen
Definition: common.h:73
Eigen::internal::min_coeff_visitor::Scalar
Derived::Scalar Scalar
Definition: Visitor.h:147
EIGEN_UNROLLING_LIMIT
#define EIGEN_UNROLLING_LIMIT
Definition: Settings.h:24
Eigen::internal::coeff_visitor::init
EIGEN_DEVICE_FUNC void init(const Scalar &value, Index i, Index j)
Definition: Visitor.h:131
Eigen::internal::max_coeff_visitor::Scalar
Derived::Scalar Scalar
Definition: Visitor.h:175
Eigen::DenseBase::maxCoeff
EIGEN_DEVICE_FUNC internal::traits< Derived >::Scalar maxCoeff() const
Definition: Redux.h:436
Eigen::internal::visitor_evaluator::size
EIGEN_DEVICE_FUNC Index size() const
Definition: Visitor.h:76
Eigen::internal::min_coeff_visitor
Definition: Visitor.h:145
Eigen::internal::visitor_evaluator::CoeffReturnType
XprType::CoeffReturnType CoeffReturnType
Definition: Visitor.h:67
Eigen::internal::visitor_evaluator
Definition: Visitor.h:60
col
EIGEN_DEVICE_FUNC ColXpr col(Index i)
This is the const version of col().
Definition: BlockMethods.h:838
EIGEN_STATIC_ASSERT_VECTOR_ONLY
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition: StaticAssert.h:139
Scalar
SCALAR Scalar
Definition: common.h:84
Eigen::internal::visitor_evaluator::CoeffReadCost
@ CoeffReadCost
Definition: Visitor.h:71
Eigen::internal::visitor_impl::col
@ col
Definition: Visitor.h:21
Eigen::internal::visitor_impl< Visitor, Derived, Dynamic >::run
static EIGEN_DEVICE_FUNC void run(const Derived &mat, Visitor &visitor)
Definition: Visitor.h:47
Eigen::internal::visitor_evaluator::coeff
EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col) const
Definition: Visitor.h:78
Eigen::internal::visitor_impl::row
@ row
Definition: Visitor.h:22
Eigen::internal::coeff_visitor
Definition: Visitor.h:125
Eigen::internal::coeff_visitor::row
Index row
Definition: Visitor.h:128
Eigen::internal::coeff_visitor::Scalar
Derived::Scalar Scalar
Definition: Visitor.h:127
Eigen::Dynamic
const int Dynamic
Definition: Constants.h:21
Eigen::internal::max_coeff_visitor::operator()
EIGEN_DEVICE_FUNC void operator()(const Scalar &value, Index i, Index j)
Definition: Visitor.h:177
Eigen::internal::visitor_evaluator::rows
EIGEN_DEVICE_FUNC Index rows() const
Definition: Visitor.h:74
Eigen::internal::min_coeff_visitor::operator()
EIGEN_DEVICE_FUNC void operator()(const Scalar &value, Index i, Index j)
Definition: Visitor.h:149
row
EIGEN_DEVICE_FUNC RowXpr row(Index i)
This is the const version of row(). *‍/.
Definition: BlockMethods.h:859
Eigen::internal::visitor_evaluator::visitor_evaluator
EIGEN_DEVICE_FUNC visitor_evaluator(const XprType &xpr)
Definition: Visitor.h:64
Eigen::internal::coeff_visitor::col
Index col
Definition: Visitor.h:128
Eigen::internal::visitor_impl::run
static EIGEN_DEVICE_FUNC void run(const Derived &mat, Visitor &visitor)
Definition: Visitor.h:26
Eigen::internal::coeff_visitor::res
Scalar res
Definition: Visitor.h:129
Eigen::internal::visitor_impl
Definition: Visitor.h:18
Eigen::internal::evaluator
Definition: CoreEvaluators.h:90
Eigen::internal::visitor_evaluator::RowsAtCompileTime
@ RowsAtCompileTime
Definition: Visitor.h:70
int
return int(ret)+1
Eigen::internal::visitor_impl< Visitor, Derived, 1 >::run
static EIGEN_DEVICE_FUNC void run(const Derived &mat, Visitor &visitor)
Definition: Visitor.h:37
Eigen::internal::visitor_evaluator::cols
EIGEN_DEVICE_FUNC Index cols() const
Definition: Visitor.h:75
Eigen::internal::visitor_evaluator::m_evaluator
internal::evaluator< XprType > m_evaluator
Definition: Visitor.h:82
Eigen::DenseBase::visit
EIGEN_DEVICE_FUNC void visit(Visitor &func) const
Definition: Visitor.h:107
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
Eigen::TensorSycl::run
void run(Expr &expr, Dev &dev)
Definition: TensorSyclRun.h:47
Eigen::internal::functor_traits
Definition: XprHelper.h:146
internal
Definition: BandTriangularSolver.h:13
Eigen::internal::max_coeff_visitor
Definition: Visitor.h:173
Eigen::internal::visitor_evaluator::Scalar
XprType::Scalar Scalar
Definition: Visitor.h:66
Eigen::internal::visitor_evaluator::m_xpr
const XprType & m_xpr
Definition: Visitor.h:83
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:150
Eigen::internal::functor_traits::Cost
@ Cost
Definition: XprHelper.h:150
mat
else mat
Definition: eigenvalues.cpp:43
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Eigen::DenseBase::minCoeff
EIGEN_DEVICE_FUNC internal::traits< Derived >::Scalar minCoeff() const
Definition: Redux.h:426


control_box_rst
Author(s): Christoph Rösmann
autogenerated on Wed Mar 2 2022 00:07:15