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 // IWYU pragma: private
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 /* This file contains the respective InnerIterator definition of the expressions defined in Eigen/Core
19  */
20 
21 namespace internal {
22 
23 template <typename XprType, typename EvaluatorKind>
25 
26 }
27 
36 template <typename XprType>
38  protected:
42 
43  public:
45  InnerIterator(const XprType &xpr, const Index &outerId) : m_eval(xpr), m_iter(m_eval, outerId, xpr.innerSize()) {}
46 
48  EIGEN_STRONG_INLINE Scalar value() const { return m_iter.value(); }
53  m_iter.operator++();
54  return *this;
55  }
57  m_iter.operator+=(i);
58  return *this;
59  }
61  InnerIterator result(*this);
62  result += i;
63  return result;
64  }
65 
67  EIGEN_STRONG_INLINE Index index() const { return m_iter.index(); }
69  EIGEN_STRONG_INLINE Index row() const { return m_iter.row(); }
71  EIGEN_STRONG_INLINE Index col() const { return m_iter.col(); }
73  EIGEN_STRONG_INLINE operator bool() const { return m_iter; }
74 
75  protected:
78 
79  private:
80  // If you get here, then you're not using the right InnerIterator type, e.g.:
81  // SparseMatrix<double,RowMajor> A;
82  // SparseMatrix<double>::InnerIterator it(A,0);
83  template <typename T>
84  InnerIterator(const EigenBase<T> &, Index outer);
85 };
86 
87 namespace internal {
88 
89 // Generic inner iterator implementation for dense objects
90 template <typename XprType>
92  protected:
94  typedef typename traits<XprType>::Scalar Scalar;
95  enum { IsRowMajor = (XprType::Flags & RowMajorBit) == RowMajorBit };
96 
97  public:
98  EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &innerSize)
99  : m_eval(eval), m_inner(0), m_outer(outerId), m_end(innerSize) {}
100 
102  return (IsRowMajor) ? m_eval.coeff(m_outer, m_inner) : m_eval.coeff(m_inner, m_outer);
103  }
104 
106  m_inner++;
107  return *this;
108  }
109 
110  EIGEN_STRONG_INLINE Index index() const { return m_inner; }
111  inline Index row() const { return IsRowMajor ? m_outer : index(); }
112  inline Index col() const { return IsRowMajor ? index() : m_outer; }
113 
114  EIGEN_STRONG_INLINE operator bool() const { return m_inner < m_end && m_inner >= 0; }
115 
116  protected:
119  const Index m_outer;
120  const Index m_end;
121 };
122 
123 // For iterator-based evaluator, inner-iterator is already implemented as
124 // evaluator<>::InnerIterator
125 template <typename XprType>
127  protected:
130 
131  public:
133  const Index & /*innerSize*/)
134  : Base(eval, outerId) {}
135 };
136 
137 } // end namespace internal
138 
139 } // end namespace Eigen
140 
141 #endif // EIGEN_COREITERATORS_H
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_STRONG_INLINE
Definition: Macros.h:834
An InnerIterator allows to loop over the element of any matrix expression.
Definition: CoreIterators.h:37
EIGEN_STRONG_INLINE Index col() const
Definition: CoreIterators.h:71
internal::evaluator< XprType > EvaluatorType
Definition: CoreIterators.h:40
EIGEN_STRONG_INLINE Index row() const
Definition: CoreIterators.h:69
EvaluatorType m_eval
Definition: CoreIterators.h:76
EIGEN_STRONG_INLINE InnerIterator & operator+=(Index i)
Definition: CoreIterators.h:56
IteratorType m_iter
Definition: CoreIterators.h:77
EIGEN_STRONG_INLINE Scalar value() const
Definition: CoreIterators.h:48
internal::inner_iterator_selector< XprType, typename internal::evaluator_traits< XprType >::Kind > IteratorType
Definition: CoreIterators.h:39
InnerIterator(const XprType &xpr, const Index &outerId)
Definition: CoreIterators.h:45
EIGEN_STRONG_INLINE Index index() const
Definition: CoreIterators.h:67
InnerIterator(const EigenBase< T > &, Index outer)
internal::traits< XprType >::Scalar Scalar
Definition: CoreIterators.h:41
EIGEN_STRONG_INLINE InnerIterator & operator++()
Definition: CoreIterators.h:52
EIGEN_STRONG_INLINE InnerIterator operator+(Index i)
Definition: CoreIterators.h:60
EIGEN_STRONG_INLINE inner_iterator_selector & operator++()
Definition: CoreIterators.h:105
EIGEN_STRONG_INLINE Scalar value() const
Definition: CoreIterators.h:101
EIGEN_STRONG_INLINE Index index() const
Definition: CoreIterators.h:110
traits< XprType >::Scalar Scalar
Definition: CoreIterators.h:94
Index row() const
Definition: CoreIterators.h:111
Index col() const
Definition: CoreIterators.h:112
const Index m_outer
Definition: CoreIterators.h:119
evaluator< XprType > EvaluatorType
Definition: CoreIterators.h:93
const Index m_end
Definition: CoreIterators.h:120
const EvaluatorType & m_eval
Definition: CoreIterators.h:117
EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &innerSize)
Definition: CoreIterators.h:98
EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &)
Definition: CoreIterators.h:132
evaluator< XprType > EvaluatorType
Definition: CoreIterators.h:129
evaluator< XprType >::InnerIterator Base
Definition: CoreIterators.h:128
Definition: CoreIterators.h:24
const unsigned int RowMajorBit
Definition: Constants.h:70
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
Definition: Eigen_Colamd.h:49
CwiseBinaryOp< internal::scalar_sum_op< double, double >, const CpyMatrixXd, const CpyMatrixXd > XprType
Definition: nestbyvalue.cpp:15
Definition: EigenBase.h:33
Definition: Constants.h:577
Definition: Constants.h:580
Definition: XprHelper.h:427
Definition: ForwardDeclarations.h:21