MOAB  4.9.3pre
SolveWithGuess.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) 2014 Gael Guennebaud <[email protected]>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 #ifndef EIGEN_SOLVEWITHGUESS_H
00011 #define EIGEN_SOLVEWITHGUESS_H
00012 
00013 namespace Eigen {
00014 
00015 template<typename Decomposition, typename RhsType, typename GuessType> class SolveWithGuess;
00016   
00029 namespace internal {
00030 
00031 
00032 template<typename Decomposition, typename RhsType, typename GuessType>
00033 struct traits<SolveWithGuess<Decomposition, RhsType, GuessType> >
00034   : traits<Solve<Decomposition,RhsType> >
00035 {};
00036 
00037 }
00038 
00039 
00040 template<typename Decomposition, typename RhsType, typename GuessType>
00041 class SolveWithGuess : public internal::generic_xpr_base<SolveWithGuess<Decomposition,RhsType,GuessType>, MatrixXpr, typename internal::traits<RhsType>::StorageKind>::type
00042 {
00043 public:
00044   typedef typename internal::traits<SolveWithGuess>::Scalar Scalar;
00045   typedef typename internal::traits<SolveWithGuess>::PlainObject PlainObject;
00046   typedef typename internal::generic_xpr_base<SolveWithGuess<Decomposition,RhsType,GuessType>, MatrixXpr, typename internal::traits<RhsType>::StorageKind>::type Base;
00047   
00048   SolveWithGuess(const Decomposition &dec, const RhsType &rhs, const GuessType &guess)
00049     : m_dec(dec), m_rhs(rhs), m_guess(guess)
00050   {}
00051   
00052   EIGEN_DEVICE_FUNC Index rows() const { return m_dec.cols(); }
00053   EIGEN_DEVICE_FUNC Index cols() const { return m_rhs.cols(); }
00054 
00055   EIGEN_DEVICE_FUNC const Decomposition& dec()   const { return m_dec; }
00056   EIGEN_DEVICE_FUNC const RhsType&       rhs()   const { return m_rhs; }
00057   EIGEN_DEVICE_FUNC const GuessType&     guess() const { return m_guess; }
00058 
00059 protected:
00060   const Decomposition &m_dec;
00061   const RhsType       &m_rhs;
00062   const GuessType     &m_guess;
00063   
00064 private:
00065   Scalar coeff(Index row, Index col) const;
00066   Scalar coeff(Index i) const;
00067 };
00068 
00069 namespace internal {
00070 
00071 // Evaluator of SolveWithGuess -> eval into a temporary
00072 template<typename Decomposition, typename RhsType, typename GuessType>
00073 struct evaluator<SolveWithGuess<Decomposition,RhsType, GuessType> >
00074   : public evaluator<typename SolveWithGuess<Decomposition,RhsType,GuessType>::PlainObject>
00075 {
00076   typedef SolveWithGuess<Decomposition,RhsType,GuessType> SolveType;
00077   typedef typename SolveType::PlainObject PlainObject;
00078   typedef evaluator<PlainObject> Base;
00079 
00080   evaluator(const SolveType& solve)
00081     : m_result(solve.rows(), solve.cols())
00082   {
00083     ::new (static_cast<Base*>(this)) Base(m_result);
00084     solve.dec()._solve_with_guess_impl(solve.rhs(), m_result, solve().guess());
00085   }
00086   
00087 protected:  
00088   PlainObject m_result;
00089 };
00090 
00091 // Specialization for "dst = dec.solveWithGuess(rhs)"
00092 // NOTE we need to specialize it for Dense2Dense to avoid ambiguous specialization error and a Sparse2Sparse specialization must exist somewhere
00093 template<typename DstXprType, typename DecType, typename RhsType, typename GuessType, typename Scalar>
00094 struct Assignment<DstXprType, SolveWithGuess<DecType,RhsType,GuessType>, internal::assign_op<Scalar>, Dense2Dense, Scalar>
00095 {
00096   typedef SolveWithGuess<DecType,RhsType,GuessType> SrcXprType;
00097   static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar> &)
00098   {
00099     // FIXME shall we resize dst here?
00100     dst = src.guess();
00101     src.dec()._solve_with_guess_impl(src.rhs(), dst/*, src.guess()*/);
00102   }
00103 };
00104 
00105 } // end namepsace internal
00106 
00107 } // end namespace Eigen
00108 
00109 #endif // EIGEN_SOLVEWITHGUESS_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines