BasicPreconditioners.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-2014 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_BASIC_PRECONDITIONERS_H
11 #define EIGEN_BASIC_PRECONDITIONERS_H
12 
13 namespace Eigen {
14 
35 template <typename _Scalar>
37 {
38  typedef _Scalar Scalar;
40  public:
41  typedef typename Vector::StorageIndex StorageIndex;
42  enum {
45  };
46 
48 
49  template<typename MatType>
50  explicit DiagonalPreconditioner(const MatType& mat) : m_invdiag(mat.cols())
51  {
52  compute(mat);
53  }
54 
55  EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_invdiag.size(); }
56  EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_invdiag.size(); }
57 
58  template<typename MatType>
60  {
61  return *this;
62  }
63 
64  template<typename MatType>
66  {
67  m_invdiag.resize(mat.cols());
68  for(int j=0; j<mat.outerSize(); ++j)
69  {
70  typename MatType::InnerIterator it(mat,j);
71  while(it && it.index()!=j) ++it;
72  if(it && it.index()==j && it.value()!=Scalar(0))
73  m_invdiag(j) = Scalar(1)/it.value();
74  else
75  m_invdiag(j) = Scalar(1);
76  }
77  m_isInitialized = true;
78  return *this;
79  }
80 
81  template<typename MatType>
83  {
84  return factorize(mat);
85  }
86 
88  template<typename Rhs, typename Dest>
89  void _solve_impl(const Rhs& b, Dest& x) const
90  {
91  x = m_invdiag.array() * b.array() ;
92  }
93 
94  template<typename Rhs> inline const Solve<DiagonalPreconditioner, Rhs>
95  solve(const MatrixBase<Rhs>& b) const
96  {
97  eigen_assert(m_isInitialized && "DiagonalPreconditioner is not initialized.");
98  eigen_assert(m_invdiag.size()==b.rows()
99  && "DiagonalPreconditioner::solve(): invalid number of rows of the right hand side matrix b");
100  return Solve<DiagonalPreconditioner, Rhs>(*this, b.derived());
101  }
102 
104 
105  protected:
108 };
109 
127 template <typename _Scalar>
129 {
130  typedef _Scalar Scalar;
133  using Base::m_invdiag;
134  public:
135 
137 
138  template<typename MatType>
139  explicit LeastSquareDiagonalPreconditioner(const MatType& mat) : Base()
140  {
141  compute(mat);
142  }
143 
144  template<typename MatType>
146  {
147  return *this;
148  }
149 
150  template<typename MatType>
152  {
153  // Compute the inverse squared-norm of each column of mat
154  m_invdiag.resize(mat.cols());
155  if(MatType::IsRowMajor)
156  {
157  m_invdiag.setZero();
158  for(Index j=0; j<mat.outerSize(); ++j)
159  {
160  for(typename MatType::InnerIterator it(mat,j); it; ++it)
161  m_invdiag(it.index()) += numext::abs2(it.value());
162  }
163  for(Index j=0; j<mat.cols(); ++j)
166  }
167  else
168  {
169  for(Index j=0; j<mat.outerSize(); ++j)
170  {
171  RealScalar sum = mat.col(j).squaredNorm();
172  if(sum>RealScalar(0))
173  m_invdiag(j) = RealScalar(1)/sum;
174  else
175  m_invdiag(j) = RealScalar(1);
176  }
177  }
178  Base::m_isInitialized = true;
179  return *this;
180  }
181 
182  template<typename MatType>
184  {
185  return factorize(mat);
186  }
187 
189 
190  protected:
191 };
192 
201 {
202  public:
203 
205 
206  template<typename MatrixType>
207  explicit IdentityPreconditioner(const MatrixType& ) {}
208 
209  template<typename MatrixType>
211 
212  template<typename MatrixType>
213  IdentityPreconditioner& factorize(const MatrixType& ) { return *this; }
214 
215  template<typename MatrixType>
216  IdentityPreconditioner& compute(const MatrixType& ) { return *this; }
217 
218  template<typename Rhs>
219  inline const Rhs& solve(const Rhs& b) const { return b; }
220 
222 };
223 
224 } // end namespace Eigen
225 
226 #endif // EIGEN_BASIC_PRECONDITIONERS_H
Eigen::LeastSquareDiagonalPreconditioner::RealScalar
NumTraits< Scalar >::Real RealScalar
Definition: BasicPreconditioners.h:131
Eigen::DiagonalPreconditioner::m_invdiag
Vector m_invdiag
Definition: BasicPreconditioners.h:106
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::DiagonalPreconditioner::Scalar
_Scalar Scalar
Definition: BasicPreconditioners.h:38
Eigen::DiagonalPreconditioner::DiagonalPreconditioner
DiagonalPreconditioner(const MatType &mat)
Definition: BasicPreconditioners.h:50
Eigen::DiagonalPreconditioner::MaxColsAtCompileTime
@ MaxColsAtCompileTime
Definition: BasicPreconditioners.h:44
MatrixType
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
b
Scalar * b
Definition: benchVecAdd.cpp:17
Eigen::LeastSquareDiagonalPreconditioner
Jacobi preconditioner for LeastSquaresConjugateGradient.
Definition: BasicPreconditioners.h:128
eigen_assert
#define eigen_assert(x)
Definition: Macros.h:1037
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
EIGEN_CONSTEXPR
#define EIGEN_CONSTEXPR
Definition: Macros.h:787
Eigen::DiagonalPreconditioner::compute
DiagonalPreconditioner & compute(const MatType &mat)
Definition: BasicPreconditioners.h:82
Eigen::Success
@ Success
Definition: Constants.h:442
real
float real
Definition: datatypes.h:10
Eigen::DiagonalPreconditioner::cols
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: BasicPreconditioners.h:56
Eigen::DiagonalPreconditioner::Vector
Matrix< Scalar, Dynamic, 1 > Vector
Definition: BasicPreconditioners.h:39
mat
MatrixXf mat
Definition: Tutorial_AdvancedInitialization_CommaTemporary.cpp:1
Eigen::DiagonalPreconditioner::factorize
DiagonalPreconditioner & factorize(const MatType &mat)
Definition: BasicPreconditioners.h:65
Eigen::DiagonalPreconditioner::solve
const Solve< DiagonalPreconditioner, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition: BasicPreconditioners.h:95
Eigen::PlainObjectBase::resize
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Definition: PlainObjectBase.h:271
Eigen::DiagonalPreconditioner::StorageIndex
Vector::StorageIndex StorageIndex
Definition: BasicPreconditioners.h:41
Eigen::LeastSquareDiagonalPreconditioner::analyzePattern
LeastSquareDiagonalPreconditioner & analyzePattern(const MatType &)
Definition: BasicPreconditioners.h:145
Eigen::IdentityPreconditioner::IdentityPreconditioner
IdentityPreconditioner()
Definition: BasicPreconditioners.h:204
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
Eigen::IdentityPreconditioner::IdentityPreconditioner
IdentityPreconditioner(const MatrixType &)
Definition: BasicPreconditioners.h:207
Eigen::LeastSquareDiagonalPreconditioner::factorize
LeastSquareDiagonalPreconditioner & factorize(const MatType &mat)
Definition: BasicPreconditioners.h:151
Eigen::Dynamic
const int Dynamic
Definition: Constants.h:22
Eigen::LeastSquareDiagonalPreconditioner::Scalar
_Scalar Scalar
Definition: BasicPreconditioners.h:130
Eigen::IdentityPreconditioner::solve
const Rhs & solve(const Rhs &b) const
Definition: BasicPreconditioners.h:219
Eigen::DiagonalPreconditioner::_solve_impl
void _solve_impl(const Rhs &b, Dest &x) const
Definition: BasicPreconditioners.h:89
Eigen::DiagonalPreconditioner::ColsAtCompileTime
@ ColsAtCompileTime
Definition: BasicPreconditioners.h:43
Eigen::LeastSquareDiagonalPreconditioner::LeastSquareDiagonalPreconditioner
LeastSquareDiagonalPreconditioner(const MatType &mat)
Definition: BasicPreconditioners.h:139
Eigen::LeastSquareDiagonalPreconditioner::compute
LeastSquareDiagonalPreconditioner & compute(const MatType &mat)
Definition: BasicPreconditioners.h:183
Eigen::IdentityPreconditioner
A naive preconditioner which approximates any matrix as the identity matrix.
Definition: BasicPreconditioners.h:200
Eigen::DiagonalPreconditioner::m_isInitialized
bool m_isInitialized
Definition: BasicPreconditioners.h:107
Eigen::DiagonalPreconditioner::analyzePattern
DiagonalPreconditioner & analyzePattern(const MatType &)
Definition: BasicPreconditioners.h:59
Eigen::IdentityPreconditioner::factorize
IdentityPreconditioner & factorize(const MatrixType &)
Definition: BasicPreconditioners.h:213
Eigen::DiagonalPreconditioner::info
ComputationInfo info()
Definition: BasicPreconditioners.h:103
Eigen::DiagonalPreconditioner::DiagonalPreconditioner
DiagonalPreconditioner()
Definition: BasicPreconditioners.h:47
Eigen::numext::abs2
EIGEN_DEVICE_FUNC bool abs2(bool x)
Definition: Eigen/src/Core/MathFunctions.h:1294
Eigen::Solve
Pseudo expression representing a solving operation.
Definition: Solve.h:62
Eigen::LeastSquareDiagonalPreconditioner::Base
DiagonalPreconditioner< _Scalar > Base
Definition: BasicPreconditioners.h:132
Eigen::internal::Rhs
@ Rhs
Definition: TensorContractionMapper.h:18
Eigen::IdentityPreconditioner::compute
IdentityPreconditioner & compute(const MatrixType &)
Definition: BasicPreconditioners.h:216
Eigen::LeastSquareDiagonalPreconditioner::info
ComputationInfo info()
Definition: BasicPreconditioners.h:188
Eigen::DiagonalPreconditioner
A preconditioner based on the digonal entries.
Definition: BasicPreconditioners.h:36
Eigen::DiagonalPreconditioner::rows
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: BasicPreconditioners.h:55
Eigen::Matrix< Scalar, Dynamic, 1 >
EIGEN_NOEXCEPT
#define EIGEN_NOEXCEPT
Definition: Macros.h:1418
Eigen::PlainObjectBase::setZero
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:562
Eigen::MatrixBase
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Eigen::LeastSquareDiagonalPreconditioner::LeastSquareDiagonalPreconditioner
LeastSquareDiagonalPreconditioner()
Definition: BasicPreconditioners.h:136
Eigen::ComputationInfo
ComputationInfo
Definition: Constants.h:440
Eigen::IdentityPreconditioner::analyzePattern
IdentityPreconditioner & analyzePattern(const MatrixType &)
Definition: BasicPreconditioners.h:210
Eigen::IdentityPreconditioner::info
ComputationInfo info()
Definition: BasicPreconditioners.h:221
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:232
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:10