Path Tracer
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 
13 namespace Eigen {
14 
31 namespace internal {
32 template<typename MatrixType, unsigned int UpLo>
33 struct traits<SelfAdjointView<MatrixType, UpLo> > : traits<MatrixType>
34 {
35  typedef typename ref_selector<MatrixType>::non_const_type MatrixTypeNested;
36  typedef typename remove_all<MatrixTypeNested>::type MatrixTypeNestedCleaned;
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 
49 template<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  typedef MatrixTypeNestedCleaned NestedExpression;
59 
62  typedef typename MatrixType::StorageIndex StorageIndex;
63  typedef typename internal::remove_all<typename MatrixType::ConjugateReturnType>::type MatrixConjugateReturnType;
65 
66  enum {
69  TransposeMode = ((Mode & Upper) ? Lower : 0) | ((Mode & Lower) ? Upper : 0)
70  };
71  typedef typename MatrixType::PlainObject PlainObject;
72 
73  EIGEN_DEVICE_FUNC
74  explicit inline SelfAdjointView(MatrixType& matrix) : m_matrix(matrix)
75  {
76  EIGEN_STATIC_ASSERT(UpLo==Lower || UpLo==Upper,SELFADJOINTVIEW_ACCEPTS_UPPER_AND_LOWER_MODE_ONLY);
77  }
78 
79  EIGEN_DEVICE_FUNC
80  inline Index rows() const { return m_matrix.rows(); }
81  EIGEN_DEVICE_FUNC
82  inline Index cols() const { return m_matrix.cols(); }
83  EIGEN_DEVICE_FUNC
84  inline Index outerStride() const { return m_matrix.outerStride(); }
85  EIGEN_DEVICE_FUNC
86  inline Index innerStride() const { return m_matrix.innerStride(); }
87 
91  EIGEN_DEVICE_FUNC
92  inline Scalar coeff(Index row, Index col) const
93  {
94  Base::check_coordinates_internal(row, col);
95  return m_matrix.coeff(row, col);
96  }
97 
101  EIGEN_DEVICE_FUNC
102  inline Scalar& coeffRef(Index row, Index col)
103  {
104  EIGEN_STATIC_ASSERT_LVALUE(SelfAdjointView);
105  Base::check_coordinates_internal(row, col);
106  return m_matrix.coeffRef(row, col);
107  }
108 
110  EIGEN_DEVICE_FUNC
111  const MatrixTypeNestedCleaned& _expression() const { return m_matrix; }
112 
113  EIGEN_DEVICE_FUNC
114  const MatrixTypeNestedCleaned& nestedExpression() const { return m_matrix; }
115  EIGEN_DEVICE_FUNC
116  MatrixTypeNestedCleaned& nestedExpression() { return m_matrix; }
117 
119  template<typename OtherDerived>
120  EIGEN_DEVICE_FUNC
121  const Product<SelfAdjointView,OtherDerived>
123  {
124  return Product<SelfAdjointView,OtherDerived>(*this, rhs.derived());
125  }
126 
128  template<typename OtherDerived> friend
129  EIGEN_DEVICE_FUNC
132  {
133  return Product<OtherDerived,SelfAdjointView>(lhs.derived(),rhs);
134  }
135 
136  friend EIGEN_DEVICE_FUNC
137  const SelfAdjointView<const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar,MatrixType,product),UpLo>
138  operator*(const Scalar& s, const SelfAdjointView& mat)
139  {
140  return (s*mat.nestedExpression()).template selfadjointView<UpLo>();
141  }
142 
153  template<typename DerivedU, typename DerivedV>
154  EIGEN_DEVICE_FUNC
156 
167  template<typename DerivedU>
168  EIGEN_DEVICE_FUNC
170 
181  template<unsigned int TriMode>
182  EIGEN_DEVICE_FUNC
183  typename internal::conditional<(TriMode&(Upper|Lower))==(UpLo&(Upper|Lower)),
187  {
188  typename internal::conditional<(TriMode&(Upper|Lower))==(UpLo&(Upper|Lower)), MatrixType&, typename MatrixType::ConstTransposeReturnType>::type tmp1(m_matrix);
189  typename internal::conditional<(TriMode&(Upper|Lower))==(UpLo&(Upper|Lower)), MatrixType&, typename MatrixType::AdjointReturnType>::type tmp2(tmp1);
190  return typename internal::conditional<(TriMode&(Upper|Lower))==(UpLo&(Upper|Lower)),
193  }
194 
195  typedef SelfAdjointView<const MatrixConjugateReturnType,UpLo> ConjugateReturnType;
197  EIGEN_DEVICE_FUNC
198  inline const ConjugateReturnType conjugate() const
199  { return ConjugateReturnType(m_matrix.conjugate()); }
200 
204  template<bool Cond>
205  EIGEN_DEVICE_FUNC
207  conjugateIf() const
208  {
210  return ReturnType(m_matrix.template conjugateIf<Cond>());
211  }
212 
215  EIGEN_DEVICE_FUNC
216  inline const AdjointReturnType adjoint() const
217  { return AdjointReturnType(m_matrix.adjoint()); }
218 
221  EIGEN_DEVICE_FUNC
223  {
224  EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
225  typename MatrixType::TransposeReturnType tmp(m_matrix);
226  return TransposeReturnType(tmp);
227  }
228 
231  EIGEN_DEVICE_FUNC
232  inline const ConstTransposeReturnType transpose() const
233  {
234  return ConstTransposeReturnType(m_matrix.transpose());
235  }
236 
242  EIGEN_DEVICE_FUNC
243  typename MatrixType::ConstDiagonalReturnType diagonal() const
244  {
245  return typename MatrixType::ConstDiagonalReturnType(m_matrix);
246  }
247 
249 
250  const LLT<PlainObject, UpLo> llt() const;
251  const LDLT<PlainObject, UpLo> ldlt() const;
252 
254 
259 
260  EIGEN_DEVICE_FUNC
262  EIGEN_DEVICE_FUNC
263  RealScalar operatorNorm() const;
264 
265  protected:
266  MatrixTypeNested m_matrix;
267 };
268 
269 
270 // template<typename OtherDerived, typename MatrixType, unsigned int UpLo>
271 // internal::selfadjoint_matrix_product_returntype<OtherDerived,SelfAdjointView<MatrixType,UpLo> >
272 // operator*(const MatrixBase<OtherDerived>& lhs, const SelfAdjointView<MatrixType,UpLo>& rhs)
273 // {
274 // return internal::matrix_selfadjoint_product_returntype<OtherDerived,SelfAdjointView<MatrixType,UpLo> >(lhs.derived(),rhs);
275 // }
276 
277 // selfadjoint to dense matrix
278 
279 namespace internal {
280 
281 // TODO currently a selfadjoint expression has the form SelfAdjointView<.,.>
282 // in the future selfadjoint-ness should be defined by the expression traits
283 // such that Transpose<SelfAdjointView<.,.> > is valid. (currently TriangularBase::transpose() is overloaded to make it work)
284 template<typename MatrixType, unsigned int Mode>
285 struct evaluator_traits<SelfAdjointView<MatrixType,Mode> >
286 {
288  typedef SelfAdjointShape Shape;
289 };
290 
291 template<int UpLo, int SetOpposite, typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT, typename Functor, int Version>
292 class triangular_dense_assignment_kernel<UpLo,SelfAdjoint,SetOpposite,DstEvaluatorTypeT,SrcEvaluatorTypeT,Functor,Version>
293  : public generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, Version>
294 {
295 protected:
297  typedef typename Base::DstXprType DstXprType;
298  typedef typename Base::SrcXprType SrcXprType;
299  using Base::m_dst;
300  using Base::m_src;
301  using Base::m_functor;
302 public:
303 
304  typedef typename Base::DstEvaluatorType DstEvaluatorType;
305  typedef typename Base::SrcEvaluatorType SrcEvaluatorType;
306  typedef typename Base::Scalar Scalar;
307  typedef typename Base::AssignmentTraits AssignmentTraits;
308 
309 
310  EIGEN_DEVICE_FUNC triangular_dense_assignment_kernel(DstEvaluatorType &dst, const SrcEvaluatorType &src, const Functor &func, DstXprType& dstExpr)
311  : Base(dst, src, func, dstExpr)
312  {}
313 
314  EIGEN_DEVICE_FUNC void assignCoeff(Index row, Index col)
315  {
316  eigen_internal_assert(row!=col);
317  Scalar tmp = m_src.coeff(row,col);
318  m_functor.assignCoeff(m_dst.coeffRef(row,col), tmp);
319  m_functor.assignCoeff(m_dst.coeffRef(col,row), numext::conj(tmp));
320  }
321 
322  EIGEN_DEVICE_FUNC void assignDiagonalCoeff(Index id)
323  {
324  Base::assignCoeff(id,id);
325  }
326 
327  EIGEN_DEVICE_FUNC void assignOppositeCoeff(Index, Index)
328  { eigen_internal_assert(false && "should never be called"); }
329 };
330 
331 } // end namespace internal
332 
333 /***************************************************************************
334 * Implementation of MatrixBase methods
335 ***************************************************************************/
336 
338 template<typename Derived>
339 template<unsigned int UpLo>
340 EIGEN_DEVICE_FUNC typename MatrixBase<Derived>::template ConstSelfAdjointViewReturnType<UpLo>::Type
342 {
343  return typename ConstSelfAdjointViewReturnType<UpLo>::Type(derived());
344 }
345 
355 template<typename Derived>
356 template<unsigned int UpLo>
357 EIGEN_DEVICE_FUNC typename MatrixBase<Derived>::template SelfAdjointViewReturnType<UpLo>::Type
359 {
360  return typename SelfAdjointViewReturnType<UpLo>::Type(derived());
361 }
362 
363 } // end namespace Eigen
364 
365 #endif // EIGEN_SELFADJOINTMATRIX_H
Eigen::internal::generic_dense_assignment_kernel
Definition: AssignEvaluator.h:619
Eigen
Namespace containing all symbols from the Eigen library.
Definition: LDLT.h:16
Eigen::SelfAdjointView::RealScalar
NumTraits< Scalar >::Real RealScalar
Definition: SelfAdjointView.h:256
Eigen::SelfAdjointView::diagonal
EIGEN_DEVICE_FUNC MatrixType::ConstDiagonalReturnType diagonal() const
Definition: SelfAdjointView.h:243
Eigen::EigenBase< SelfAdjointView< _MatrixType, UpLo > >::Index
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:39
Eigen::SelfAdjointView::conjugateIf
EIGEN_DEVICE_FUNC internal::conditional< Cond, ConjugateReturnType, ConstSelfAdjointView >::type conjugateIf() const
Definition: SelfAdjointView.h:207
Eigen::SelfAdjointView::ldlt
const LDLT< PlainObject, UpLo > ldlt() const
Definition: LDLT.h:670
Eigen::internal::is_lvalue
Definition: XprHelper.h:668
Eigen::SelfAdjointView::adjoint
EIGEN_DEVICE_FUNC const AdjointReturnType adjoint() const
Definition: SelfAdjointView.h:216
Eigen::SelfAdjointView::llt
const LLT< PlainObject, UpLo > llt() const
Definition: LLT.h:551
Eigen::Upper
@ Upper
Definition: Constants.h:210
Eigen::internal::evaluator_traits
Definition: CoreEvaluators.h:80
Eigen::SelfAdjointView
Expression of a selfadjoint matrix from a triangular part of a dense matrix.
Definition: SelfAdjointView.h:51
Eigen::SelfAdjointView::eigenvalues
EIGEN_DEVICE_FUNC EigenvaluesReturnType eigenvalues() const
Computes the eigenvalues of a matrix.
Definition: MatrixBaseEigenvalues.h:88
Eigen::internal::copy_using_evaluator_traits
Definition: AssignEvaluator.h:29
Eigen::DirectAccessBit
const unsigned int DirectAccessBit
Definition: Constants.h:154
Eigen::SelfAdjointView::conjugate
EIGEN_DEVICE_FUNC const ConjugateReturnType conjugate() const
Definition: SelfAdjointView.h:198
Eigen::PacketAccessBit
const unsigned int PacketAccessBit
Definition: Constants.h:93
Eigen::SelfAdjointView::Scalar
internal::traits< SelfAdjointView >::Scalar Scalar
The type of coefficients in this matrix.
Definition: SelfAdjointView.h:61
Eigen::internal::true_type
Definition: Meta.h:63
Eigen::SelfAdjointView::operatorNorm
EIGEN_DEVICE_FUNC RealScalar operatorNorm() const
Computes the L2 operator norm.
Definition: MatrixBaseEigenvalues.h:151
Eigen::SelfAdjointView::rankUpdate
EIGEN_DEVICE_FUNC SelfAdjointView & rankUpdate(const MatrixBase< DerivedU > &u, const Scalar &alpha=Scalar(1))
Eigen::LvalueBit
const unsigned int LvalueBit
Definition: Constants.h:143
Eigen::TriangularBase
Base class for triangular part in a matrix.
Definition: TriangularMatrix.h:28
Eigen::SelfAdjointView::transpose
EIGEN_DEVICE_FUNC TransposeReturnType transpose()
Definition: SelfAdjointView.h:222
Eigen::Product
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:75
Eigen::SelfAdjointView::transpose
EIGEN_DEVICE_FUNC const ConstTransposeReturnType transpose() const
Definition: SelfAdjointView.h:232
Eigen::LDLT
Robust Cholesky decomposition of a matrix with pivoting.
Definition: LDLT.h:61
Eigen::SelfAdjointView::operator*
EIGEN_DEVICE_FUNC const Product< SelfAdjointView, OtherDerived > operator*(const MatrixBase< OtherDerived > &rhs) const
Definition: SelfAdjointView.h:122
Eigen::Lower
@ Lower
Definition: Constants.h:208
Eigen::internal::ref_selector
Definition: XprHelper.h:425
Eigen::SelfAdjointView::operator*
friend EIGEN_DEVICE_FUNC const Product< OtherDerived, SelfAdjointView > operator*(const MatrixBase< OtherDerived > &lhs, const SelfAdjointView &rhs)
Definition: SelfAdjointView.h:131
Eigen::LinearAccessBit
const unsigned int LinearAccessBit
Definition: Constants.h:129
Eigen::LLT
Standard Cholesky decomposition (LL^T) of a matrix and associated features.
Definition: LLT.h:68
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
Eigen::internal::triangular_dense_assignment_kernel::assignCoeff
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:654
Eigen::internal::conditional
Definition: Meta.h:76
Eigen::SelfAdjointShape
Definition: Constants.h:530
Eigen::SelfAdjointView::EigenvaluesReturnType
Matrix< RealScalar, internal::traits< MatrixType >::ColsAtCompileTime, 1 > EigenvaluesReturnType
Definition: SelfAdjointView.h:258
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:180
Eigen::internal::triangular_dense_assignment_kernel
Definition: TriangularMatrix.h:759
Eigen::internal::generic_dense_assignment_kernel::assignCoeff
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:654
Eigen::MatrixBase
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:50
Eigen::SelfAdjointView::coeff
EIGEN_DEVICE_FUNC Scalar coeff(Index row, Index col) const
Definition: SelfAdjointView.h:92
Eigen::SelfAdjointView::coeffRef
EIGEN_DEVICE_FUNC Scalar & coeffRef(Index row, Index col)
Definition: SelfAdjointView.h:102
Eigen::TriangularView
Expression of a triangular part in a matrix.
Definition: TriangularMatrix.h:189
Eigen::internal::IndexBased
Definition: Constants.h:538
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:213
Eigen::SelfAdjointView::triangularView
EIGEN_DEVICE_FUNC internal::conditional<(TriMode &(Upper|Lower))==(UpLo &(Upper|Lower)), TriangularView< MatrixType, TriMode >, TriangularView< typename MatrixType::AdjointReturnType, TriMode > >::type triangularView() const
Definition: SelfAdjointView.h:186
Eigen::SelfAdjoint
@ SelfAdjoint
Definition: Constants.h:224
Eigen::SelfAdjointView::rankUpdate
EIGEN_DEVICE_FUNC SelfAdjointView & rankUpdate(const MatrixBase< DerivedU > &u, const MatrixBase< DerivedV > &v, const Scalar &alpha=Scalar(1))
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:42