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 // IWYU pragma: private
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 template <typename Scalar_>
19 class IncompleteLU : public SparseSolverBase<IncompleteLU<Scalar_> > {
20  protected:
23 
24  typedef Scalar_ Scalar;
26  typedef typename Vector::Index Index;
28 
29  public:
31 
33 
34  template <typename MatrixType>
36  compute(mat);
37  }
38 
39  Index rows() const { return m_lu.rows(); }
40  Index cols() const { return m_lu.cols(); }
41 
42  template <typename MatrixType>
44  m_lu = mat;
45  int size = mat.cols();
46  Vector diag(size);
47  for (int i = 0; i < size; ++i) {
48  typename FactorType::InnerIterator k_it(m_lu, i);
49  for (; k_it && k_it.index() < i; ++k_it) {
50  int k = k_it.index();
51  k_it.valueRef() /= diag(k);
52 
53  typename FactorType::InnerIterator j_it(k_it);
54  typename FactorType::InnerIterator kj_it(m_lu, k);
55  while (kj_it && kj_it.index() <= k) ++kj_it;
56  for (++j_it; j_it;) {
57  if (kj_it.index() == j_it.index()) {
58  j_it.valueRef() -= k_it.value() * kj_it.value();
59  ++j_it;
60  ++kj_it;
61  } else if (kj_it.index() < j_it.index())
62  ++kj_it;
63  else
64  ++j_it;
65  }
66  }
67  if (k_it && k_it.index() == i)
68  diag(i) = k_it.value();
69  else
70  diag(i) = 1;
71  }
72  m_isInitialized = true;
73  return *this;
74  }
75 
76  template <typename Rhs, typename Dest>
77  void _solve_impl(const Rhs& b, Dest& x) const {
78  x = m_lu.template triangularView<UnitLower>().solve(b);
79  x = m_lu.template triangularView<Upper>().solve(x);
80  }
81 
82  protected:
84 };
85 
86 } // end namespace Eigen
87 
88 #endif // EIGEN_INCOMPLETE_LU_H
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Eigen::SparseMatrix< double > mat
Definition: EigenUnitTest.cpp:10
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
Scalar * b
Definition: benchVecAdd.cpp:17
Definition: IncompleteLU.h:19
Scalar_ Scalar
Definition: IncompleteLU.h:24
Matrix< Scalar, Dynamic, Dynamic > MatrixType
Definition: IncompleteLU.h:30
Index rows() const
Definition: IncompleteLU.h:39
SparseSolverBase< IncompleteLU< Scalar_ > > Base
Definition: IncompleteLU.h:21
Matrix< Scalar, Dynamic, 1 > Vector
Definition: IncompleteLU.h:25
FactorType m_lu
Definition: IncompleteLU.h:83
IncompleteLU(const MatrixType &mat)
Definition: IncompleteLU.h:35
void _solve_impl(const Rhs &b, Dest &x) const
Definition: IncompleteLU.h:77
IncompleteLU()
Definition: IncompleteLU.h:32
Vector::Index Index
Definition: IncompleteLU.h:26
SparseMatrix< Scalar, RowMajor > FactorType
Definition: IncompleteLU.h:27
IncompleteLU & compute(const MatrixType &mat)
Definition: IncompleteLU.h:43
Index cols() const
Definition: IncompleteLU.h:40
Index cols() const
Definition: SparseMatrix.h:161
Index rows() const
Definition: SparseMatrix.h:159
Base::InnerIterator InnerIterator
Definition: SparseMatrix.h:138
A base class for sparse solvers.
Definition: SparseSolverBase.h:67
bool m_isInitialized
Definition: SparseSolverBase.h:110
const char const char const char * diag
Definition: level2_impl.h:86
char char char int int * k
Definition: level2_impl.h:374
@ Rhs
Definition: TensorContractionMapper.h:20
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
list x
Definition: plotDoE.py:28