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