Medial Code Documentation
Loading...
Searching...
No Matches
SolveWithGuess.h
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
13namespace Eigen {
14
15template<typename Decomposition, typename RhsType, typename GuessType> class SolveWithGuess;
16
29namespace internal {
30
31
32template<typename Decomposition, typename RhsType, typename GuessType>
34 : traits<Solve<Decomposition,RhsType> >
35{};
36
37}
38
39
40template<typename Decomposition, typename RhsType, typename GuessType>
41class SolveWithGuess : public internal::generic_xpr_base<SolveWithGuess<Decomposition,RhsType,GuessType>, MatrixXpr, typename internal::traits<RhsType>::StorageKind>::type
42{
43public:
44 typedef typename internal::traits<SolveWithGuess>::Scalar Scalar;
45 typedef typename internal::traits<SolveWithGuess>::PlainObject PlainObject;
47
48 SolveWithGuess(const Decomposition &dec, const RhsType &rhs, const GuessType &guess)
49 : m_dec(dec), m_rhs(rhs), m_guess(guess)
50 {}
51
52 EIGEN_DEVICE_FUNC Index rows() const { return m_dec.cols(); }
53 EIGEN_DEVICE_FUNC Index cols() const { return m_rhs.cols(); }
54
55 EIGEN_DEVICE_FUNC const Decomposition& dec() const { return m_dec; }
56 EIGEN_DEVICE_FUNC const RhsType& rhs() const { return m_rhs; }
57 EIGEN_DEVICE_FUNC const GuessType& guess() const { return m_guess; }
58
59protected:
60 const Decomposition &m_dec;
61 const RhsType &m_rhs;
62 const GuessType &m_guess;
63
64private:
65 Scalar coeff(Index row, Index col) const;
66 Scalar coeff(Index i) const;
67};
68
69namespace internal {
70
71// Evaluator of SolveWithGuess -> eval into a temporary
72template<typename Decomposition, typename RhsType, typename GuessType>
74 : public evaluator<typename SolveWithGuess<Decomposition,RhsType,GuessType>::PlainObject>
75{
77 typedef typename SolveType::PlainObject PlainObject;
78 typedef evaluator<PlainObject> Base;
79
80 evaluator(const SolveType& solve)
81 : m_result(solve.rows(), solve.cols())
82 {
83 ::new (static_cast<Base*>(this)) Base(m_result);
84 solve.dec()._solve_with_guess_impl(solve.rhs(), m_result, solve().guess());
85 }
86
88 PlainObject m_result;
89};
90
91// Specialization for "dst = dec.solveWithGuess(rhs)"
92// NOTE we need to specialize it for Dense2Dense to avoid ambiguous specialization error and a Sparse2Sparse specialization must exist somewhere
93template<typename DstXprType, typename DecType, typename RhsType, typename GuessType, typename Scalar>
94struct Assignment<DstXprType, SolveWithGuess<DecType,RhsType,GuessType>, internal::assign_op<Scalar>, Dense2Dense, Scalar>
95{
97 static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar> &)
98 {
99 // FIXME shall we resize dst here?
100 dst = src.guess();
101 src.dec()._solve_with_guess_impl(src.rhs(), dst/*, src.guess()*/);
102 }
103};
104
105} // end namepsace internal
106
107} // end namespace Eigen
108
109#endif // EIGEN_SOLVEWITHGUESS_H
Pseudo expression representing a solving operation.
Definition SolveWithGuess.h:42
Pseudo expression representing a solving operation.
Definition Solve.h:63
The type used to identify a matrix expression.
Definition Constants.h:505
Definition AssignmentFunctors.h:21
Definition XprHelper.h:445
Definition ForwardDeclarations.h:17