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 namespace Eigen {
14 
15 template<typename Decomposition, typename RhsType, typename GuessType> class SolveWithGuess;
16 
29 namespace internal {
30 
31 
32 template<typename Decomposition, typename RhsType, typename GuessType>
33 struct traits<SolveWithGuess<Decomposition, RhsType, GuessType> >
34  : traits<Solve<Decomposition,RhsType> >
35 {};
36 
37 }
38 
39 
40 template<typename Decomposition, typename RhsType, typename GuessType>
41 class SolveWithGuess : public internal::generic_xpr_base<SolveWithGuess<Decomposition,RhsType,GuessType>, MatrixXpr, typename internal::traits<RhsType>::StorageKind>::type
42 {
43 public:
48 
49  SolveWithGuess(const Decomposition &dec, const RhsType &rhs, const GuessType &guess)
51  {}
52 
54  Index rows() const EIGEN_NOEXCEPT { return m_dec.cols(); }
56  Index cols() const EIGEN_NOEXCEPT { return m_rhs.cols(); }
57 
58  EIGEN_DEVICE_FUNC const Decomposition& dec() const { return m_dec; }
59  EIGEN_DEVICE_FUNC const RhsType& rhs() const { return m_rhs; }
60  EIGEN_DEVICE_FUNC const GuessType& guess() const { return m_guess; }
61 
62 protected:
63  const Decomposition &m_dec;
64  const RhsType &m_rhs;
65  const GuessType &m_guess;
66 
67 private:
68  Scalar coeff(Index row, Index col) const;
69  Scalar coeff(Index i) const;
70 };
71 
72 namespace internal {
73 
74 // Evaluator of SolveWithGuess -> eval into a temporary
75 template<typename Decomposition, typename RhsType, typename GuessType>
76 struct evaluator<SolveWithGuess<Decomposition,RhsType, GuessType> >
77  : public evaluator<typename SolveWithGuess<Decomposition,RhsType,GuessType>::PlainObject>
78 {
82 
83  evaluator(const SolveType& solve)
84  : m_result(solve.rows(), solve.cols())
85  {
86  ::new (static_cast<Base*>(this)) Base(m_result);
87  m_result = solve.guess();
88  solve.dec()._solve_with_guess_impl(solve.rhs(), m_result);
89  }
90 
91 protected:
93 };
94 
95 // Specialization for "dst = dec.solveWithGuess(rhs)"
96 // NOTE we need to specialize it for Dense2Dense to avoid ambiguous specialization error and a Sparse2Sparse specialization must exist somewhere
97 template<typename DstXprType, typename DecType, typename RhsType, typename GuessType, typename Scalar>
98 struct Assignment<DstXprType, SolveWithGuess<DecType,RhsType,GuessType>, internal::assign_op<Scalar,Scalar>, Dense2Dense>
99 {
101  static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &)
102  {
103  Index dstRows = src.rows();
104  Index dstCols = src.cols();
105  if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
106  dst.resize(dstRows, dstCols);
107 
108  dst = src.guess();
109  src.dec()._solve_with_guess_impl(src.rhs(), dst/*, src.guess()*/);
110  }
111 };
112 
113 } // end namespace internal
114 
115 } // end namespace Eigen
116 
117 #endif // EIGEN_SOLVEWITHGUESS_H
Eigen::internal::evaluator::Base
unary_evaluator< T > Base
Definition: CoreEvaluators.h:92
Eigen::MatrixXpr
Definition: Constants.h:522
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::internal::evaluator< SolveWithGuess< Decomposition, RhsType, GuessType > >::SolveType
SolveWithGuess< Decomposition, RhsType, GuessType > SolveType
Definition: SolveWithGuess.h:79
col
m col(1)
Eigen::internal::Assignment< DstXprType, SolveWithGuess< DecType, RhsType, GuessType >, internal::assign_op< Scalar, Scalar >, Dense2Dense >::run
static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op< Scalar, Scalar > &)
Definition: SolveWithGuess.h:101
Eigen::SolveWithGuess::rhs
const EIGEN_DEVICE_FUNC RhsType & rhs() const
Definition: SolveWithGuess.h:59
Eigen::internal::evaluator< SolveWithGuess< Decomposition, RhsType, GuessType > >::PlainObject
SolveType::PlainObject PlainObject
Definition: SolveWithGuess.h:80
EIGEN_CONSTEXPR
#define EIGEN_CONSTEXPR
Definition: Macros.h:787
Eigen::internal::Dense2Dense
Definition: AssignEvaluator.h:814
Eigen::SolveWithGuess::dec
const EIGEN_DEVICE_FUNC Decomposition & dec() const
Definition: SolveWithGuess.h:58
type
Definition: pytypes.h:1525
Eigen::internal::evaluator< SolveWithGuess< Decomposition, RhsType, GuessType > >::evaluator
evaluator(const SolveType &solve)
Definition: SolveWithGuess.h:83
Eigen::SolveWithGuess::cols
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: SolveWithGuess.h:56
Eigen::internal::evaluator< SolveWithGuess< Decomposition, RhsType, GuessType > >::m_result
PlainObject m_result
Definition: SolveWithGuess.h:92
Eigen::SolveWithGuess::Nested
internal::ref_selector< SolveWithGuess >::type Nested
Definition: SolveWithGuess.h:47
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
Eigen::internal::true_type
Definition: Meta.h:96
Eigen::SolveWithGuess::SolveWithGuess
SolveWithGuess(const Decomposition &dec, const RhsType &rhs, const GuessType &guess)
Definition: SolveWithGuess.h:49
Eigen::internal::generic_xpr_base
Definition: XprHelper.h:501
Eigen::SolveWithGuess::rows
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: SolveWithGuess.h:54
Eigen::SolveWithGuess::m_rhs
const RhsType & m_rhs
Definition: SolveWithGuess.h:64
Eigen::internal::evaluator
Definition: CoreEvaluators.h:90
Eigen::internal::evaluator< SolveWithGuess< Decomposition, RhsType, GuessType > >::Base
evaluator< PlainObject > Base
Definition: SolveWithGuess.h:81
Eigen::SolveWithGuess::coeff
Scalar coeff(Index row, Index col) const
Eigen::internal::Assignment< DstXprType, SolveWithGuess< DecType, RhsType, GuessType >, internal::assign_op< Scalar, Scalar >, Dense2Dense >::SrcXprType
SolveWithGuess< DecType, RhsType, GuessType > SrcXprType
Definition: SolveWithGuess.h:100
Eigen::internal::assign_op
Definition: AssignmentFunctors.h:21
Eigen::SolveWithGuess::Scalar
internal::traits< SolveWithGuess >::Scalar Scalar
Definition: SolveWithGuess.h:44
Eigen::SolveWithGuess::Base
internal::generic_xpr_base< SolveWithGuess< Decomposition, RhsType, GuessType >, MatrixXpr, typename internal::traits< RhsType >::StorageKind >::type Base
Definition: SolveWithGuess.h:46
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
Eigen::SolveWithGuess::m_guess
const GuessType & m_guess
Definition: SolveWithGuess.h:65
Eigen::SolveWithGuess::m_dec
const Decomposition & m_dec
Definition: SolveWithGuess.h:63
row
m row(1)
Eigen::SolveWithGuess::PlainObject
internal::traits< SolveWithGuess >::PlainObject PlainObject
Definition: SolveWithGuess.h:45
Eigen::SolveWithGuess::guess
const EIGEN_DEVICE_FUNC GuessType & guess() const
Definition: SolveWithGuess.h:60
Eigen::internal::Assignment
Definition: AssignEvaluator.h:824
Eigen::SolveWithGuess
Pseudo expression representing a solving operation.
Definition: SolveWithGuess.h:15
EIGEN_NOEXCEPT
#define EIGEN_NOEXCEPT
Definition: Macros.h:1418
internal
Definition: BandTriangularSolver.h:13
cols
int cols
Definition: Tutorial_commainit_02.cpp:1
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:04:24