File indexing completed on 2025-02-22 10:34:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef EIGEN_SPARSESOLVERBASE_H
0011 #define EIGEN_SPARSESOLVERBASE_H
0012
0013 namespace Eigen {
0014
0015 namespace internal {
0016
0017
0018
0019
0020
0021 template<typename Decomposition, typename Rhs, typename Dest>
0022 typename enable_if<Rhs::ColsAtCompileTime!=1 && Dest::ColsAtCompileTime!=1>::type
0023 solve_sparse_through_dense_panels(const Decomposition &dec, const Rhs& rhs, Dest &dest)
0024 {
0025 EIGEN_STATIC_ASSERT((Dest::Flags&RowMajorBit)==0,THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
0026 typedef typename Dest::Scalar DestScalar;
0027
0028 static const Index NbColsAtOnce = 4;
0029 Index rhsCols = rhs.cols();
0030 Index size = rhs.rows();
0031
0032 Index tmpCols = (std::min)(rhsCols, NbColsAtOnce);
0033 Eigen::Matrix<DestScalar,Dynamic,Dynamic> tmp(size,tmpCols);
0034 Eigen::Matrix<DestScalar,Dynamic,Dynamic> tmpX(size,tmpCols);
0035 for(Index k=0; k<rhsCols; k+=NbColsAtOnce)
0036 {
0037 Index actualCols = std::min<Index>(rhsCols-k, NbColsAtOnce);
0038 tmp.leftCols(actualCols) = rhs.middleCols(k,actualCols);
0039 tmpX.leftCols(actualCols) = dec.solve(tmp.leftCols(actualCols));
0040 dest.middleCols(k,actualCols) = tmpX.leftCols(actualCols).sparseView();
0041 }
0042 }
0043
0044
0045 template<typename Decomposition, typename Rhs, typename Dest>
0046 typename enable_if<Rhs::ColsAtCompileTime==1 || Dest::ColsAtCompileTime==1>::type
0047 solve_sparse_through_dense_panels(const Decomposition &dec, const Rhs& rhs, Dest &dest)
0048 {
0049 typedef typename Dest::Scalar DestScalar;
0050 Index size = rhs.rows();
0051 Eigen::Matrix<DestScalar,Dynamic,1> rhs_dense(rhs);
0052 Eigen::Matrix<DestScalar,Dynamic,1> dest_dense(size);
0053 dest_dense = dec.solve(rhs_dense);
0054 dest = dest_dense.sparseView();
0055 }
0056
0057 }
0058
0059
0060
0061
0062
0063
0064
0065
0066 template<typename Derived>
0067 class SparseSolverBase : internal::noncopyable
0068 {
0069 public:
0070
0071
0072 SparseSolverBase()
0073 : m_isInitialized(false)
0074 {}
0075
0076 ~SparseSolverBase()
0077 {}
0078
0079 Derived& derived() { return *static_cast<Derived*>(this); }
0080 const Derived& derived() const { return *static_cast<const Derived*>(this); }
0081
0082
0083
0084
0085
0086 template<typename Rhs>
0087 inline const Solve<Derived, Rhs>
0088 solve(const MatrixBase<Rhs>& b) const
0089 {
0090 eigen_assert(m_isInitialized && "Solver is not initialized.");
0091 eigen_assert(derived().rows()==b.rows() && "solve(): invalid number of rows of the right hand side matrix b");
0092 return Solve<Derived, Rhs>(derived(), b.derived());
0093 }
0094
0095
0096
0097
0098
0099 template<typename Rhs>
0100 inline const Solve<Derived, Rhs>
0101 solve(const SparseMatrixBase<Rhs>& b) const
0102 {
0103 eigen_assert(m_isInitialized && "Solver is not initialized.");
0104 eigen_assert(derived().rows()==b.rows() && "solve(): invalid number of rows of the right hand side matrix b");
0105 return Solve<Derived, Rhs>(derived(), b.derived());
0106 }
0107
0108 #ifndef EIGEN_PARSED_BY_DOXYGEN
0109
0110 template<typename Rhs,typename Dest>
0111 void _solve_impl(const SparseMatrixBase<Rhs> &b, SparseMatrixBase<Dest> &dest) const
0112 {
0113 internal::solve_sparse_through_dense_panels(derived(), b.derived(), dest.derived());
0114 }
0115 #endif
0116
0117 protected:
0118
0119 mutable bool m_isInitialized;
0120 };
0121
0122 }
0123
0124 #endif