Eigen  3.2.91
Inverse.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2014 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_INVERSE_H
11 #define EIGEN_INVERSE_H
12 
13 namespace Eigen {
14 
15 // TODO move the general declaration in Core, and rename this file DenseInverseImpl.h, or something like this...
16 
17 template<typename XprType,typename StorageKind> class InverseImpl;
18 
19 namespace internal {
20 
21 template<typename XprType>
22 struct traits<Inverse<XprType> >
23  : traits<typename XprType::PlainObject>
24 {
25  typedef typename XprType::PlainObject PlainObject;
26  typedef traits<PlainObject> BaseTraits;
27  enum {
28  Flags = BaseTraits::Flags & RowMajorBit
29  };
30 };
31 
32 } // end namespace internal
33 
44 template<typename XprType>
45 class Inverse : public InverseImpl<XprType,typename internal::traits<XprType>::StorageKind>
46 {
47 public:
48  typedef typename XprType::StorageIndex StorageIndex;
49  typedef typename XprType::PlainObject PlainObject;
50  typedef typename internal::ref_selector<XprType>::type XprTypeNested;
51  typedef typename internal::remove_all<XprTypeNested>::type XprTypeNestedCleaned;
52 
53  explicit Inverse(const XprType &xpr)
54  : m_xpr(xpr)
55  {}
56 
57  EIGEN_DEVICE_FUNC Index rows() const { return m_xpr.rows(); }
58  EIGEN_DEVICE_FUNC Index cols() const { return m_xpr.cols(); }
59 
60  EIGEN_DEVICE_FUNC const XprTypeNestedCleaned& nestedExpression() const { return m_xpr; }
61 
62 protected:
63  XprTypeNested m_xpr;
64 };
65 
71 template<typename XprType>
72 class InverseImpl<XprType,Dense>
73  : public MatrixBase<Inverse<XprType> >
74 {
75  typedef Inverse<XprType> Derived;
76 
77 public:
78 
79  typedef MatrixBase<Derived> Base;
80  EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
81  typedef typename internal::remove_all<XprType>::type NestedExpression;
82 
83 private:
84 
85  Scalar coeff(Index row, Index col) const;
86  Scalar coeff(Index i) const;
87 };
88 
89 namespace internal {
90 
101 template<typename ArgType>
102 struct unary_evaluator<Inverse<ArgType> >
103  : public evaluator<typename Inverse<ArgType>::PlainObject>
104 {
105  typedef Inverse<ArgType> InverseType;
106  typedef typename InverseType::PlainObject PlainObject;
107  typedef evaluator<PlainObject> Base;
108 
109  enum { Flags = Base::Flags | EvalBeforeNestingBit };
110 
111  unary_evaluator(const InverseType& inv_xpr)
112  : m_result(inv_xpr.rows(), inv_xpr.cols())
113  {
114  ::new (static_cast<Base*>(this)) Base(m_result);
115  internal::call_assignment_no_alias(m_result, inv_xpr);
116  }
117 
118 protected:
119  PlainObject m_result;
120 };
121 
122 } // end namespace internal
123 
124 } // end namespace Eigen
125 
126 #endif // EIGEN_INVERSE_H
Definition: LDLT.h:16
const unsigned int RowMajorBit
Definition: Constants.h:53
Expression of the inverse of another expression.
Definition: Inverse.h:45
Definition: Eigen_Colamd.h:54
Definition: Constants.h:482
const unsigned int EvalBeforeNestingBit
Definition: Constants.h:57
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48