SparseSolve.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #ifndef EIGEN_SPARSE_SOLVE_H
00026 #define EIGEN_SPARSE_SOLVE_H
00027 
00028 namespace Eigen { 
00029 
00030 namespace internal {
00031 
00032 template<typename _DecompositionType, typename Rhs> struct sparse_solve_retval_base;
00033 template<typename _DecompositionType, typename Rhs> struct sparse_solve_retval;
00034   
00035 template<typename DecompositionType, typename Rhs>
00036 struct traits<sparse_solve_retval_base<DecompositionType, Rhs> >
00037 {
00038   typedef typename DecompositionType::MatrixType MatrixType;
00039   typedef SparseMatrix<typename Rhs::Scalar, Rhs::Options, typename Rhs::Index> ReturnType;
00040 };
00041 
00042 template<typename _DecompositionType, typename Rhs> struct sparse_solve_retval_base
00043  : public ReturnByValue<sparse_solve_retval_base<_DecompositionType, Rhs> >
00044 {
00045   typedef typename remove_all<typename Rhs::Nested>::type RhsNestedCleaned;
00046   typedef _DecompositionType DecompositionType;
00047   typedef ReturnByValue<sparse_solve_retval_base> Base;
00048   typedef typename Base::Index Index;
00049 
00050   sparse_solve_retval_base(const DecompositionType& dec, const Rhs& rhs)
00051     : m_dec(dec), m_rhs(rhs)
00052   {}
00053 
00054   inline Index rows() const { return m_dec.cols(); }
00055   inline Index cols() const { return m_rhs.cols(); }
00056   inline const DecompositionType& dec() const { return m_dec; }
00057   inline const RhsNestedCleaned& rhs() const { return m_rhs; }
00058 
00059   template<typename Dest> inline void evalTo(Dest& dst) const
00060   {
00061     static_cast<const sparse_solve_retval<DecompositionType,Rhs>*>(this)->evalTo(dst);
00062   }
00063 
00064   protected:
00065     const DecompositionType& m_dec;
00066     typename Rhs::Nested m_rhs;
00067 };
00068 
00069 #define EIGEN_MAKE_SPARSE_SOLVE_HELPERS(DecompositionType,Rhs) \
00070   typedef typename DecompositionType::MatrixType MatrixType; \
00071   typedef typename MatrixType::Scalar Scalar; \
00072   typedef typename MatrixType::RealScalar RealScalar; \
00073   typedef typename MatrixType::Index Index; \
00074   typedef Eigen::internal::sparse_solve_retval_base<DecompositionType,Rhs> Base; \
00075   using Base::dec; \
00076   using Base::rhs; \
00077   using Base::rows; \
00078   using Base::cols; \
00079   sparse_solve_retval(const DecompositionType& dec, const Rhs& rhs) \
00080     : Base(dec, rhs) {}
00081 
00082 
00083 
00084 template<typename DecompositionType, typename Rhs, typename Guess> struct solve_retval_with_guess;
00085 
00086 template<typename DecompositionType, typename Rhs, typename Guess>
00087 struct traits<solve_retval_with_guess<DecompositionType, Rhs, Guess> >
00088 {
00089   typedef typename DecompositionType::MatrixType MatrixType;
00090   typedef Matrix<typename Rhs::Scalar,
00091                  MatrixType::ColsAtCompileTime,
00092                  Rhs::ColsAtCompileTime,
00093                  Rhs::PlainObject::Options,
00094                  MatrixType::MaxColsAtCompileTime,
00095                  Rhs::MaxColsAtCompileTime> ReturnType;
00096 };
00097 
00098 template<typename DecompositionType, typename Rhs, typename Guess> struct solve_retval_with_guess
00099  : public ReturnByValue<solve_retval_with_guess<DecompositionType, Rhs, Guess> >
00100 {
00101   typedef typename DecompositionType::Index Index;
00102 
00103   solve_retval_with_guess(const DecompositionType& dec, const Rhs& rhs, const Guess& guess)
00104     : m_dec(dec), m_rhs(rhs), m_guess(guess)
00105   {}
00106 
00107   inline Index rows() const { return m_dec.cols(); }
00108   inline Index cols() const { return m_rhs.cols(); }
00109 
00110   template<typename Dest> inline void evalTo(Dest& dst) const
00111   {
00112     dst = m_guess;
00113     m_dec._solveWithGuess(m_rhs,dst);
00114   }
00115 
00116   protected:
00117     const DecompositionType& m_dec;
00118     const typename Rhs::Nested m_rhs;
00119     const typename Guess::Nested m_guess;
00120 };
00121 
00122 } // namepsace internal
00123 
00124 } // end namespace Eigen
00125 
00126 #endif // EIGEN_SPARSE_SOLVE_H