MOAB
4.9.3pre
|
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_SPARSESOLVERBASE_H 00011 #define EIGEN_SPARSESOLVERBASE_H 00012 00013 namespace Eigen { 00014 00015 namespace internal { 00016 00021 template<typename Decomposition, typename Rhs, typename Dest> 00022 void solve_sparse_through_dense_panels(const Decomposition &dec, const Rhs& rhs, Dest &dest) 00023 { 00024 EIGEN_STATIC_ASSERT((Dest::Flags&RowMajorBit)==0,THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES); 00025 typedef typename Dest::Scalar DestScalar; 00026 // we process the sparse rhs per block of NbColsAtOnce columns temporarily stored into a dense matrix. 00027 static const Index NbColsAtOnce = 4; 00028 Index rhsCols = rhs.cols(); 00029 Index size = rhs.rows(); 00030 // the temporary matrices do not need more columns than NbColsAtOnce: 00031 Index tmpCols = (std::min)(rhsCols, NbColsAtOnce); 00032 Eigen::Matrix<DestScalar,Dynamic,Dynamic> tmp(size,tmpCols); 00033 Eigen::Matrix<DestScalar,Dynamic,Dynamic> tmpX(size,tmpCols); 00034 for(Index k=0; k<rhsCols; k+=NbColsAtOnce) 00035 { 00036 Index actualCols = std::min<Index>(rhsCols-k, NbColsAtOnce); 00037 tmp.leftCols(actualCols) = rhs.middleCols(k,actualCols); 00038 tmpX.leftCols(actualCols) = dec.solve(tmp.leftCols(actualCols)); 00039 dest.middleCols(k,actualCols) = tmpX.leftCols(actualCols).sparseView(); 00040 } 00041 } 00042 00043 } // end namespace internal 00044 00052 template<typename Derived> 00053 class SparseSolverBase : internal::noncopyable 00054 { 00055 public: 00056 00058 SparseSolverBase() 00059 : m_isInitialized(false) 00060 {} 00061 00062 ~SparseSolverBase() 00063 {} 00064 00065 Derived& derived() { return *static_cast<Derived*>(this); } 00066 const Derived& derived() const { return *static_cast<const Derived*>(this); } 00067 00072 template<typename Rhs> 00073 inline const Solve<Derived, Rhs> 00074 solve(const MatrixBase<Rhs>& b) const 00075 { 00076 eigen_assert(m_isInitialized && "Solver is not initialized."); 00077 eigen_assert(derived().rows()==b.rows() && "solve(): invalid number of rows of the right hand side matrix b"); 00078 return Solve<Derived, Rhs>(derived(), b.derived()); 00079 } 00080 00085 template<typename Rhs> 00086 inline const Solve<Derived, Rhs> 00087 solve(const SparseMatrixBase<Rhs>& b) const 00088 { 00089 eigen_assert(m_isInitialized && "Solver is not initialized."); 00090 eigen_assert(derived().rows()==b.rows() && "solve(): invalid number of rows of the right hand side matrix b"); 00091 return Solve<Derived, Rhs>(derived(), b.derived()); 00092 } 00093 00094 #ifndef EIGEN_PARSED_BY_DOXYGEN 00095 00096 template<typename Rhs,typename Dest> 00097 void _solve_impl(const SparseMatrixBase<Rhs> &b, SparseMatrixBase<Dest> &dest) const 00098 { 00099 internal::solve_sparse_through_dense_panels(derived(), b.derived(), dest.derived()); 00100 } 00101 #endif // EIGEN_PARSED_BY_DOXYGEN 00102 00103 protected: 00104 00105 mutable bool m_isInitialized; 00106 }; 00107 00108 } // end namespace Eigen 00109 00110 #endif // EIGEN_SPARSESOLVERBASE_H