IncompleteLU.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2011 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_INCOMPLETE_LU_H
11 #define EIGEN_INCOMPLETE_LU_H
12 
13 #include "./InternalHeaderCheck.h"
14 
15 namespace Eigen {
16 
17 template <typename Scalar_>
18 class IncompleteLU : public SparseSolverBase<IncompleteLU<Scalar_> >
19 {
20  protected:
23 
24  typedef Scalar_ Scalar;
26  typedef typename Vector::Index Index;
28 
29  public:
31 
33 
34  template<typename MatrixType>
36  {
37  compute(mat);
38  }
39 
40  Index rows() const { return m_lu.rows(); }
41  Index cols() const { return m_lu.cols(); }
42 
43  template<typename MatrixType>
45  {
46  m_lu = mat;
47  int size = mat.cols();
48  Vector diag(size);
49  for(int i=0; i<size; ++i)
50  {
51  typename FactorType::InnerIterator k_it(m_lu,i);
52  for(; k_it && k_it.index()<i; ++k_it)
53  {
54  int k = k_it.index();
55  k_it.valueRef() /= diag(k);
56 
57  typename FactorType::InnerIterator j_it(k_it);
58  typename FactorType::InnerIterator kj_it(m_lu, k);
59  while(kj_it && kj_it.index()<=k) ++kj_it;
60  for(++j_it; j_it; )
61  {
62  if(kj_it.index()==j_it.index())
63  {
64  j_it.valueRef() -= k_it.value() * kj_it.value();
65  ++j_it;
66  ++kj_it;
67  }
68  else if(kj_it.index()<j_it.index()) ++kj_it;
69  else ++j_it;
70  }
71  }
72  if(k_it && k_it.index()==i) diag(i) = k_it.value();
73  else diag(i) = 1;
74  }
75  m_isInitialized = true;
76  return *this;
77  }
78 
79  template<typename Rhs, typename Dest>
80  void _solve_impl(const Rhs& b, Dest& x) const
81  {
82  x = m_lu.template triangularView<UnitLower>().solve(b);
83  x = m_lu.template triangularView<Upper>().solve(x);
84  }
85 
86  protected:
88 };
89 
90 } // end namespace Eigen
91 
92 #endif // EIGEN_INCOMPLETE_LU_H
int i
MatrixXf mat
Index rows() const
Definition: IncompleteLU.h:40
SparseSolverBase< IncompleteLU< Scalar_ > > Base
Definition: IncompleteLU.h:21
SparseMatrix< Scalar, RowMajor > FactorType
Definition: IncompleteLU.h:27
IncompleteLU(const MatrixType &mat)
Definition: IncompleteLU.h:35
void _solve_impl(const Rhs &b, Dest &x) const
Definition: IncompleteLU.h:80
Matrix< Scalar, Dynamic, Dynamic > MatrixType
Definition: IncompleteLU.h:30
Vector::Index Index
Definition: IncompleteLU.h:26
IncompleteLU & compute(const MatrixType &mat)
Definition: IncompleteLU.h:44
Index cols() const
Definition: IncompleteLU.h:41
Matrix< Scalar, Dynamic, 1 > Vector
Definition: IncompleteLU.h:25
Index cols() const
Index rows() const
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
SparseMat::Index size