Medial Code Documentation
Loading...
Searching...
No Matches
SelfAdjointView.h
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
13namespace Eigen {
14
31namespace internal {
32template<typename MatrixType, unsigned int UpLo>
33struct 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 ??
49template<typename _MatrixType, unsigned int UpLo> class SelfAdjointView
50 : public TriangularBase<SelfAdjointView<_MatrixType, UpLo> >
51{
52 public:
53
54 typedef _MatrixType MatrixType;
56 typedef typename internal::traits<SelfAdjointView>::MatrixTypeNested MatrixTypeNested;
57 typedef typename internal::traits<SelfAdjointView>::MatrixTypeNestedCleaned MatrixTypeNestedCleaned;
58
61 typedef typename MatrixType::StorageIndex StorageIndex;
62
63 enum {
66 };
67 typedef typename MatrixType::PlainObject PlainObject;
68
70 explicit inline SelfAdjointView(MatrixType& matrix) : m_matrix(matrix)
71 {}
72
73 EIGEN_DEVICE_FUNC
74 inline Index rows() const { return m_matrix.rows(); }
75 EIGEN_DEVICE_FUNC
76 inline Index cols() const { return m_matrix.cols(); }
77 EIGEN_DEVICE_FUNC
78 inline Index outerStride() const { return m_matrix.outerStride(); }
79 EIGEN_DEVICE_FUNC
80 inline Index innerStride() const { return m_matrix.innerStride(); }
81
85 EIGEN_DEVICE_FUNC
86 inline Scalar coeff(Index row, Index col) const
87 {
88 Base::check_coordinates_internal(row, col);
89 return m_matrix.coeff(row, col);
90 }
91
96 inline Scalar& coeffRef(Index row, Index col)
97 {
98 EIGEN_STATIC_ASSERT_LVALUE(SelfAdjointView);
99 Base::check_coordinates_internal(row, col);
100 return m_matrix.const_cast_derived().coeffRef(row, col);
101 }
102
105 const MatrixTypeNestedCleaned& _expression() const { return m_matrix; }
106
107 EIGEN_DEVICE_FUNC
108 const MatrixTypeNestedCleaned& nestedExpression() const { return m_matrix; }
109 EIGEN_DEVICE_FUNC
110 MatrixTypeNestedCleaned& nestedExpression() { return *const_cast<MatrixTypeNestedCleaned*>(&m_matrix); }
111
113 template<typename OtherDerived>
114 EIGEN_DEVICE_FUNC
115 const Product<SelfAdjointView,OtherDerived>
117 {
118 return Product<SelfAdjointView,OtherDerived>(*this, rhs.derived());
119 }
120
122 template<typename OtherDerived> friend
126 {
127 return Product<OtherDerived,SelfAdjointView>(lhs.derived(),rhs);
128 }
129
130 friend EIGEN_DEVICE_FUNC
132 operator*(const Scalar& s, const SelfAdjointView& mat)
133 {
134 return (s*mat.nestedExpression()).template selfadjointView<UpLo>();
135 }
136
147 template<typename DerivedU, typename DerivedV>
148 EIGEN_DEVICE_FUNC
150
161 template<typename DerivedU>
164
166
167 const LLT<PlainObject, UpLo> llt() const;
168 const LDLT<PlainObject, UpLo> ldlt() const;
169
171
173 typedef typename NumTraits<Scalar>::Real RealScalar;
176
180 RealScalar operatorNorm() const;
181
182 protected:
183 MatrixTypeNested m_matrix;
184};
185
186
187// template<typename OtherDerived, typename MatrixType, unsigned int UpLo>
188// internal::selfadjoint_matrix_product_returntype<OtherDerived,SelfAdjointView<MatrixType,UpLo> >
189// operator*(const MatrixBase<OtherDerived>& lhs, const SelfAdjointView<MatrixType,UpLo>& rhs)
190// {
191// return internal::matrix_selfadjoint_product_returntype<OtherDerived,SelfAdjointView<MatrixType,UpLo> >(lhs.derived(),rhs);
192// }
193
194// selfadjoint to dense matrix
195
196namespace internal {
197
198// TODO currently a selfadjoint expression has the form SelfAdjointView<.,.>
199// in the future selfadjoint-ness should be defined by the expression traits
200// such that Transpose<SelfAdjointView<.,.> > is valid. (currently TriangularBase::transpose() is overloaded to make it work)
201template<typename MatrixType, unsigned int Mode>
202struct evaluator_traits<SelfAdjointView<MatrixType,Mode> >
203{
205 typedef SelfAdjointShape Shape;
206
207 static const int AssumeAliasing = 0;
208};
209
210template<int UpLo, int SetOpposite, typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT, typename Functor, int Version>
212 : public generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, Version>
213{
214protected:
216 typedef typename Base::DstXprType DstXprType;
217 typedef typename Base::SrcXprType SrcXprType;
218 using Base::m_dst;
219 using Base::m_src;
220 using Base::m_functor;
221public:
222
223 typedef typename Base::DstEvaluatorType DstEvaluatorType;
224 typedef typename Base::SrcEvaluatorType SrcEvaluatorType;
225 typedef typename Base::Scalar Scalar;
227
228
229 EIGEN_DEVICE_FUNC triangular_dense_assignment_kernel(DstEvaluatorType &dst, const SrcEvaluatorType &src, const Functor &func, DstXprType& dstExpr)
230 : Base(dst, src, func, dstExpr)
231 {}
232
233 EIGEN_DEVICE_FUNC void assignCoeff(Index row, Index col)
234 {
235 eigen_internal_assert(row!=col);
236 Scalar tmp = m_src.coeff(row,col);
237 m_functor.assignCoeff(m_dst.coeffRef(row,col), tmp);
238 m_functor.assignCoeff(m_dst.coeffRef(col,row), numext::conj(tmp));
239 }
240
241 EIGEN_DEVICE_FUNC void assignDiagonalCoeff(Index id)
242 {
243 Base::assignCoeff(id,id);
244 }
245
246 EIGEN_DEVICE_FUNC void assignOppositeCoeff(Index, Index)
247 { eigen_internal_assert(false && "should never be called"); }
248};
249
250} // end namespace internal
251
252/***************************************************************************
253* Implementation of MatrixBase methods
254***************************************************************************/
255
256template<typename Derived>
257template<unsigned int UpLo>
258typename MatrixBase<Derived>::template ConstSelfAdjointViewReturnType<UpLo>::Type
260{
261 return typename ConstSelfAdjointViewReturnType<UpLo>::Type(derived());
262}
263
264template<typename Derived>
265template<unsigned int UpLo>
266typename MatrixBase<Derived>::template SelfAdjointViewReturnType<UpLo>::Type
267MatrixBase<Derived>::selfadjointView()
268{
269 return typename SelfAdjointViewReturnType<UpLo>::Type(derived());
270}
271
272} // end namespace Eigen
273
274#endif // EIGEN_SELFADJOINTMATRIX_H
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
Expression of a selfadjoint matrix from a triangular part of a dense matrix.
Definition SelfAdjointView.h:51
friend EIGEN_DEVICE_FUNC const Product< OtherDerived, SelfAdjointView > operator*(const MatrixBase< OtherDerived > &lhs, const SelfAdjointView &rhs)
Efficient vector/matrix times triangular matrix product.
Definition SelfAdjointView.h:125
EIGEN_DEVICE_FUNC RealScalar operatorNorm() const
Computes the L2 operator norm.
Definition MatrixBaseEigenvalues.h:153
EIGEN_DEVICE_FUNC SelfAdjointView & rankUpdate(const MatrixBase< DerivedU > &u, const MatrixBase< DerivedV > &v, const Scalar &alpha=Scalar(1))
Perform a symmetric rank 2 update of the selfadjoint matrix *this: .
EIGEN_DEVICE_FUNC SelfAdjointView & rankUpdate(const MatrixBase< DerivedU > &u, const Scalar &alpha=Scalar(1))
Perform a symmetric rank K update of the selfadjoint matrix *this: where u is a vector or matrix.
const LLT< PlainObject, UpLo > llt() const
\cholesky_module
Definition LLT.h:484
EIGEN_DEVICE_FUNC const Product< SelfAdjointView, OtherDerived > operator*(const MatrixBase< OtherDerived > &rhs) const
Efficient triangular matrix times vector/matrix product.
Definition SelfAdjointView.h:116
const LDLT< PlainObject, UpLo > ldlt() const
\cholesky_module
Definition LDLT.h:582
Matrix< RealScalar, internal::traits< MatrixType >::ColsAtCompileTime, 1 > EigenvaluesReturnType
Return type of eigenvalues()
Definition SelfAdjointView.h:175
EIGEN_DEVICE_FUNC Scalar & coeffRef(Index row, Index col)
Definition SelfAdjointView.h:96
EIGEN_DEVICE_FUNC Scalar coeff(Index row, Index col) const
Definition SelfAdjointView.h:86
EIGEN_DEVICE_FUNC EigenvaluesReturnType eigenvalues() const
Computes the eigenvalues of a matrix.
Definition MatrixBaseEigenvalues.h:89
internal::traits< SelfAdjointView >::Scalar Scalar
The type of coefficients in this matrix.
Definition SelfAdjointView.h:60
NumTraits< Scalar >::Real RealScalar
Real part of Scalar.
Definition SelfAdjointView.h:173
Pseudo expression representing a solving operation.
Definition Solve.h:63
Base class for triangular part in a matrix.
Definition TriangularMatrix.h:28
Definition AssignEvaluator.h:539
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Index row, Index col)
Assign src(row,col) to dst(row,col) through the assignment functor.
Definition AssignEvaluator.h:571
@ SelfAdjoint
Used in BandMatrix and SelfAdjointView to indicate that the matrix is self-adjoint.
Definition Constants.h:220
const unsigned int PacketAccessBit
Short version: means the expression might be vectorized.
Definition Constants.h:88
const unsigned int LinearAccessBit
Short version: means the expression can be seen as 1D vector.
Definition Constants.h:124
const unsigned int DirectAccessBit
Means that the underlying array of coefficients can be directly accessed as a plain strided array.
Definition Constants.h:149
const unsigned int LvalueBit
Means the expression has a coeffRef() method, i.e.
Definition Constants.h:138
Eigen::Index Index
The interface type of indices.
Definition EigenBase.h:37
Definition Constants.h:517
Definition Constants.h:525
Definition CoreEvaluators.h:75
Definition XprHelper.h:628
Definition ForwardDeclarations.h:17
Definition Meta.h:30