WPILibC++ 2023.4.3-108-ge5452e3
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
13namespace Eigen {
14
15/* This file contains the respective InnerIterator definition of the expressions defined in Eigen/Core
16 */
17
18namespace internal {
19
20template<typename XprType, typename EvaluatorKind>
22
23}
24
25/** \class InnerIterator
26 * \brief An InnerIterator allows to loop over the element of any matrix expression.
27 *
28 * \warning To be used with care because an evaluator is constructed every time an InnerIterator iterator is constructed.
29 *
30 * TODO: add a usage example
31 */
32template<typename XprType>
34{
35protected:
39public:
40 /** Construct an iterator over the \a outerId -th row or column of \a xpr */
41 InnerIterator(const XprType &xpr, const Index &outerId)
42 : m_eval(xpr), m_iter(m_eval, outerId, xpr.innerSize())
43 {}
44
45 /// \returns the value of the current coefficient.
46 EIGEN_STRONG_INLINE Scalar value() const { return m_iter.value(); }
47 /** Increment the iterator \c *this to the next non-zero coefficient.
48 * Explicit zeros are not skipped over. To skip explicit zeros, see class SparseView
49 */
50 EIGEN_STRONG_INLINE InnerIterator& operator++() { m_iter.operator++(); return *this; }
51 EIGEN_STRONG_INLINE InnerIterator& operator+=(Index i) { m_iter.operator+=(i); return *this; }
53 { InnerIterator result(*this); result+=i; return result; }
54
55
56 /// \returns the column or row index of the current coefficient.
57 EIGEN_STRONG_INLINE Index index() const { return m_iter.index(); }
58 /// \returns the row index of the current coefficient.
59 EIGEN_STRONG_INLINE Index row() const { return m_iter.row(); }
60 /// \returns the column index of the current coefficient.
61 EIGEN_STRONG_INLINE Index col() const { return m_iter.col(); }
62 /// \returns \c true if the iterator \c *this still references a valid coefficient.
63 EIGEN_STRONG_INLINE operator bool() const { return m_iter; }
64
65protected:
68private:
69 // If you get here, then you're not using the right InnerIterator type, e.g.:
70 // SparseMatrix<double,RowMajor> A;
71 // SparseMatrix<double>::InnerIterator it(A,0);
72 template<typename T> InnerIterator(const EigenBase<T>&,Index outer);
73};
74
75namespace internal {
76
77// Generic inner iterator implementation for dense objects
78template<typename XprType>
80{
81protected:
84 enum { IsRowMajor = (XprType::Flags&RowMajorBit)==RowMajorBit };
85
86public:
87 EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &innerSize)
88 : m_eval(eval), m_inner(0), m_outer(outerId), m_end(innerSize)
89 {}
90
92 {
93 return (IsRowMajor) ? m_eval.coeff(m_outer, m_inner)
94 : m_eval.coeff(m_inner, m_outer);
95 }
96
98
99 EIGEN_STRONG_INLINE Index index() const { return m_inner; }
100 inline Index row() const { return IsRowMajor ? m_outer : index(); }
101 inline Index col() const { return IsRowMajor ? index() : m_outer; }
102
103 EIGEN_STRONG_INLINE operator bool() const { return m_inner < m_end && m_inner>=0; }
104
105protected:
110};
111
112// For iterator-based evaluator, inner-iterator is already implemented as
113// evaluator<>::InnerIterator
114template<typename XprType>
116 : public evaluator<XprType>::InnerIterator
117{
118protected:
121
122public:
123 EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &/*innerSize*/)
124 : Base(eval, outerId)
125 {}
126};
127
128} // end namespace internal
129
130} // end namespace Eigen
131
132#endif // EIGEN_COREITERATORS_H
#define EIGEN_STRONG_INLINE
Definition: Macros.h:927
An InnerIterator allows to loop over the element of any matrix expression.
Definition: CoreIterators.h:34
EIGEN_STRONG_INLINE Index col() const
Definition: CoreIterators.h:61
internal::evaluator< XprType > EvaluatorType
Definition: CoreIterators.h:37
EIGEN_STRONG_INLINE Index row() const
Definition: CoreIterators.h:59
EvaluatorType m_eval
Definition: CoreIterators.h:66
IteratorType m_iter
Definition: CoreIterators.h:67
EIGEN_STRONG_INLINE Scalar value() const
Definition: CoreIterators.h:46
internal::inner_iterator_selector< XprType, typename internal::evaluator_traits< XprType >::Kind > IteratorType
Definition: CoreIterators.h:36
InnerIterator(const XprType &xpr, const Index &outerId)
Construct an iterator over the outerId -th row or column of xpr.
Definition: CoreIterators.h:41
EIGEN_STRONG_INLINE Index index() const
Definition: CoreIterators.h:57
EIGEN_STRONG_INLINE InnerIterator & operator++()
Increment the iterator *this to the next non-zero coefficient.
Definition: CoreIterators.h:50
internal::traits< XprType >::Scalar Scalar
Definition: CoreIterators.h:38
EIGEN_STRONG_INLINE InnerIterator operator+(Index i)
Definition: CoreIterators.h:52
EIGEN_STRONG_INLINE InnerIterator & operator+=(Index i)
Definition: CoreIterators.h:51
EIGEN_STRONG_INLINE inner_iterator_selector & operator++()
Definition: CoreIterators.h:97
EIGEN_STRONG_INLINE Scalar value() const
Definition: CoreIterators.h:91
EIGEN_STRONG_INLINE Index index() const
Definition: CoreIterators.h:99
traits< XprType >::Scalar Scalar
Definition: CoreIterators.h:83
Index row() const
Definition: CoreIterators.h:100
Index col() const
Definition: CoreIterators.h:101
const Index m_outer
Definition: CoreIterators.h:108
evaluator< XprType > EvaluatorType
Definition: CoreIterators.h:82
const Index m_end
Definition: CoreIterators.h:109
const EvaluatorType & m_eval
Definition: CoreIterators.h:106
EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &innerSize)
Definition: CoreIterators.h:87
EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &)
Definition: CoreIterators.h:123
evaluator< XprType > EvaluatorType
Definition: CoreIterators.h:120
evaluator< XprType >::InnerIterator Base
Definition: CoreIterators.h:119
Definition: CoreIterators.h:21
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition: Constants.h:66
Namespace containing all symbols from the Eigen library.
Definition: Core:141
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
result
Definition: format.h:2564
Definition: Eigen_Colamd.h:50
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition: EigenBase.h:30
Definition: Constants.h:542
Definition: Constants.h:545
Definition: XprHelper.h:332
Definition: ForwardDeclarations.h:17