SolveWithGuess.h
Go to the documentation of this file.
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_SOLVEWITHGUESS_H
11 #define EIGEN_SOLVEWITHGUESS_H
12 
13 // IWYU pragma: private
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 template <typename Decomposition, typename RhsType, typename GuessType>
19 class SolveWithGuess;
20 
33 namespace internal {
34 
35 template <typename Decomposition, typename RhsType, typename GuessType>
36 struct traits<SolveWithGuess<Decomposition, RhsType, GuessType> > : traits<Solve<Decomposition, RhsType> > {};
37 
38 } // namespace internal
39 
40 template <typename Decomposition, typename RhsType, typename GuessType>
41 class SolveWithGuess : public internal::generic_xpr_base<SolveWithGuess<Decomposition, RhsType, GuessType>, MatrixXpr,
42  typename internal::traits<RhsType>::StorageKind>::type {
43  public:
49 
50  SolveWithGuess(const Decomposition &dec, const RhsType &rhs, const GuessType &guess)
51  : m_dec(dec), m_rhs(rhs), m_guess(guess) {}
52 
55 
56  EIGEN_DEVICE_FUNC const Decomposition &dec() const { return m_dec; }
57  EIGEN_DEVICE_FUNC const RhsType &rhs() const { return m_rhs; }
58  EIGEN_DEVICE_FUNC const GuessType &guess() const { return m_guess; }
59 
60  protected:
61  const Decomposition &m_dec;
62  const RhsType &m_rhs;
63  const GuessType &m_guess;
64 
65  private:
67  Scalar coeff(Index i) const;
68 };
69 
70 namespace internal {
71 
72 // Evaluator of SolveWithGuess -> eval into a temporary
73 template <typename Decomposition, typename RhsType, typename GuessType>
74 struct evaluator<SolveWithGuess<Decomposition, RhsType, GuessType> >
75  : public evaluator<typename SolveWithGuess<Decomposition, RhsType, GuessType>::PlainObject> {
79 
80  evaluator(const SolveType &solve) : m_result(solve.rows(), solve.cols()) {
81  internal::construct_at<Base>(this, m_result);
82  m_result = solve.guess();
83  solve.dec()._solve_with_guess_impl(solve.rhs(), m_result);
84  }
85 
86  protected:
88 };
89 
90 // Specialization for "dst = dec.solveWithGuess(rhs)"
91 // NOTE we need to specialize it for Dense2Dense to avoid ambiguous specialization error and a Sparse2Sparse
92 // specialization must exist somewhere
93 template <typename DstXprType, typename DecType, typename RhsType, typename GuessType, typename Scalar>
94 struct Assignment<DstXprType, SolveWithGuess<DecType, RhsType, GuessType>, internal::assign_op<Scalar, Scalar>,
95  Dense2Dense> {
97  static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar, Scalar> &) {
98  Index dstRows = src.rows();
99  Index dstCols = src.cols();
100  if ((dst.rows() != dstRows) || (dst.cols() != dstCols)) dst.resize(dstRows, dstCols);
101 
102  dst = src.guess();
103  src.dec()._solve_with_guess_impl(src.rhs(), dst /*, src.guess()*/);
104  }
105 };
106 
107 } // end namespace internal
108 
109 } // end namespace Eigen
110 
111 #endif // EIGEN_SOLVEWITHGUESS_H
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_NOEXCEPT
Definition: Macros.h:1267
#define EIGEN_CONSTEXPR
Definition: Macros.h:758
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
m col(1)
m row(1)
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
Pseudo expression representing a solving operation.
Definition: SolveWithGuess.h:19
internal::traits< SolveWithGuess >::PlainObject PlainObject
Definition: SolveWithGuess.h:45
const GuessType & m_guess
Definition: SolveWithGuess.h:63
Scalar coeff(Index i) const
EIGEN_DEVICE_FUNC const Decomposition & dec() const
Definition: SolveWithGuess.h:56
internal::generic_xpr_base< SolveWithGuess< Decomposition, RhsType, GuessType >, MatrixXpr, typename internal::traits< RhsType >::StorageKind >::type Base
Definition: SolveWithGuess.h:47
Scalar coeff(Index row, Index col) const
EIGEN_DEVICE_FUNC const RhsType & rhs() const
Definition: SolveWithGuess.h:57
const RhsType & m_rhs
Definition: SolveWithGuess.h:62
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: SolveWithGuess.h:53
EIGEN_DEVICE_FUNC const GuessType & guess() const
Definition: SolveWithGuess.h:58
internal::traits< SolveWithGuess >::Scalar Scalar
Definition: SolveWithGuess.h:44
const Decomposition & m_dec
Definition: SolveWithGuess.h:61
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: SolveWithGuess.h:54
internal::ref_selector< SolveWithGuess >::type Nested
Definition: SolveWithGuess.h:48
SolveWithGuess(const Decomposition &dec, const RhsType &rhs, const GuessType &guess)
Definition: SolveWithGuess.h:50
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
type
Definition: compute_granudrum_aor.py:141
Definition: Eigen_Colamd.h:49
Update the problem specs before solve
Definition: steady_axisym_advection_diffusion.cc:353
Definition: Constants.h:534
static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op< Scalar, Scalar > &)
Definition: SolveWithGuess.h:97
Definition: AssignEvaluator.h:773
Definition: AssignEvaluator.h:756
Template functor for scalar/packet assignment.
Definition: AssignmentFunctors.h:25
evaluator< PlainObject > Base
Definition: SolveWithGuess.h:78
evaluator(const SolveType &solve)
Definition: SolveWithGuess.h:80
SolveType::PlainObject PlainObject
Definition: SolveWithGuess.h:77
SolveWithGuess< Decomposition, RhsType, GuessType > SolveType
Definition: SolveWithGuess.h:76
Definition: CoreEvaluators.h:104
Definition: XprHelper.h:575
std::conditional_t< bool(traits< T >::Flags &NestByRefBit), T const &, const T > type
Definition: XprHelper.h:507
Definition: ForwardDeclarations.h:21