[136] | 1 | // This file is part of Eigen, a lightweight C++ template library
|
---|
| 2 | // for linear algebra.
|
---|
| 3 | //
|
---|
| 4 | // Copyright (C) 2008-2010 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 | /** \ingroup SparseCore_Module
|
---|
| 19 | * \class InnerIterator
|
---|
| 20 | * \brief An InnerIterator allows to loop over the element of a sparse (or dense) matrix or expression
|
---|
| 21 | *
|
---|
| 22 | * todo
|
---|
| 23 | */
|
---|
| 24 |
|
---|
| 25 | // generic version for dense matrix and expressions
|
---|
| 26 | template<typename Derived> class DenseBase<Derived>::InnerIterator
|
---|
| 27 | {
|
---|
| 28 | protected:
|
---|
| 29 | typedef typename Derived::Scalar Scalar;
|
---|
| 30 | typedef typename Derived::Index Index;
|
---|
| 31 |
|
---|
| 32 | enum { IsRowMajor = (Derived::Flags&RowMajorBit)==RowMajorBit };
|
---|
| 33 | public:
|
---|
| 34 | EIGEN_STRONG_INLINE InnerIterator(const Derived& expr, Index outer)
|
---|
| 35 | : m_expression(expr), m_inner(0), m_outer(outer), m_end(expr.innerSize())
|
---|
| 36 | {}
|
---|
| 37 |
|
---|
| 38 | EIGEN_STRONG_INLINE Scalar value() const
|
---|
| 39 | {
|
---|
| 40 | return (IsRowMajor) ? m_expression.coeff(m_outer, m_inner)
|
---|
| 41 | : m_expression.coeff(m_inner, m_outer);
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | EIGEN_STRONG_INLINE InnerIterator& operator++() { m_inner++; return *this; }
|
---|
| 45 |
|
---|
| 46 | EIGEN_STRONG_INLINE Index index() const { return m_inner; }
|
---|
| 47 | inline Index row() const { return IsRowMajor ? m_outer : index(); }
|
---|
| 48 | inline Index col() const { return IsRowMajor ? index() : m_outer; }
|
---|
| 49 |
|
---|
| 50 | EIGEN_STRONG_INLINE operator bool() const { return m_inner < m_end && m_inner>=0; }
|
---|
| 51 |
|
---|
| 52 | protected:
|
---|
| 53 | const Derived& m_expression;
|
---|
| 54 | Index m_inner;
|
---|
| 55 | const Index m_outer;
|
---|
| 56 | const Index m_end;
|
---|
| 57 | };
|
---|
| 58 |
|
---|
| 59 | } // end namespace Eigen
|
---|
| 60 |
|
---|
| 61 | #endif // EIGEN_COREITERATORS_H
|
---|