$darkmode
Eigen  5.0.1-dev
Inverse.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2014-2019 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 // IWYU pragma: private
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 template <typename XprType, typename StorageKind>
19 class InverseImpl;
20 
21 namespace internal {
22 
23 template <typename XprType>
24 struct traits<Inverse<XprType> > : traits<typename XprType::PlainObject> {
25  typedef typename XprType::PlainObject PlainObject;
26  typedef traits<PlainObject> BaseTraits;
27  enum { Flags = BaseTraits::Flags & RowMajorBit };
28 };
29 
30 } // end namespace internal
31 
42 template <typename XprType>
43 class Inverse : public InverseImpl<XprType, typename internal::traits<XprType>::StorageKind> {
44  public:
45  typedef typename XprType::StorageIndex StorageIndex;
46  typedef typename XprType::Scalar Scalar;
47  typedef typename internal::ref_selector<XprType>::type XprTypeNested;
48  typedef internal::remove_all_t<XprTypeNested> XprTypeNestedCleaned;
49  typedef typename internal::ref_selector<Inverse>::type Nested;
50  typedef internal::remove_all_t<XprType> NestedExpression;
51 
52  explicit EIGEN_DEVICE_FUNC Inverse(const XprType& xpr) : m_xpr(xpr) {}
53 
54  EIGEN_DEVICE_FUNC constexpr Index rows() const noexcept { return m_xpr.cols(); }
55  EIGEN_DEVICE_FUNC constexpr Index cols() const noexcept { return m_xpr.rows(); }
56 
57  EIGEN_DEVICE_FUNC const XprTypeNestedCleaned& nestedExpression() const { return m_xpr; }
58 
59  protected:
60  XprTypeNested m_xpr;
61 };
62 
63 // Generic API dispatcher
64 template <typename XprType, typename StorageKind>
65 class InverseImpl : public internal::generic_xpr_base<Inverse<XprType> >::type {
66  public:
67  typedef typename internal::generic_xpr_base<Inverse<XprType> >::type Base;
68  typedef typename XprType::Scalar Scalar;
69 
70  private:
71  Scalar coeff(Index row, Index col) const;
72  Scalar coeff(Index i) const;
73 };
74 
75 namespace internal {
76 
87 template <typename ArgType>
88 struct unary_evaluator<Inverse<ArgType> > : public evaluator<typename Inverse<ArgType>::PlainObject> {
89  typedef Inverse<ArgType> InverseType;
90  typedef typename InverseType::PlainObject PlainObject;
91  typedef evaluator<PlainObject> Base;
92 
93  enum { Flags = Base::Flags | EvalBeforeNestingBit };
94 
95  EIGEN_DEVICE_FUNC unary_evaluator(const InverseType& inv_xpr) : m_result(inv_xpr.rows(), inv_xpr.cols()) {
96  internal::construct_at<Base>(this, m_result);
97  internal::call_assignment_no_alias(m_result, inv_xpr);
98  }
99 
100  protected:
101  PlainObject m_result;
102 };
103 
104 } // end namespace internal
105 
106 } // end namespace Eigen
107 
108 #endif // EIGEN_INVERSE_H
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
const unsigned int RowMajorBit
Definition: Constants.h:70
Expression of the inverse of another expression.
Definition: Inverse.h:43
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
const unsigned int EvalBeforeNestingBit
Definition: Constants.h:74