CoreIterators.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-2014 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_COREITERATORS_H
11 #define EIGEN_COREITERATORS_H
12 
13 namespace Eigen {
14 
15 /* This file contains the respective InnerIterator definition of the expressions defined in Eigen/Core
16  */
17 
18 namespace internal {
19 
20 template<typename XprType, typename EvaluatorKind>
22 
23 }
24 
32 template<typename XprType>
34 {
35 protected:
39 public:
41  InnerIterator(const XprType &xpr, const Index &outerId)
42  : m_eval(xpr), m_iter(m_eval, outerId, xpr.innerSize())
43  {}
44 
46  EIGEN_STRONG_INLINE Scalar value() const { return m_iter.value(); }
50  EIGEN_STRONG_INLINE InnerIterator& operator++() { m_iter.operator++(); return *this; }
52  EIGEN_STRONG_INLINE Index index() const { return m_iter.index(); }
54  EIGEN_STRONG_INLINE Index row() const { return m_iter.row(); }
56  EIGEN_STRONG_INLINE Index col() const { return m_iter.col(); }
58  EIGEN_STRONG_INLINE operator bool() const { return m_iter; }
59 
60 protected:
61  EvaluatorType m_eval;
62  IteratorType m_iter;
63 private:
64  // If you get here, then you're not using the right InnerIterator type, e.g.:
65  // SparseMatrix<double,RowMajor> A;
66  // SparseMatrix<double>::InnerIterator it(A,0);
67  template<typename T> InnerIterator(const EigenBase<T>&,Index outer);
68 };
69 
70 namespace internal {
71 
72 // Generic inner iterator implementation for dense objects
73 template<typename XprType>
75 {
76 protected:
78  typedef typename traits<XprType>::Scalar Scalar;
79  enum { IsRowMajor = (XprType::Flags&RowMajorBit)==RowMajorBit };
80 
81 public:
82  EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &innerSize)
83  : m_eval(eval), m_inner(0), m_outer(outerId), m_end(innerSize)
84  {}
85 
86  EIGEN_STRONG_INLINE Scalar value() const
87  {
88  return (IsRowMajor) ? m_eval.coeff(m_outer, m_inner)
89  : m_eval.coeff(m_inner, m_outer);
90  }
91 
92  EIGEN_STRONG_INLINE inner_iterator_selector& operator++() { m_inner++; return *this; }
93 
94  EIGEN_STRONG_INLINE Index index() const { return m_inner; }
95  inline Index row() const { return IsRowMajor ? m_outer : index(); }
96  inline Index col() const { return IsRowMajor ? index() : m_outer; }
97 
98  EIGEN_STRONG_INLINE operator bool() const { return m_inner < m_end && m_inner>=0; }
99 
100 protected:
101  const EvaluatorType& m_eval;
103  const Index m_outer;
104  const Index m_end;
105 };
106 
107 // For iterator-based evaluator, inner-iterator is already implemented as
108 // evaluator<>::InnerIterator
109 template<typename XprType>
111  : public evaluator<XprType>::InnerIterator
112 {
113 protected:
116 
117 public:
118  EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &/*innerSize*/)
119  : Base(eval, outerId)
120  {}
121 };
122 
123 } // end namespace internal
124 
125 } // end namespace Eigen
126 
127 #endif // EIGEN_COREITERATORS_H
#define EIGEN_STRONG_INLINE
Definition: Macros.h:493
internal::evaluator< XprType > EvaluatorType
Definition: CoreIterators.h:37
EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &innerSize)
Definition: CoreIterators.h:82
Definition: LDLT.h:16
EIGEN_STRONG_INLINE Index col() const
Definition: CoreIterators.h:56
const unsigned int RowMajorBit
Definition: Constants.h:61
internal::traits< XprType >::Scalar Scalar
Definition: CoreIterators.h:38
EIGEN_STRONG_INLINE Index index() const
Definition: CoreIterators.h:52
InnerIterator(const XprType &xpr, const Index &outerId)
Definition: CoreIterators.h:41
EIGEN_STRONG_INLINE inner_iterator_selector & operator++()
Definition: CoreIterators.h:92
internal::inner_iterator_selector< XprType, typename internal::evaluator_traits< XprType >::Kind > IteratorType
Definition: CoreIterators.h:36
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &)
EIGEN_STRONG_INLINE Index row() const
Definition: CoreIterators.h:54
EIGEN_STRONG_INLINE Scalar value() const
Definition: CoreIterators.h:46
EvaluatorType m_eval
Definition: CoreIterators.h:61
IteratorType m_iter
Definition: CoreIterators.h:62
An InnerIterator allows to loop over the element of any matrix expression.
Definition: CoreIterators.h:33
EIGEN_STRONG_INLINE InnerIterator & operator++()
Definition: CoreIterators.h:50


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:08:08