10 #ifndef EIGEN_SPARSETRIANGULARSOLVER_H 11 #define EIGEN_SPARSETRIANGULARSOLVER_H 17 template<
typename Lhs,
typename Rhs,
int Mode,
18 int UpLo = (Mode &
Lower)
23 int StorageOrder = int(traits<Lhs>::Flags) &
RowMajorBit>
27 template<
typename Lhs,
typename Rhs,
int Mode>
31 static void run(
const Lhs& lhs, Rhs& other)
35 for(
int i=0; i<lhs.rows(); ++i)
37 Scalar tmp = other.coeff(i,
col);
40 for(
typename Lhs::InnerIterator it(lhs, i); it; ++it)
43 lastIndex = it.index();
46 tmp -= lastVal * other.coeff(lastIndex,
col);
49 other.coeffRef(i,
col) = tmp;
53 other.coeffRef(i,
col) = tmp/lastVal;
61 template<
typename Lhs,
typename Rhs,
int Mode>
65 static void run(
const Lhs& lhs, Rhs& other)
69 for(
int i=lhs.rows()-1 ; i>=0 ; --i)
71 Scalar tmp = other.coeff(i,
col);
73 typename Lhs::InnerIterator it(lhs, i);
74 while(it && it.index()<i)
82 else if (it && it.index() == i)
86 tmp -= it.value() * other.coeff(it.index(),
col);
90 other.coeffRef(i,
col) = tmp;
92 other.coeffRef(i,
col) = tmp/l_ii;
99 template<
typename Lhs,
typename Rhs,
int Mode>
103 static void run(
const Lhs& lhs, Rhs& other)
105 for(
int col=0 ;
col<other.cols() ; ++
col)
107 for(
int i=0; i<lhs.cols(); ++i)
109 Scalar& tmp = other.coeffRef(i,
col);
112 typename Lhs::InnerIterator it(lhs, i);
113 while(it && it.index()<i)
120 if (it && it.index()==i)
123 other.coeffRef(it.index(),
col) -= tmp * it.value();
131 template<
typename Lhs,
typename Rhs,
int Mode>
135 static void run(
const Lhs& lhs, Rhs& other)
137 for(
int col=0 ;
col<other.cols() ; ++
col)
139 for(
int i=lhs.cols()-1; i>=0; --i)
141 Scalar& tmp = other.coeffRef(i,
col);
147 typename Lhs::ReverseInnerIterator it(lhs, i);
148 while(it && it.index()!=i)
151 other.coeffRef(i,
col) /= it.value();
153 typename Lhs::InnerIterator it(lhs, i);
154 for(; it && it.index()<i; ++it)
155 other.coeffRef(it.index(),
col) -= tmp * it.value();
164 template<
typename ExpressionType,
int Mode>
165 template<
typename OtherDerived>
168 eigen_assert(m_matrix.cols() == m_matrix.rows() && m_matrix.cols() == other.rows());
175 OtherCopy otherCopy(other.derived());
183 template<
typename ExpressionType,
int Mode>
184 template<
typename OtherDerived>
197 template<
typename Lhs,
typename Rhs,
int Mode,
198 int UpLo = (Mode &
Lower)
203 int StorageOrder = int(Lhs::Flags) & (
RowMajorBit)>
207 template<
typename Lhs,
typename Rhs,
int Mode,
int UpLo>
213 static void run(
const Lhs& lhs, Rhs& other)
215 const bool IsLower = (UpLo==
Lower);
219 Rhs res(other.rows(), other.cols());
220 res.reserve(other.nonZeros());
222 for(
int col=0 ;
col<other.cols() ; ++
col)
225 tempVector.init(.99);
226 tempVector.setZero();
227 tempVector.restart();
228 for (
typename Rhs::InnerIterator rhsIt(other,
col); rhsIt; ++rhsIt)
230 tempVector.coeffRef(rhsIt.index()) = rhsIt.value();
233 for(
int i=IsLower?0:lhs.cols()-1;
234 IsLower?i<lhs.cols():i>=0;
237 tempVector.restart();
238 Scalar& ci = tempVector.coeffRef(i);
242 typename Lhs::InnerIterator it(lhs, i);
251 ci /= lhs.coeff(i,i);
253 tempVector.restart();
259 tempVector.coeffRef(it.index()) -= ci * it.value();
263 for(; it && it.index()<i; ++it)
264 tempVector.coeffRef(it.index()) -= ci * it.value();
278 res.insert(it.index(),
col) = it.value();
283 other = res.markAsRValue();
289 template<
typename ExpressionType,
int Mode>
290 template<
typename OtherDerived>
293 eigen_assert(m_matrix.cols() == m_matrix.rows() && m_matrix.cols() == other.
rows());
308 #ifdef EIGEN2_SUPPORT 313 template<
typename Derived>
314 template<
typename OtherDerived>
317 this->
template triangular<Flags&(Upper|Lower)>().solveInPlace(other);
321 template<
typename Derived>
322 template<
typename OtherDerived>
327 derived().solveTriangularInPlace(res);
330 #endif // EIGEN2_SUPPORT 334 #endif // EIGEN_SPARSETRIANGULARSOLVER_H
void setBounds(Index start, Index end)
static void run(const Lhs &lhs, Rhs &other)
iterative scaling algorithm to equilibrate rows and column norms in matrices
const unsigned int RowMajorBit
internal::plain_matrix_type_column_major< OtherDerived >::type solve(const MatrixBase< OtherDerived > &other) const
static void run(const Lhs &lhs, Rhs &other)
Base class of any sparse matrices or sparse expressions.
static void run(const Lhs &lhs, Rhs &other)
static void run(const Lhs &lhs, Rhs &other)
const Derived & derived() const
void solveInPlace(MatrixBase< OtherDerived > &other) const
promote_index_type< typename traits< Lhs >::Index, typename traits< Rhs >::Index >::type Index
The matrix class, also used for vectors and row-vectors.
Base class for all dense matrices, vectors, and expressions.
static void run(const Lhs &lhs, Rhs &other)