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 FullMatrixType;
39  enum {
40  Mode = UpLo | SelfAdjoint,
41  FlagsLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0,
42  Flags = MatrixTypeNestedCleaned::Flags & (HereditaryBits|FlagsLvalueBit)
43  & (~(PacketAccessBit | DirectAccessBit | LinearAccessBit)) // FIXME these flags should be preserved
44  };
45 };
46 }
47 
48 // FIXME could also be called SelfAdjointWrapper to be consistent with DiagonalWrapper ??
49 template<typename _MatrixType, unsigned int UpLo> class SelfAdjointView
50  : public TriangularBase<SelfAdjointView<_MatrixType, UpLo> >
51 {
52  public:
53 
54  typedef _MatrixType MatrixType;
58  typedef MatrixTypeNestedCleaned NestedExpression;
59 
62  typedef typename MatrixType::StorageIndex StorageIndex;
63 
64  enum {
67  };
68  typedef typename MatrixType::PlainObject PlainObject;
69 
70  EIGEN_DEVICE_FUNC
71  explicit inline SelfAdjointView(MatrixType& matrix) : m_matrix(matrix)
72  {}
73 
74  EIGEN_DEVICE_FUNC
75  inline Index rows() const { return m_matrix.rows(); }
76  EIGEN_DEVICE_FUNC
77  inline Index cols() const { return m_matrix.cols(); }
78  EIGEN_DEVICE_FUNC
79  inline Index outerStride() const { return m_matrix.outerStride(); }
80  EIGEN_DEVICE_FUNC
81  inline Index innerStride() const { return m_matrix.innerStride(); }
82 
86  EIGEN_DEVICE_FUNC
87  inline Scalar coeff(Index row, Index col) const
88  {
89  Base::check_coordinates_internal(row, col);
90  return m_matrix.coeff(row, col);
91  }
92 
96  EIGEN_DEVICE_FUNC
97  inline Scalar& coeffRef(Index row, Index col)
98  {
100  Base::check_coordinates_internal(row, col);
101  return m_matrix.coeffRef(row, col);
102  }
103 
105  EIGEN_DEVICE_FUNC
106  const MatrixTypeNestedCleaned& _expression() const { return m_matrix; }
107 
108  EIGEN_DEVICE_FUNC
109  const MatrixTypeNestedCleaned& nestedExpression() const { return m_matrix; }
110  EIGEN_DEVICE_FUNC
111  MatrixTypeNestedCleaned& nestedExpression() { return m_matrix; }
112 
114  template<typename OtherDerived>
115  EIGEN_DEVICE_FUNC
118  {
119  return Product<SelfAdjointView,OtherDerived>(*this, rhs.derived());
120  }
121 
123  template<typename OtherDerived> friend
124  EIGEN_DEVICE_FUNC
127  {
128  return Product<OtherDerived,SelfAdjointView>(lhs.derived(),rhs);
129  }
130 
131  friend EIGEN_DEVICE_FUNC
133  operator*(const Scalar& s, const SelfAdjointView& mat)
134  {
135  return (s*mat.nestedExpression()).template selfadjointView<UpLo>();
136  }
137 
148  template<typename DerivedU, typename DerivedV>
149  EIGEN_DEVICE_FUNC
150  SelfAdjointView& rankUpdate(const MatrixBase<DerivedU>& u, const MatrixBase<DerivedV>& v, const Scalar& alpha = Scalar(1));
151 
162  template<typename DerivedU>
163  EIGEN_DEVICE_FUNC
164  SelfAdjointView& rankUpdate(const MatrixBase<DerivedU>& u, const Scalar& alpha = Scalar(1));
165 
176  template<unsigned int TriMode>
177  EIGEN_DEVICE_FUNC
178  typename internal::conditional<(TriMode&(Upper|Lower))==(UpLo&(Upper|Lower)),
182  {
185  return typename internal::conditional<(TriMode&(Upper|Lower))==(UpLo&(Upper|Lower)),
188  }
189 
195  EIGEN_DEVICE_FUNC
196  typename MatrixType::ConstDiagonalReturnType diagonal() const
197  {
198  return typename MatrixType::ConstDiagonalReturnType(m_matrix);
199  }
200 
202 
203  const LLT<PlainObject, UpLo> llt() const;
204  const LDLT<PlainObject, UpLo> ldlt() const;
205 
207 
212 
213  EIGEN_DEVICE_FUNC
214  EigenvaluesReturnType eigenvalues() const;
215  EIGEN_DEVICE_FUNC
216  RealScalar operatorNorm() const;
217 
218  protected:
219  MatrixTypeNested m_matrix;
220 };
221 
222 
223 // template<typename OtherDerived, typename MatrixType, unsigned int UpLo>
224 // internal::selfadjoint_matrix_product_returntype<OtherDerived,SelfAdjointView<MatrixType,UpLo> >
225 // operator*(const MatrixBase<OtherDerived>& lhs, const SelfAdjointView<MatrixType,UpLo>& rhs)
226 // {
227 // return internal::matrix_selfadjoint_product_returntype<OtherDerived,SelfAdjointView<MatrixType,UpLo> >(lhs.derived(),rhs);
228 // }
229 
230 // selfadjoint to dense matrix
231 
232 namespace internal {
233 
234 // TODO currently a selfadjoint expression has the form SelfAdjointView<.,.>
235 // in the future selfadjoint-ness should be defined by the expression traits
236 // such that Transpose<SelfAdjointView<.,.> > is valid. (currently TriangularBase::transpose() is overloaded to make it work)
237 template<typename MatrixType, unsigned int Mode>
238 struct evaluator_traits<SelfAdjointView<MatrixType,Mode> >
239 {
242 };
243 
244 template<int UpLo, int SetOpposite, typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT, typename Functor, int Version>
245 class triangular_dense_assignment_kernel<UpLo,SelfAdjoint,SetOpposite,DstEvaluatorTypeT,SrcEvaluatorTypeT,Functor,Version>
246  : public generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, Version>
247 {
248 protected:
250  typedef typename Base::DstXprType DstXprType;
251  typedef typename Base::SrcXprType SrcXprType;
252  using Base::m_dst;
253  using Base::m_src;
254  using Base::m_functor;
255 public:
256 
259  typedef typename Base::Scalar Scalar;
261 
262 
263  EIGEN_DEVICE_FUNC triangular_dense_assignment_kernel(DstEvaluatorType &dst, const SrcEvaluatorType &src, const Functor &func, DstXprType& dstExpr)
264  : Base(dst, src, func, dstExpr)
265  {}
266 
267  EIGEN_DEVICE_FUNC void assignCoeff(Index row, Index col)
268  {
269  eigen_internal_assert(row!=col);
270  Scalar tmp = m_src.coeff(row,col);
271  m_functor.assignCoeff(m_dst.coeffRef(row,col), tmp);
272  m_functor.assignCoeff(m_dst.coeffRef(col,row), numext::conj(tmp));
273  }
274 
275  EIGEN_DEVICE_FUNC void assignDiagonalCoeff(Index id)
276  {
277  Base::assignCoeff(id,id);
278  }
279 
280  EIGEN_DEVICE_FUNC void assignOppositeCoeff(Index, Index)
281  { eigen_internal_assert(false && "should never be called"); }
282 };
283 
284 } // end namespace internal
285 
286 /***************************************************************************
287 * Implementation of MatrixBase methods
288 ***************************************************************************/
289 
290 template<typename Derived>
291 template<unsigned int UpLo>
294 {
295  return typename ConstSelfAdjointViewReturnType<UpLo>::Type(derived());
296 }
297 
298 template<typename Derived>
299 template<unsigned int UpLo>
302 {
303  return typename SelfAdjointViewReturnType<UpLo>::Type(derived());
304 }
305 
306 } // end namespace Eigen
307 
308 #endif // EIGEN_SELFADJOINTMATRIX_H
Robust Cholesky decomposition of a matrix with pivoting.
Definition: LDLT.h:50
Matrix< RealScalar, internal::traits< MatrixType >::ColsAtCompileTime, 1 > EigenvaluesReturnType
friend EIGEN_DEVICE_FUNC const SelfAdjointView< const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar, MatrixType, product), UpLo > operator*(const Scalar &s, const SelfAdjointView &mat)
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:71
EIGEN_DEVICE_FUNC Index outerStride() const
MatrixType::StorageIndex StorageIndex
Base class for triangular part in a matrix.
const unsigned int DirectAccessBit
Definition: Constants.h:150
EIGEN_DEVICE_FUNC MatrixType::ConstDiagonalReturnType diagonal() const
EIGEN_DEVICE_FUNC ColXpr col(Index i)
This is the const version of col(). */.
Definition: BlockMethods.h:838
const unsigned int LvalueBit
Definition: Constants.h:139
Definition: LDLT.h:16
MatrixType::PlainObject PlainObject
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:150
NumTraits< Scalar >::Real RealScalar
EIGEN_DEVICE_FUNC triangular_dense_assignment_kernel(DstEvaluatorType &dst, const SrcEvaluatorType &src, const Functor &func, DstXprType &dstExpr)
storage_kind_to_evaluator_kind< typename MatrixType::StorageKind >::Kind Kind
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:37
EIGEN_DEVICE_FUNC SelfAdjointViewReturnType< UpLo >::Type selfadjointView()
const unsigned int PacketAccessBit
Definition: Constants.h:89
EIGEN_DEVICE_FUNC const MatrixTypeNestedCleaned & _expression() const
#define EIGEN_STATIC_ASSERT_LVALUE(Derived)
Definition: StaticAssert.h:197
internal::traits< SelfAdjointView >::Scalar Scalar
The type of coefficients in this matrix.
internal::traits< SelfAdjointView >::MatrixTypeNestedCleaned MatrixTypeNestedCleaned
EIGEN_DEVICE_FUNC MatrixTypeNestedCleaned & nestedExpression()
internal::traits< SelfAdjointView >::MatrixTypeNested MatrixTypeNested
EIGEN_DEVICE_FUNC const MatrixTypeNestedCleaned & nestedExpression() const
TriangularBase< SelfAdjointView > Base
const unsigned int HereditaryBits
Definition: Constants.h:190
EIGEN_DEVICE_FUNC Index rows() const
Standard Cholesky decomposition (LL^T) of a matrix and associated features.
Definition: LLT.h:52
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
ref_selector< MatrixType >::non_const_type MatrixTypeNested
Expression of a selfadjoint matrix from a triangular part of a dense matrix.
EIGEN_DEVICE_FUNC Index innerStride() const
EIGEN_DEVICE_FUNC SelfAdjointView(MatrixType &matrix)
EIGEN_DEVICE_FUNC Index cols() const
MatrixTypeNested m_matrix
Expression of a triangular part in a matrix.
EIGEN_DEVICE_FUNC RowXpr row(Index i)
This is the const version of row(). */.
Definition: BlockMethods.h:859
remove_all< MatrixTypeNested >::type MatrixTypeNestedCleaned
#define eigen_internal_assert(x)
Definition: Macros.h:582
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:178
EIGEN_DEVICE_FUNC internal::conditional<(TriMode &(Upper|Lower))==(UpLo &(Upper|Lower)), TriangularView< MatrixType, TriMode >, TriangularView< typename MatrixType::AdjointReturnType, TriMode > >::type triangularView() const
EIGEN_DEVICE_FUNC const Product< SelfAdjointView, OtherDerived > operator*(const MatrixBase< OtherDerived > &rhs) const
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
const unsigned int LinearAccessBit
Definition: Constants.h:125
friend EIGEN_DEVICE_FUNC const Product< OtherDerived, SelfAdjointView > operator*(const MatrixBase< OtherDerived > &lhs, const SelfAdjointView &rhs)
MatrixTypeNestedCleaned NestedExpression
EIGEN_DEVICE_FUNC Scalar coeff(Index row, Index col) const
EIGEN_DEVICE_FUNC Scalar & coeffRef(Index row, Index col)


co_scan
Author(s):
autogenerated on Mon Feb 28 2022 23:00:49