Diagonal.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) 2007-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
5 // Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_DIAGONAL_H
12 #define EIGEN_DIAGONAL_H
13 
14 namespace Eigen {
15 
35 namespace internal {
36 template<typename MatrixType, int DiagIndex>
37 struct traits<Diagonal<MatrixType,DiagIndex> >
38  : traits<MatrixType>
39 {
42  typedef typename MatrixType::StorageKind StorageKind;
43  enum {
44  RowsAtCompileTime = (int(DiagIndex) == DynamicIndex || int(MatrixType::SizeAtCompileTime) == Dynamic) ? Dynamic
45  : (EIGEN_PLAIN_ENUM_MIN(MatrixType::RowsAtCompileTime - EIGEN_PLAIN_ENUM_MAX(-DiagIndex, 0),
46  MatrixType::ColsAtCompileTime - EIGEN_PLAIN_ENUM_MAX( DiagIndex, 0))),
47  ColsAtCompileTime = 1,
48  MaxRowsAtCompileTime = int(MatrixType::MaxSizeAtCompileTime) == Dynamic ? Dynamic
49  : DiagIndex == DynamicIndex ? EIGEN_SIZE_MIN_PREFER_FIXED(MatrixType::MaxRowsAtCompileTime,
50  MatrixType::MaxColsAtCompileTime)
51  : (EIGEN_PLAIN_ENUM_MIN(MatrixType::MaxRowsAtCompileTime - EIGEN_PLAIN_ENUM_MAX(-DiagIndex, 0),
52  MatrixType::MaxColsAtCompileTime - EIGEN_PLAIN_ENUM_MAX( DiagIndex, 0))),
53  MaxColsAtCompileTime = 1,
54  MaskLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0,
55  Flags = (unsigned int)_MatrixTypeNested::Flags & (HereditaryBits | LinearAccessBit | MaskLvalueBit | DirectAccessBit) & ~RowMajorBit,
56  CoeffReadCost = _MatrixTypeNested::CoeffReadCost,
57  MatrixTypeOuterStride = outer_stride_at_compile_time<MatrixType>::ret,
58  InnerStrideAtCompileTime = MatrixTypeOuterStride == Dynamic ? Dynamic : MatrixTypeOuterStride+1,
59  OuterStrideAtCompileTime = 0
60  };
61 };
62 }
63 
64 template<typename MatrixType, int _DiagIndex> class Diagonal
65  : public internal::dense_xpr_base< Diagonal<MatrixType,_DiagIndex> >::type
66 {
67  public:
68 
69  enum { DiagIndex = _DiagIndex };
72 
73  inline Diagonal(MatrixType& matrix, Index a_index = DiagIndex) : m_matrix(matrix), m_index(a_index) {}
74 
76 
77  inline Index rows() const
78  { return m_index.value()<0 ? (std::min<Index>)(m_matrix.cols(),m_matrix.rows()+m_index.value()) : (std::min<Index>)(m_matrix.rows(),m_matrix.cols()-m_index.value()); }
79 
80  inline Index cols() const { return 1; }
81 
82  inline Index innerStride() const
83  {
84  return m_matrix.outerStride() + 1;
85  }
86 
87  inline Index outerStride() const
88  {
89  return 0;
90  }
91 
92  typedef typename internal::conditional<
94  Scalar,
95  const Scalar
97 
98  inline ScalarWithConstIfNotLvalue* data() { return &(m_matrix.const_cast_derived().coeffRef(rowOffset(), colOffset())); }
99  inline const Scalar* data() const { return &(m_matrix.const_cast_derived().coeffRef(rowOffset(), colOffset())); }
100 
101  inline Scalar& coeffRef(Index row, Index)
102  {
103  EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
104  return m_matrix.const_cast_derived().coeffRef(row+rowOffset(), row+colOffset());
105  }
106 
107  inline const Scalar& coeffRef(Index row, Index) const
108  {
109  return m_matrix.const_cast_derived().coeffRef(row+rowOffset(), row+colOffset());
110  }
111 
112  inline CoeffReturnType coeff(Index row, Index) const
113  {
114  return m_matrix.coeff(row+rowOffset(), row+colOffset());
115  }
116 
117  inline Scalar& coeffRef(Index idx)
118  {
119  EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
120  return m_matrix.const_cast_derived().coeffRef(idx+rowOffset(), idx+colOffset());
121  }
122 
123  inline const Scalar& coeffRef(Index idx) const
124  {
125  return m_matrix.const_cast_derived().coeffRef(idx+rowOffset(), idx+colOffset());
126  }
127 
128  inline CoeffReturnType coeff(Index idx) const
129  {
130  return m_matrix.coeff(idx+rowOffset(), idx+colOffset());
131  }
132 
135  {
136  return m_matrix;
137  }
138 
139  int index() const
140  {
141  return m_index.value();
142  }
143 
144  protected:
145  typename MatrixType::Nested m_matrix;
147 
148  private:
149  // some compilers may fail to optimize std::max etc in case of compile-time constants...
150  EIGEN_STRONG_INLINE Index absDiagIndex() const { return m_index.value()>0 ? m_index.value() : -m_index.value(); }
151  EIGEN_STRONG_INLINE Index rowOffset() const { return m_index.value()>0 ? 0 : -m_index.value(); }
152  EIGEN_STRONG_INLINE Index colOffset() const { return m_index.value()>0 ? m_index.value() : 0; }
153  // triger a compile time error is someone try to call packet
154  template<int LoadMode> typename MatrixType::PacketReturnType packet(Index) const;
155  template<int LoadMode> typename MatrixType::PacketReturnType packet(Index,Index) const;
156 };
157 
166 template<typename Derived>
169 {
170  return derived();
171 }
172 
174 template<typename Derived>
177 {
178  return ConstDiagonalReturnType(derived());
179 }
180 
192 template<typename Derived>
195 {
196  return typename DiagonalIndexReturnType<DynamicIndex>::Type(derived(), index);
197 }
198 
200 template<typename Derived>
203 {
204  return typename ConstDiagonalIndexReturnType<DynamicIndex>::Type(derived(), index);
205 }
206 
218 template<typename Derived>
219 template<int Index>
222 {
223  return derived();
224 }
225 
227 template<typename Derived>
228 template<int Index>
231 {
232  return derived();
233 }
234 
235 } // end namespace Eigen
236 
237 #endif // EIGEN_DIAGONAL_H
MatrixType::Nested m_matrix
Definition: Diagonal.h:145
#define EIGEN_STRONG_INLINE
CoeffReturnType coeff(Index idx) const
Definition: Diagonal.h:128
EIGEN_STRONG_INLINE Index absDiagIndex() const
Definition: Diagonal.h:150
Index innerStride() const
Definition: Diagonal.h:82
#define inline
Definition: Types.h:109
internal::traits< Derived >::Index Index
The type of indices.
Definition: DenseBase.h:61
Expression of the transpose of a matrix.
Definition: Transpose.h:57
const unsigned int DirectAccessBit
DiagonalReturnType diagonal()
Definition: Diagonal.h:168
const unsigned int LvalueBit
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471
Scalar & coeffRef(Index idx)
Definition: Diagonal.h:117
#define EIGEN_PLAIN_ENUM_MIN(a, b)
internal::conditional< internal::is_lvalue< MatrixType >::value, Scalar, const Scalar >::type ScalarWithConstIfNotLvalue
Definition: Diagonal.h:96
#define EIGEN_SIZE_MIN_PREFER_FIXED(a, b)
const unsigned int RowMajorBit
CoeffReturnType coeff(Index row, Index) const
Definition: Diagonal.h:112
#define EIGEN_STATIC_ASSERT_LVALUE(Derived)
Definition: StaticAssert.h:191
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)
const Scalar * data() const
Definition: Diagonal.h:99
const unsigned int HereditaryBits
Index cols() const
Definition: Diagonal.h:80
int index() const
Definition: Diagonal.h:139
remove_reference< MatrixTypeNested >::type _MatrixTypeNested
Definition: Diagonal.h:41
internal::dense_xpr_base< Diagonal >::type Base
Definition: Diagonal.h:70
Scalar & coeffRef(Index row, Index)
Definition: Diagonal.h:101
Index outerStride() const
Definition: Diagonal.h:87
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
RowXpr row(Index i)
Definition: BlockMethods.h:725
const Scalar & coeffRef(Index idx) const
Definition: Diagonal.h:123
const internal::variable_if_dynamicindex< Index, DiagIndex > m_index
Definition: Diagonal.h:146
EIGEN_STRONG_INLINE Index colOffset() const
Definition: Diagonal.h:152
ScalarWithConstIfNotLvalue * data()
Definition: Diagonal.h:98
Expression of a diagonal/subdiagonal/superdiagonal in a matrix.
Definition: Diagonal.h:64
const Scalar & coeffRef(Index row, Index) const
Definition: Diagonal.h:107
const internal::remove_all< typename MatrixType::Nested >::type & nestedExpression() const
Definition: Diagonal.h:134
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
const unsigned int LinearAccessBit
#define EIGEN_PLAIN_ENUM_MAX(a, b)
EIGEN_STRONG_INLINE Index rowOffset() const
Definition: Diagonal.h:151


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:32