Eigen  3.4.90 (git rev a4098ac676528a83cfb73d4d26ce1b42ec05f47c)
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
13#include "./InternalHeaderCheck.h"
14
15namespace Eigen {
16
17template<typename Decomposition, typename RhsType, typename GuessType> class SolveWithGuess;
18
31namespace internal {
32
33
34template<typename Decomposition, typename RhsType, typename GuessType>
35struct traits<SolveWithGuess<Decomposition, RhsType, GuessType> >
36 : traits<Solve<Decomposition,RhsType> >
37{};
38
39}
40
41
42template<typename Decomposition, typename RhsType, typename GuessType>
43class SolveWithGuess : public internal::generic_xpr_base<SolveWithGuess<Decomposition,RhsType,GuessType>, MatrixXpr, typename internal::traits<RhsType>::StorageKind>::type
44{
45public:
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)
52 : m_dec(dec), m_rhs(rhs), m_guess(guess)
53 {}
54
55 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
56 Index rows() const EIGEN_NOEXCEPT { return m_dec.cols(); }
57 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
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
64protected:
65 const Decomposition &m_dec;
66 const RhsType &m_rhs;
67 const GuessType &m_guess;
68
69private:
70 Scalar coeff(Index row, Index col) const;
71 Scalar coeff(Index i) const;
72};
73
74namespace internal {
75
76// Evaluator of SolveWithGuess -> eval into a temporary
77template<typename Decomposition, typename RhsType, typename GuessType>
78struct evaluator<SolveWithGuess<Decomposition,RhsType, GuessType> >
79 : public evaluator<typename SolveWithGuess<Decomposition,RhsType,GuessType>::PlainObject>
80{
81 typedef SolveWithGuess<Decomposition,RhsType,GuessType> SolveType;
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 ::new (static_cast<Base*>(this)) Base(m_result);
89 m_result = solve.guess();
90 solve.dec()._solve_with_guess_impl(solve.rhs(), m_result);
91 }
92
93protected:
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
99template<typename DstXprType, typename DecType, typename RhsType, typename GuessType, typename Scalar>
100struct 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
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59