File indexing completed on 2025-04-19 09:06:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef EIGEN_COREITERATORS_H
0011 #define EIGEN_COREITERATORS_H
0012
0013 namespace RivetEigen {
0014
0015
0016
0017
0018 namespace internal {
0019
0020 template<typename XprType, typename EvaluatorKind>
0021 class inner_iterator_selector;
0022
0023 }
0024
0025
0026
0027
0028
0029
0030
0031
0032 template<typename XprType>
0033 class InnerIterator
0034 {
0035 protected:
0036 typedef internal::inner_iterator_selector<XprType, typename internal::evaluator_traits<XprType>::Kind> IteratorType;
0037 typedef internal::evaluator<XprType> EvaluatorType;
0038 typedef typename internal::traits<XprType>::Scalar Scalar;
0039 public:
0040
0041 InnerIterator(const XprType &xpr, const Index &outerId)
0042 : m_eval(xpr), m_iter(m_eval, outerId, xpr.innerSize())
0043 {}
0044
0045
0046 EIGEN_STRONG_INLINE Scalar value() const { return m_iter.value(); }
0047
0048
0049
0050 EIGEN_STRONG_INLINE InnerIterator& operator++() { m_iter.operator++(); return *this; }
0051 EIGEN_STRONG_INLINE InnerIterator& operator+=(Index i) { m_iter.operator+=(i); return *this; }
0052 EIGEN_STRONG_INLINE InnerIterator operator+(Index i)
0053 { InnerIterator result(*this); result+=i; return result; }
0054
0055
0056
0057 EIGEN_STRONG_INLINE Index index() const { return m_iter.index(); }
0058
0059 EIGEN_STRONG_INLINE Index row() const { return m_iter.row(); }
0060
0061 EIGEN_STRONG_INLINE Index col() const { return m_iter.col(); }
0062
0063 EIGEN_STRONG_INLINE operator bool() const { return m_iter; }
0064
0065 protected:
0066 EvaluatorType m_eval;
0067 IteratorType m_iter;
0068 private:
0069
0070
0071
0072 template<typename T> InnerIterator(const EigenBase<T>&,Index outer);
0073 };
0074
0075 namespace internal {
0076
0077
0078 template<typename XprType>
0079 class inner_iterator_selector<XprType, IndexBased>
0080 {
0081 protected:
0082 typedef evaluator<XprType> EvaluatorType;
0083 typedef typename traits<XprType>::Scalar Scalar;
0084 enum { IsRowMajor = (XprType::Flags&RowMajorBit)==RowMajorBit };
0085
0086 public:
0087 EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &innerSize)
0088 : m_eval(eval), m_inner(0), m_outer(outerId), m_end(innerSize)
0089 {}
0090
0091 EIGEN_STRONG_INLINE Scalar value() const
0092 {
0093 return (IsRowMajor) ? m_eval.coeff(m_outer, m_inner)
0094 : m_eval.coeff(m_inner, m_outer);
0095 }
0096
0097 EIGEN_STRONG_INLINE inner_iterator_selector& operator++() { m_inner++; return *this; }
0098
0099 EIGEN_STRONG_INLINE Index index() const { return m_inner; }
0100 inline Index row() const { return IsRowMajor ? m_outer : index(); }
0101 inline Index col() const { return IsRowMajor ? index() : m_outer; }
0102
0103 EIGEN_STRONG_INLINE operator bool() const { return m_inner < m_end && m_inner>=0; }
0104
0105 protected:
0106 const EvaluatorType& m_eval;
0107 Index m_inner;
0108 const Index m_outer;
0109 const Index m_end;
0110 };
0111
0112
0113
0114 template<typename XprType>
0115 class inner_iterator_selector<XprType, IteratorBased>
0116 : public evaluator<XprType>::InnerIterator
0117 {
0118 protected:
0119 typedef typename evaluator<XprType>::InnerIterator Base;
0120 typedef evaluator<XprType> EvaluatorType;
0121
0122 public:
0123 EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &)
0124 : Base(eval, outerId)
0125 {}
0126 };
0127
0128 }
0129
0130 }
0131
0132 #endif