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 #include "./InternalHeaderCheck.h"
14 
15 namespace Eigen {
16 
17 template<typename Decomposition, typename RhsType, typename GuessType> class SolveWithGuess;
18 
31 namespace internal {
32 
33 
34 template<typename Decomposition, typename RhsType, typename GuessType>
35 struct traits<SolveWithGuess<Decomposition, RhsType, GuessType> >
36  : traits<Solve<Decomposition,RhsType> >
37 {};
38 
39 }
40 
41 
42 template<typename Decomposition, typename RhsType, typename GuessType>
43 class SolveWithGuess : public internal::generic_xpr_base<SolveWithGuess<Decomposition,RhsType,GuessType>, MatrixXpr, typename internal::traits<RhsType>::StorageKind>::type
44 {
45 public:
46  typedef typename internal::traits<SolveWithGuess>::Scalar Scalar;
47  typedef typename internal::traits<SolveWithGuess>::PlainObject PlainObject;
48  typedef typename internal::generic_xpr_base<SolveWithGuess<Decomposition,RhsType,GuessType>, MatrixXpr, typename internal::traits<RhsType>::StorageKind>::type Base;
49  typedef typename internal::ref_selector<SolveWithGuess>::type Nested;
50 
51  SolveWithGuess(const Decomposition &dec, const RhsType &rhs, const GuessType &guess)
53  {}
54 
56  Index rows() const EIGEN_NOEXCEPT { return m_dec.cols(); }
58  Index cols() const EIGEN_NOEXCEPT { return m_rhs.cols(); }
59 
60  EIGEN_DEVICE_FUNC const Decomposition& dec() const { return m_dec; }
61  EIGEN_DEVICE_FUNC const RhsType& rhs() const { return m_rhs; }
62  EIGEN_DEVICE_FUNC const GuessType& guess() const { return m_guess; }
63 
64 protected:
65  const Decomposition &m_dec;
66  const RhsType &m_rhs;
67  const GuessType &m_guess;
68 
69 private:
71  Scalar coeff(Index i) const;
72 };
73 
74 namespace internal {
75 
76 // Evaluator of SolveWithGuess -> eval into a temporary
77 template<typename Decomposition, typename RhsType, typename GuessType>
78 struct evaluator<SolveWithGuess<Decomposition,RhsType, GuessType> >
79  : public evaluator<typename SolveWithGuess<Decomposition,RhsType,GuessType>::PlainObject>
80 {
82  typedef typename SolveType::PlainObject PlainObject;
83  typedef evaluator<PlainObject> Base;
84 
85  evaluator(const SolveType& solve)
86  : m_result(solve.rows(), solve.cols())
87  {
88  internal::construct_at<Base>(this, m_result);
89  m_result = solve.guess();
90  solve.dec()._solve_with_guess_impl(solve.rhs(), m_result);
91  }
92 
93 protected:
94  PlainObject m_result;
95 };
96 
97 // Specialization for "dst = dec.solveWithGuess(rhs)"
98 // NOTE we need to specialize it for Dense2Dense to avoid ambiguous specialization error and a Sparse2Sparse specialization must exist somewhere
99 template<typename DstXprType, typename DecType, typename RhsType, typename GuessType, typename Scalar>
100 struct Assignment<DstXprType, SolveWithGuess<DecType,RhsType,GuessType>, internal::assign_op<Scalar,Scalar>, Dense2Dense>
101 {
102  typedef SolveWithGuess<DecType,RhsType,GuessType> SrcXprType;
103  static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &)
104  {
105  Index dstRows = src.rows();
106  Index dstCols = src.cols();
107  if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
108  dst.resize(dstRows, dstCols);
109 
110  dst = src.guess();
111  src.dec()._solve_with_guess_impl(src.rhs(), dst/*, src.guess()*/);
112  }
113 };
114 
115 } // end namespace internal
116 
117 } // end namespace Eigen
118 
119 #endif // EIGEN_SOLVEWITHGUESS_H
RowXpr row(Index i)
This is the const version of row(). *‍/.
ColXpr col(Index i)
This is the const version of col().
#define EIGEN_NOEXCEPT
Definition: Macros.h:1260
#define EIGEN_CONSTEXPR
Definition: Macros.h:747
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
Pseudo expression representing a solving operation.
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
internal::traits< SolveWithGuess >::PlainObject PlainObject
const GuessType & m_guess
Scalar coeff(Index i) const
const GuessType & guess() const
const RhsType & rhs() const
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Scalar coeff(Index row, Index col) const
const RhsType & m_rhs
const Decomposition & dec() const
internal::generic_xpr_base< SolveWithGuess< Decomposition, RhsType, GuessType >, MatrixXpr, typename internal::traits< RhsType >::StorageKind >::type Base
internal::traits< SolveWithGuess >::Scalar Scalar
const Decomposition & m_dec
internal::ref_selector< SolveWithGuess >::type Nested
SolveWithGuess(const Decomposition &dec, const RhsType &rhs, const GuessType &guess)
: InteropHeaders
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82