SelfAdjointView.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) 2009 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_SELFADJOINTMATRIX_H
11 #define EIGEN_SELFADJOINTMATRIX_H
12 
13 namespace Eigen {
14 
31 namespace internal {
32 template<typename MatrixType, unsigned int UpLo>
33 struct traits<SelfAdjointView<MatrixType, UpLo> > : traits<MatrixType>
34 {
37  typedef MatrixType ExpressionType;
38  typedef typename MatrixType::PlainObject DenseMatrixType;
39  enum {
40  Mode = UpLo | SelfAdjoint,
41  Flags = MatrixTypeNestedCleaned::Flags & (HereditaryBits)
42  & (~(PacketAccessBit | DirectAccessBit | LinearAccessBit)), // FIXME these flags should be preserved
43  CoeffReadCost = MatrixTypeNestedCleaned::CoeffReadCost
44  };
45 };
46 }
47 
48 template <typename Lhs, int LhsMode, bool LhsIsVector,
49  typename Rhs, int RhsMode, bool RhsIsVector>
51 
52 // FIXME could also be called SelfAdjointWrapper to be consistent with DiagonalWrapper ??
53 template<typename MatrixType, unsigned int UpLo> class SelfAdjointView
54  : public TriangularBase<SelfAdjointView<MatrixType, UpLo> >
55 {
56  public:
57 
61 
64 
65  typedef typename MatrixType::Index Index;
66 
67  enum {
69  };
70  typedef typename MatrixType::PlainObject PlainObject;
71 
72  inline SelfAdjointView(MatrixType& matrix) : m_matrix(matrix)
73  {}
74 
75  inline Index rows() const { return m_matrix.rows(); }
76  inline Index cols() const { return m_matrix.cols(); }
77  inline Index outerStride() const { return m_matrix.outerStride(); }
78  inline Index innerStride() const { return m_matrix.innerStride(); }
79 
83  inline Scalar coeff(Index row, Index col) const
84  {
85  Base::check_coordinates_internal(row, col);
86  return m_matrix.coeff(row, col);
87  }
88 
92  inline Scalar& coeffRef(Index row, Index col)
93  {
94  Base::check_coordinates_internal(row, col);
95  return m_matrix.const_cast_derived().coeffRef(row, col);
96  }
97 
99  const MatrixTypeNestedCleaned& _expression() const { return m_matrix; }
100 
101  const MatrixTypeNestedCleaned& nestedExpression() const { return m_matrix; }
102  MatrixTypeNestedCleaned& nestedExpression() { return *const_cast<MatrixTypeNestedCleaned*>(&m_matrix); }
103 
105  template<typename OtherDerived>
108  {
110  <MatrixType,Mode,false,OtherDerived,0,OtherDerived::IsVectorAtCompileTime>
111  (m_matrix, rhs.derived());
112  }
113 
115  template<typename OtherDerived> friend
118  {
120  <OtherDerived,0,OtherDerived::IsVectorAtCompileTime,MatrixType,Mode,false>
121  (lhs.derived(),rhs.m_matrix);
122  }
123 
134  template<typename DerivedU, typename DerivedV>
135  SelfAdjointView& rankUpdate(const MatrixBase<DerivedU>& u, const MatrixBase<DerivedV>& v, const Scalar& alpha = Scalar(1));
136 
147  template<typename DerivedU>
148  SelfAdjointView& rankUpdate(const MatrixBase<DerivedU>& u, const Scalar& alpha = Scalar(1));
149 
151 
152  const LLT<PlainObject, UpLo> llt() const;
153  const LDLT<PlainObject, UpLo> ldlt() const;
154 
156 
161 
162  EigenvaluesReturnType eigenvalues() const;
163  RealScalar operatorNorm() const;
164 
165  #ifdef EIGEN2_SUPPORT
166  template<typename OtherDerived>
167  SelfAdjointView& operator=(const MatrixBase<OtherDerived>& other)
168  {
169  enum {
170  OtherPart = UpLo == Upper ? StrictlyLower : StrictlyUpper
171  };
172  m_matrix.const_cast_derived().template triangularView<UpLo>() = other;
173  m_matrix.const_cast_derived().template triangularView<OtherPart>() = other.adjoint();
174  return *this;
175  }
176  template<typename OtherMatrixType, unsigned int OtherMode>
178  {
179  enum {
180  OtherPart = UpLo == Upper ? StrictlyLower : StrictlyUpper
181  };
182  m_matrix.const_cast_derived().template triangularView<UpLo>() = other.toDenseMatrix();
183  m_matrix.const_cast_derived().template triangularView<OtherPart>() = other.toDenseMatrix().adjoint();
184  return *this;
185  }
186  #endif
187 
188  protected:
189  MatrixTypeNested m_matrix;
190 };
191 
192 
193 // template<typename OtherDerived, typename MatrixType, unsigned int UpLo>
194 // internal::selfadjoint_matrix_product_returntype<OtherDerived,SelfAdjointView<MatrixType,UpLo> >
195 // operator*(const MatrixBase<OtherDerived>& lhs, const SelfAdjointView<MatrixType,UpLo>& rhs)
196 // {
197 // return internal::matrix_selfadjoint_product_returntype<OtherDerived,SelfAdjointView<MatrixType,UpLo> >(lhs.derived(),rhs);
198 // }
199 
200 // selfadjoint to dense matrix
201 
202 namespace internal {
203 
204 template<typename Derived1, typename Derived2, int UnrollCount, bool ClearOpposite>
205 struct triangular_assignment_selector<Derived1, Derived2, (SelfAdjoint|Upper), UnrollCount, ClearOpposite>
206 {
207  enum {
208  col = (UnrollCount-1) / Derived1::RowsAtCompileTime,
209  row = (UnrollCount-1) % Derived1::RowsAtCompileTime
210  };
211 
212  static inline void run(Derived1 &dst, const Derived2 &src)
213  {
214  triangular_assignment_selector<Derived1, Derived2, (SelfAdjoint|Upper), UnrollCount-1, ClearOpposite>::run(dst, src);
215 
216  if(row == col)
217  dst.coeffRef(row, col) = numext::real(src.coeff(row, col));
218  else if(row < col)
219  dst.coeffRef(col, row) = numext::conj(dst.coeffRef(row, col) = src.coeff(row, col));
220  }
221 };
222 
223 template<typename Derived1, typename Derived2, bool ClearOpposite>
224 struct triangular_assignment_selector<Derived1, Derived2, SelfAdjoint|Upper, 0, ClearOpposite>
225 {
226  static inline void run(Derived1 &, const Derived2 &) {}
227 };
228 
229 template<typename Derived1, typename Derived2, int UnrollCount, bool ClearOpposite>
230 struct triangular_assignment_selector<Derived1, Derived2, (SelfAdjoint|Lower), UnrollCount, ClearOpposite>
231 {
232  enum {
233  col = (UnrollCount-1) / Derived1::RowsAtCompileTime,
234  row = (UnrollCount-1) % Derived1::RowsAtCompileTime
235  };
236 
237  static inline void run(Derived1 &dst, const Derived2 &src)
238  {
239  triangular_assignment_selector<Derived1, Derived2, (SelfAdjoint|Lower), UnrollCount-1, ClearOpposite>::run(dst, src);
240 
241  if(row == col)
242  dst.coeffRef(row, col) = numext::real(src.coeff(row, col));
243  else if(row > col)
244  dst.coeffRef(col, row) = numext::conj(dst.coeffRef(row, col) = src.coeff(row, col));
245  }
246 };
247 
248 template<typename Derived1, typename Derived2, bool ClearOpposite>
249 struct triangular_assignment_selector<Derived1, Derived2, SelfAdjoint|Lower, 0, ClearOpposite>
250 {
251  static inline void run(Derived1 &, const Derived2 &) {}
252 };
253 
254 template<typename Derived1, typename Derived2, bool ClearOpposite>
255 struct triangular_assignment_selector<Derived1, Derived2, SelfAdjoint|Upper, Dynamic, ClearOpposite>
256 {
257  typedef typename Derived1::Index Index;
258  static inline void run(Derived1 &dst, const Derived2 &src)
259  {
260  for(Index j = 0; j < dst.cols(); ++j)
261  {
262  for(Index i = 0; i < j; ++i)
263  {
264  dst.copyCoeff(i, j, src);
265  dst.coeffRef(j,i) = numext::conj(dst.coeff(i,j));
266  }
267  dst.copyCoeff(j, j, src);
268  }
269  }
270 };
271 
272 template<typename Derived1, typename Derived2, bool ClearOpposite>
273 struct triangular_assignment_selector<Derived1, Derived2, SelfAdjoint|Lower, Dynamic, ClearOpposite>
274 {
275  static inline void run(Derived1 &dst, const Derived2 &src)
276  {
277  typedef typename Derived1::Index Index;
278  for(Index i = 0; i < dst.rows(); ++i)
279  {
280  for(Index j = 0; j < i; ++j)
281  {
282  dst.copyCoeff(i, j, src);
283  dst.coeffRef(j,i) = numext::conj(dst.coeff(i,j));
284  }
285  dst.copyCoeff(i, i, src);
286  }
287  }
288 };
289 
290 } // end namespace internal
291 
292 /***************************************************************************
293 * Implementation of MatrixBase methods
294 ***************************************************************************/
295 
296 template<typename Derived>
297 template<unsigned int UpLo>
300 {
301  return derived();
302 }
303 
304 template<typename Derived>
305 template<unsigned int UpLo>
308 {
309  return derived();
310 }
311 
312 } // end namespace Eigen
313 
314 #endif // EIGEN_SELFADJOINTMATRIX_H
Robust Cholesky decomposition of a matrix with pivoting.
Definition: LDLT.h:45
internal::traits< SelfAdjointView >::MatrixTypeNestedCleaned MatrixTypeNestedCleaned
Scalar & coeffRef(Index row, Index col)
TriangularBase< SelfAdjointView > Base
const AutoDiffScalar< DerType > & conj(const AutoDiffScalar< DerType > &x)
friend SelfadjointProductMatrix< OtherDerived, 0, OtherDerived::IsVectorAtCompileTime, MatrixType, Mode, false > operator*(const MatrixBase< OtherDerived > &lhs, const SelfAdjointView &rhs)
const unsigned int DirectAccessBit
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:88
Matrix< RealScalar, internal::traits< MatrixType >::ColsAtCompileTime, 1 > EigenvaluesReturnType
const unsigned int PacketAccessBit
internal::traits< SelfAdjointView >::Scalar Scalar
The type of coefficients in this matrix.
RealReturnType real() const
const unsigned int HereditaryBits
const MatrixTypeNestedCleaned & nestedExpression() const
Standard Cholesky decomposition (LL^T) of a matrix and associated features.
Definition: LLT.h:50
NumTraits< Scalar >::Real RealScalar
Expression of a selfadjoint matrix from a triangular part of a dense matrix.
Index outerStride() const
MatrixType::PlainObject PlainObject
MatrixTypeNestedCleaned & nestedExpression()
#define v
void rhs(const real_t *x, real_t *f)
Index innerStride() const
Scalar coeff(Index row, Index col) const
SelfAdjointViewReturnType< UpLo >::Type selfadjointView()
RowXpr row(Index i)
Definition: BlockMethods.h:725
Base class for triangular part in a matrix.
MatrixTypeNested m_matrix
remove_all< MatrixTypeNested >::type MatrixTypeNestedCleaned
ColXpr col(Index i)
Definition: BlockMethods.h:708
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:127
const MatrixTypeNestedCleaned & _expression() const
const AdjointReturnType adjoint() const
Definition: Transpose.h:237
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
SelfadjointProductMatrix< MatrixType, Mode, false, OtherDerived, 0, OtherDerived::IsVectorAtCompileTime > operator*(const MatrixBase< OtherDerived > &rhs) const
const unsigned int LinearAccessBit
SelfAdjointView(MatrixType &matrix)
internal::traits< SelfAdjointView >::MatrixTypeNested MatrixTypeNested
MatrixType::Index Index


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