Eigen  5.0.1
 
Loading...
Searching...
No Matches
SolverBase.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2015 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_SOLVERBASE_H
12#define EIGEN_SOLVERBASE_H
13
14// IWYU pragma: private
15#include "./InternalHeaderCheck.h"
16
17namespace Eigen {
18
19namespace internal {
20
21template <typename Derived>
22struct solve_assertion {
23 template <bool Transpose_, typename Rhs>
24 static void run(const Derived& solver, const Rhs& b) {
25 solver.template _check_solve_assertion<Transpose_>(b);
26 }
27};
28
29template <typename Derived>
30struct solve_assertion<Transpose<Derived>> {
31 using type = Transpose<Derived>;
32
33 template <bool Transpose_, typename Rhs>
34 static void run(const type& transpose, const Rhs& b) {
35 internal::solve_assertion<internal::remove_all_t<Derived>>::template run<true>(transpose.nestedExpression(), b);
36 }
37};
38
39template <typename Scalar, typename Derived>
40struct solve_assertion<CwiseUnaryOp<Eigen::internal::scalar_conjugate_op<Scalar>, const Transpose<Derived>>> {
41 using type = CwiseUnaryOp<Eigen::internal::scalar_conjugate_op<Scalar>, const Transpose<Derived>>;
42
43 template <bool Transpose_, typename Rhs>
44 static void run(const type& adjoint, const Rhs& b) {
45 internal::solve_assertion<internal::remove_all_t<Transpose<Derived>>>::template run<true>(
46 adjoint.nestedExpression(), b);
47 }
48};
49} // end namespace internal
50
72template <typename Derived>
73class SolverBase : public EigenBase<Derived> {
74 public:
75 using Base = EigenBase<Derived>;
76 using Scalar = typename internal::traits<Derived>::Scalar;
77 using CoeffReturnType = Scalar;
78
79 template <typename Derived_>
80 friend struct internal::solve_assertion;
81
82 ComputationInfo info() const {
83 // CRTP static dispatch: Calls the 'info()' method on the derived class.
84 // Derived must implement 'ComputationInfo info() const'.
85 // If not implemented, name lookup falls back to this base method, causing
86 // infinite recursion (detectable by -Winfinite-recursion).
87 return derived().info();
88 }
89
90 enum {
91 RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
92 ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
93 SizeAtCompileTime = (internal::size_of_xpr_at_compile_time<Derived>::value),
94 MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
95 MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
96 MaxSizeAtCompileTime = internal::size_at_compile_time(internal::traits<Derived>::MaxRowsAtCompileTime,
97 internal::traits<Derived>::MaxColsAtCompileTime),
98 IsVectorAtCompileTime =
99 internal::traits<Derived>::MaxRowsAtCompileTime == 1 || internal::traits<Derived>::MaxColsAtCompileTime == 1,
100 NumDimensions = int(MaxSizeAtCompileTime) == 1 ? 0
101 : bool(IsVectorAtCompileTime) ? 1
102 : 2
103 };
104
106 SolverBase() = default;
107
108 using Base::derived;
109
112 template <typename Rhs>
114 internal::solve_assertion<internal::remove_all_t<Derived>>::template run<false>(derived(), b);
115 return Solve<Derived, Rhs>(derived(), b.derived());
116 }
117
119 using ConstTransposeReturnType = Transpose<const Derived>;
127 inline const ConstTransposeReturnType transpose() const { return ConstTransposeReturnType(derived()); }
128
130 using AdjointReturnType =
131 std::conditional_t<NumTraits<Scalar>::IsComplex,
132 CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, const ConstTransposeReturnType>,
133 const ConstTransposeReturnType>;
143 inline const AdjointReturnType adjoint() const { return AdjointReturnType(derived().transpose()); }
144
145 protected:
146 template <bool Transpose_, typename Rhs>
147 void _check_solve_assertion(const Rhs& b) const {
148 EIGEN_ONLY_USED_FOR_DEBUG(b);
149 eigen_assert(derived().m_isInitialized && "Solver is not initialized.");
150 eigen_assert((Transpose_ ? derived().cols() : derived().rows()) == b.rows() &&
151 "SolverBase::solve(): invalid number of rows of the right hand side matrix b");
152 }
153};
154
155namespace internal {
156
157template <typename Derived>
158struct generic_xpr_base<Derived, MatrixXpr, SolverStorage> {
159 using type = SolverBase<Derived>;
160};
161
162} // end namespace internal
163
164} // end namespace Eigen
165
166#endif // EIGEN_SOLVERBASE_H
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition CwiseUnaryOp.h:55
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:53
Pseudo expression representing a solving operation.
Definition Solve.h:63
Solve< Derived, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition SolverBase.h:113
constexpr Derived & derived()
Definition EigenBase.h:50
SolverBase()=default
const ConstTransposeReturnType transpose() const
Definition SolverBase.h:127
const AdjointReturnType adjoint() const
Definition SolverBase.h:143
Expression of the transpose of a matrix.
Definition Transpose.h:57
ComputationInfo
Definition Constants.h:455
Definition EigenBase.h:34
constexpr Index cols() const noexcept
Definition EigenBase.h:62
constexpr Derived & derived()
Definition EigenBase.h:50
constexpr Index rows() const noexcept
Definition EigenBase.h:60