Flagged.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 Benoit Jacob <jacob.benoit.1@gmail.com>
5 //
6 // Eigen is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // Alternatively, you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of
14 // the License, or (at your option) any later version.
15 //
16 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License and a copy of the GNU General Public License along with
23 // Eigen. If not, see <http://www.gnu.org/licenses/>.
24 
25 #ifndef EIGEN_FLAGGED_H
26 #define EIGEN_FLAGGED_H
27 
28 namespace Eigen {
29 
46 namespace internal {
47 template<typename ExpressionType, unsigned int Added, unsigned int Removed>
48 struct traits<Flagged<ExpressionType, Added, Removed> > : traits<ExpressionType>
49 {
50  enum { Flags = (ExpressionType::Flags | Added) & ~Removed };
51 };
52 }
53 
54 template<typename ExpressionType, unsigned int Added, unsigned int Removed> class Flagged
55  : public MatrixBase<Flagged<ExpressionType, Added, Removed> >
56 {
57  public:
58 
59  typedef MatrixBase<Flagged> Base;
60 
62  typedef typename internal::conditional<internal::must_nest_by_value<ExpressionType>::ret,
63  ExpressionType, const ExpressionType&>::type ExpressionTypeNested;
64  typedef typename ExpressionType::InnerIterator InnerIterator;
65 
66  inline Flagged(const ExpressionType& matrix) : m_matrix(matrix) {}
67 
68  inline Index rows() const { return m_matrix.rows(); }
69  inline Index cols() const { return m_matrix.cols(); }
70  inline Index outerStride() const { return m_matrix.outerStride(); }
71  inline Index innerStride() const { return m_matrix.innerStride(); }
72 
73  inline CoeffReturnType coeff(Index row, Index col) const
74  {
75  return m_matrix.coeff(row, col);
76  }
77 
78  inline CoeffReturnType coeff(Index index) const
79  {
80  return m_matrix.coeff(index);
81  }
82 
83  inline const Scalar& coeffRef(Index row, Index col) const
84  {
85  return m_matrix.const_cast_derived().coeffRef(row, col);
86  }
87 
88  inline const Scalar& coeffRef(Index index) const
89  {
90  return m_matrix.const_cast_derived().coeffRef(index);
91  }
92 
93  inline Scalar& coeffRef(Index row, Index col)
94  {
95  return m_matrix.const_cast_derived().coeffRef(row, col);
96  }
97 
98  inline Scalar& coeffRef(Index index)
99  {
100  return m_matrix.const_cast_derived().coeffRef(index);
101  }
102 
103  template<int LoadMode>
104  inline const PacketScalar packet(Index row, Index col) const
105  {
106  return m_matrix.template packet<LoadMode>(row, col);
107  }
108 
109  template<int LoadMode>
110  inline void writePacket(Index row, Index col, const PacketScalar& x)
111  {
112  m_matrix.const_cast_derived().template writePacket<LoadMode>(row, col, x);
113  }
114 
115  template<int LoadMode>
116  inline const PacketScalar packet(Index index) const
117  {
118  return m_matrix.template packet<LoadMode>(index);
119  }
120 
121  template<int LoadMode>
122  inline void writePacket(Index index, const PacketScalar& x)
123  {
124  m_matrix.const_cast_derived().template writePacket<LoadMode>(index, x);
125  }
126 
127  const ExpressionType& _expression() const { return m_matrix; }
128 
129  template<typename OtherDerived>
130  typename ExpressionType::PlainObject solveTriangular(const MatrixBase<OtherDerived>& other) const;
131 
132  template<typename OtherDerived>
133  void solveTriangularInPlace(const MatrixBase<OtherDerived>& other) const;
134 
135  protected:
136  ExpressionTypeNested m_matrix;
137 };
138 
145 template<typename Derived>
146 template<unsigned int Added,unsigned int Removed>
147 inline const Flagged<Derived, Added, Removed>
149 {
150  return derived();
151 }
152 
153 } // end namespace Eigen
154 
155 #endif // EIGEN_FLAGGED_H