Eigen  3.3.3
SolveWithGuess.h
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2014 Gael Guennebaud <gael.guennebaud@inria.fr>
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   typedef typename internal::ref_selector<SolveWithGuess>::type Nested;
00048   
00049   SolveWithGuess(const Decomposition &dec, const RhsType &rhs, const GuessType &guess)
00050     : m_dec(dec), m_rhs(rhs), m_guess(guess)
00051   {}
00052   
00053   EIGEN_DEVICE_FUNC Index rows() const { return m_dec.cols(); }
00054   EIGEN_DEVICE_FUNC Index cols() const { return m_rhs.cols(); }
00055 
00056   EIGEN_DEVICE_FUNC const Decomposition& dec()   const { return m_dec; }
00057   EIGEN_DEVICE_FUNC const RhsType&       rhs()   const { return m_rhs; }
00058   EIGEN_DEVICE_FUNC const GuessType&     guess() const { return m_guess; }
00059 
00060 protected:
00061   const Decomposition &m_dec;
00062   const RhsType       &m_rhs;
00063   const GuessType     &m_guess;
00064   
00065 private:
00066   Scalar coeff(Index row, Index col) const;
00067   Scalar coeff(Index i) const;
00068 };
00069 
00070 namespace internal {
00071 
00072 // Evaluator of SolveWithGuess -> eval into a temporary
00073 template<typename Decomposition, typename RhsType, typename GuessType>
00074 struct evaluator<SolveWithGuess<Decomposition,RhsType, GuessType> >
00075   : public evaluator<typename SolveWithGuess<Decomposition,RhsType,GuessType>::PlainObject>
00076 {
00077   typedef SolveWithGuess<Decomposition,RhsType,GuessType> SolveType;
00078   typedef typename SolveType::PlainObject PlainObject;
00079   typedef evaluator<PlainObject> Base;
00080 
00081   evaluator(const SolveType& solve)
00082     : m_result(solve.rows(), solve.cols())
00083   {
00084     ::new (static_cast<Base*>(this)) Base(m_result);
00085     m_result = solve.guess();
00086     solve.dec()._solve_with_guess_impl(solve.rhs(), m_result);
00087   }
00088   
00089 protected:  
00090   PlainObject m_result;
00091 };
00092 
00093 // Specialization for "dst = dec.solveWithGuess(rhs)"
00094 // NOTE we need to specialize it for Dense2Dense to avoid ambiguous specialization error and a Sparse2Sparse specialization must exist somewhere
00095 template<typename DstXprType, typename DecType, typename RhsType, typename GuessType, typename Scalar>
00096 struct Assignment<DstXprType, SolveWithGuess<DecType,RhsType,GuessType>, internal::assign_op<Scalar,Scalar>, Dense2Dense>
00097 {
00098   typedef SolveWithGuess<DecType,RhsType,GuessType> SrcXprType;
00099   static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &)
00100   {
00101     Index dstRows = src.rows();
00102     Index dstCols = src.cols();
00103     if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
00104       dst.resize(dstRows, dstCols);
00105 
00106     dst = src.guess();
00107     src.dec()._solve_with_guess_impl(src.rhs(), dst/*, src.guess()*/);
00108   }
00109 };
00110 
00111 } // end namepsace internal
00112 
00113 } // end namespace Eigen
00114 
00115 #endif // EIGEN_SOLVEWITHGUESS_H
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends