1 | // This file is part of Eigen, a lightweight C++ template library |
---|
2 | // for linear algebra. |
---|
3 | // |
---|
4 | // Copyright (C) 2010 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_SPARSE_SOLVE_H |
---|
11 | #define EIGEN_SPARSE_SOLVE_H |
---|
12 | |
---|
13 | namespace Eigen { |
---|
14 | |
---|
15 | namespace internal { |
---|
16 | |
---|
17 | template<typename _DecompositionType, typename Rhs> struct sparse_solve_retval_base; |
---|
18 | template<typename _DecompositionType, typename Rhs> struct sparse_solve_retval; |
---|
19 | |
---|
20 | template<typename DecompositionType, typename Rhs> |
---|
21 | struct traits<sparse_solve_retval_base<DecompositionType, Rhs> > |
---|
22 | { |
---|
23 | typedef typename DecompositionType::MatrixType MatrixType; |
---|
24 | typedef SparseMatrix<typename Rhs::Scalar, Rhs::Options, typename Rhs::Index> ReturnType; |
---|
25 | }; |
---|
26 | |
---|
27 | template<typename _DecompositionType, typename Rhs> struct sparse_solve_retval_base |
---|
28 | : public ReturnByValue<sparse_solve_retval_base<_DecompositionType, Rhs> > |
---|
29 | { |
---|
30 | typedef typename remove_all<typename Rhs::Nested>::type RhsNestedCleaned; |
---|
31 | typedef _DecompositionType DecompositionType; |
---|
32 | typedef ReturnByValue<sparse_solve_retval_base> Base; |
---|
33 | typedef typename Base::Index Index; |
---|
34 | |
---|
35 | sparse_solve_retval_base(const DecompositionType& dec, const Rhs& rhs) |
---|
36 | : m_dec(dec), m_rhs(rhs) |
---|
37 | {} |
---|
38 | |
---|
39 | inline Index rows() const { return m_dec.cols(); } |
---|
40 | inline Index cols() const { return m_rhs.cols(); } |
---|
41 | inline const DecompositionType& dec() const { return m_dec; } |
---|
42 | inline const RhsNestedCleaned& rhs() const { return m_rhs; } |
---|
43 | |
---|
44 | template<typename Dest> inline void evalTo(Dest& dst) const |
---|
45 | { |
---|
46 | static_cast<const sparse_solve_retval<DecompositionType,Rhs>*>(this)->evalTo(dst); |
---|
47 | } |
---|
48 | |
---|
49 | protected: |
---|
50 | const DecompositionType& m_dec; |
---|
51 | typename Rhs::Nested m_rhs; |
---|
52 | }; |
---|
53 | |
---|
54 | #define EIGEN_MAKE_SPARSE_SOLVE_HELPERS(DecompositionType,Rhs) \ |
---|
55 | typedef typename DecompositionType::MatrixType MatrixType; \ |
---|
56 | typedef typename MatrixType::Scalar Scalar; \ |
---|
57 | typedef typename MatrixType::RealScalar RealScalar; \ |
---|
58 | typedef typename MatrixType::Index Index; \ |
---|
59 | typedef Eigen::internal::sparse_solve_retval_base<DecompositionType,Rhs> Base; \ |
---|
60 | using Base::dec; \ |
---|
61 | using Base::rhs; \ |
---|
62 | using Base::rows; \ |
---|
63 | using Base::cols; \ |
---|
64 | sparse_solve_retval(const DecompositionType& dec, const Rhs& rhs) \ |
---|
65 | : Base(dec, rhs) {} |
---|
66 | |
---|
67 | |
---|
68 | |
---|
69 | template<typename DecompositionType, typename Rhs, typename Guess> struct solve_retval_with_guess; |
---|
70 | |
---|
71 | template<typename DecompositionType, typename Rhs, typename Guess> |
---|
72 | struct traits<solve_retval_with_guess<DecompositionType, Rhs, Guess> > |
---|
73 | { |
---|
74 | typedef typename DecompositionType::MatrixType MatrixType; |
---|
75 | typedef Matrix<typename Rhs::Scalar, |
---|
76 | MatrixType::ColsAtCompileTime, |
---|
77 | Rhs::ColsAtCompileTime, |
---|
78 | Rhs::PlainObject::Options, |
---|
79 | MatrixType::MaxColsAtCompileTime, |
---|
80 | Rhs::MaxColsAtCompileTime> ReturnType; |
---|
81 | }; |
---|
82 | |
---|
83 | template<typename DecompositionType, typename Rhs, typename Guess> struct solve_retval_with_guess |
---|
84 | : public ReturnByValue<solve_retval_with_guess<DecompositionType, Rhs, Guess> > |
---|
85 | { |
---|
86 | typedef typename DecompositionType::Index Index; |
---|
87 | |
---|
88 | solve_retval_with_guess(const DecompositionType& dec, const Rhs& rhs, const Guess& guess) |
---|
89 | : m_dec(dec), m_rhs(rhs), m_guess(guess) |
---|
90 | {} |
---|
91 | |
---|
92 | inline Index rows() const { return m_dec.cols(); } |
---|
93 | inline Index cols() const { return m_rhs.cols(); } |
---|
94 | |
---|
95 | template<typename Dest> inline void evalTo(Dest& dst) const |
---|
96 | { |
---|
97 | dst = m_guess; |
---|
98 | m_dec._solveWithGuess(m_rhs,dst); |
---|
99 | } |
---|
100 | |
---|
101 | protected: |
---|
102 | const DecompositionType& m_dec; |
---|
103 | const typename Rhs::Nested m_rhs; |
---|
104 | const typename Guess::Nested m_guess; |
---|
105 | }; |
---|
106 | |
---|
107 | } // namepsace internal |
---|
108 | |
---|
109 | } // end namespace Eigen |
---|
110 | |
---|
111 | #endif // EIGEN_SPARSE_SOLVE_H |
---|