Eigen  5.0.1
 
Loading...
Searching...
No Matches
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// SPDX-License-Identifier: MPL-2.0
10
11#ifndef EIGEN_INVERSE_H
12#define EIGEN_INVERSE_H
13
14// IWYU pragma: private
15#include "./InternalHeaderCheck.h"
16
17namespace Eigen {
18
19template <typename XprType, typename StorageKind>
20class InverseImpl;
21
22namespace internal {
23
24template <typename XprType>
25struct traits<Inverse<XprType> > : traits<typename XprType::PlainObject> {
26 using PlainObject = typename XprType::PlainObject;
27 using BaseTraits = traits<PlainObject>;
28 enum { Flags = BaseTraits::Flags & RowMajorBit };
29};
30
31} // end namespace internal
32
43template <typename XprType>
44class Inverse : public InverseImpl<XprType, typename internal::traits<XprType>::StorageKind> {
45 public:
46 using StorageIndex = typename XprType::StorageIndex;
47 using Scalar = typename XprType::Scalar;
48 using XprTypeNested = typename internal::ref_selector<XprType>::type;
49 using XprTypeNestedCleaned = internal::remove_all_t<XprTypeNested>;
50 using Nested = typename internal::ref_selector<Inverse>::type;
51 using NestedExpression = internal::remove_all_t<XprType>;
52
53 explicit EIGEN_DEVICE_FUNC constexpr Inverse(const XprType& xpr) : m_xpr(xpr) {}
54
55 EIGEN_DEVICE_FUNC constexpr Index rows() const noexcept { return m_xpr.cols(); }
56 EIGEN_DEVICE_FUNC constexpr Index cols() const noexcept { return m_xpr.rows(); }
57
58 EIGEN_DEVICE_FUNC constexpr const XprTypeNestedCleaned& nestedExpression() const { return m_xpr; }
59
60 protected:
61 XprTypeNested m_xpr;
62};
63
64// Generic API dispatcher
65template <typename XprType, typename StorageKind>
66class InverseImpl : public internal::generic_xpr_base<Inverse<XprType> >::type {
67 public:
68 using Base = typename internal::generic_xpr_base<Inverse<XprType>>::type;
69 using Scalar = typename XprType::Scalar;
70
71 private:
72 Scalar coeff(Index row, Index col) const;
73 Scalar coeff(Index i) const;
74};
75
76namespace internal {
77
88template <typename ArgType>
89struct unary_evaluator<Inverse<ArgType> > : public evaluator<typename Inverse<ArgType>::PlainObject> {
90 using InverseType = Inverse<ArgType>;
91 using PlainObject = typename InverseType::PlainObject;
92 using Base = evaluator<PlainObject>;
93
94 enum { Flags = Base::Flags | EvalBeforeNestingBit };
95
96 EIGEN_DEVICE_FUNC unary_evaluator(const InverseType& inv_xpr) : m_result(inv_xpr.rows(), inv_xpr.cols()) {
97 internal::construct_at<Base>(this, m_result);
98 internal::call_assignment_no_alias(m_result, inv_xpr);
99 }
100
101 protected:
102 PlainObject m_result;
103};
104
105} // end namespace internal
106
107} // end namespace Eigen
108
109#endif // EIGEN_INVERSE_H
constexpr unsigned int EvalBeforeNestingBit
Definition Constants.h:75
constexpr unsigned int RowMajorBit
Definition Constants.h:71