HessenbergDecomposition.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) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_HESSENBERGDECOMPOSITION_H
12 #define EIGEN_HESSENBERGDECOMPOSITION_H
13 
14 namespace Eigen {
15 
16 namespace internal {
17 
18 template<typename MatrixType> struct HessenbergDecompositionMatrixHReturnType;
19 template<typename MatrixType>
21 {
23 };
24 
25 }
26 
57 template<typename _MatrixType> class HessenbergDecomposition
58 {
59  public:
60 
62  typedef _MatrixType MatrixType;
63 
64  enum {
65  Size = MatrixType::RowsAtCompileTime,
67  Options = MatrixType::Options,
68  MaxSize = MatrixType::MaxRowsAtCompileTime,
70  };
71 
73  typedef typename MatrixType::Scalar Scalar;
74  typedef Eigen::Index Index;
75 
83 
86 
88 
101  : m_matrix(size,size),
102  m_temp(size),
103  m_isInitialized(false)
104  {
105  if(size>1)
106  m_hCoeffs.resize(size-1);
107  }
108 
118  template<typename InputType>
120  : m_matrix(matrix.derived()),
121  m_temp(matrix.rows()),
122  m_isInitialized(false)
123  {
124  if(matrix.rows()<2)
125  {
126  m_isInitialized = true;
127  return;
128  }
129  m_hCoeffs.resize(matrix.rows()-1,1);
131  m_isInitialized = true;
132  }
133 
151  template<typename InputType>
153  {
154  m_matrix = matrix.derived();
155  if(matrix.rows()<2)
156  {
157  m_isInitialized = true;
158  return *this;
159  }
160  m_hCoeffs.resize(matrix.rows()-1,1);
162  m_isInitialized = true;
163  return *this;
164  }
165 
180  {
181  eigen_assert(m_isInitialized && "HessenbergDecomposition is not initialized.");
182  return m_hCoeffs;
183  }
184 
214  const MatrixType& packedMatrix() const
215  {
216  eigen_assert(m_isInitialized && "HessenbergDecomposition is not initialized.");
217  return m_matrix;
218  }
219 
235  {
236  eigen_assert(m_isInitialized && "HessenbergDecomposition is not initialized.");
237  return HouseholderSequenceType(m_matrix, m_hCoeffs.conjugate())
238  .setLength(m_matrix.rows() - 1)
239  .setShift(1);
240  }
241 
263  {
264  eigen_assert(m_isInitialized && "HessenbergDecomposition is not initialized.");
265  return MatrixHReturnType(*this);
266  }
267 
268  private:
269 
272  static void _compute(MatrixType& matA, CoeffVectorType& hCoeffs, VectorType& temp);
273 
274  protected:
279 };
280 
293 template<typename MatrixType>
295 {
296  eigen_assert(matA.rows()==matA.cols());
297  Index n = matA.rows();
298  temp.resize(n);
299  for (Index i = 0; i<n-1; ++i)
300  {
301  // let's consider the vector v = i-th column starting at position i+1
302  Index remainingSize = n-i-1;
304  Scalar h;
305  matA.col(i).tail(remainingSize).makeHouseholderInPlace(h, beta);
306  matA.col(i).coeffRef(i+1) = beta;
307  hCoeffs.coeffRef(i) = h;
308 
309  // Apply similarity transformation to remaining columns,
310  // i.e., compute A = H A H'
311 
312  // A = H A
313  matA.bottomRightCorner(remainingSize, remainingSize)
314  .applyHouseholderOnTheLeft(matA.col(i).tail(remainingSize-1), h, &temp.coeffRef(0));
315 
316  // A = A H'
317  matA.rightCols(remainingSize)
318  .applyHouseholderOnTheRight(matA.col(i).tail(remainingSize-1), numext::conj(h), &temp.coeffRef(0));
319  }
320 }
321 
322 namespace internal {
323 
339 template<typename MatrixType> struct HessenbergDecompositionMatrixHReturnType
340 : public ReturnByValue<HessenbergDecompositionMatrixHReturnType<MatrixType> >
341 {
342  public:
348 
354  template <typename ResultType>
355  inline void evalTo(ResultType& result) const
356  {
357  result = m_hess.packedMatrix();
358  Index n = result.rows();
359  if (n>2)
360  result.bottomLeftCorner(n-2, n-2).template triangularView<Lower>().setZero();
361  }
362 
363  Index rows() const { return m_hess.packedMatrix().rows(); }
364  Index cols() const { return m_hess.packedMatrix().cols(); }
365 
366  protected:
368 };
369 
370 } // end namespace internal
371 
372 } // end namespace Eigen
373 
374 #endif // EIGEN_HESSENBERGDECOMPOSITION_H
matA
MatrixXf matA(2, 2)
gtsam.examples.DogLegOptimizerExample.int
int
Definition: DogLegOptimizerExample.py:111
Eigen::HessenbergDecomposition::HouseholderSequenceType
HouseholderSequence< MatrixType, typename internal::remove_all< typename CoeffVectorType::ConjugateReturnType >::type > HouseholderSequenceType
Return type of matrixQ()
Definition: HessenbergDecomposition.h:85
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::ReturnByValue
Definition: ReturnByValue.h:50
Eigen::HessenbergDecomposition::compute
HessenbergDecomposition & compute(const EigenBase< InputType > &matrix)
Computes Hessenberg decomposition of given matrix.
Definition: HessenbergDecomposition.h:152
Eigen::HessenbergDecomposition::matrixQ
HouseholderSequenceType matrixQ() const
Reconstructs the orthogonal matrix Q in the decomposition.
Definition: HessenbergDecomposition.h:234
MatrixType
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
Eigen::HessenbergDecomposition::_compute
static void _compute(MatrixType &matA, CoeffVectorType &hCoeffs, VectorType &temp)
Definition: HessenbergDecomposition.h:294
Eigen::HessenbergDecomposition::m_isInitialized
bool m_isInitialized
Definition: HessenbergDecomposition.h:278
Eigen::EigenBase
Definition: EigenBase.h:29
eigen_assert
#define eigen_assert(x)
Definition: Macros.h:1037
Eigen::HessenbergDecomposition::VectorType
Matrix< Scalar, 1, Size, int(Options)|int(RowMajor), 1, MaxSize > VectorType
Definition: HessenbergDecomposition.h:270
Eigen::HessenbergDecomposition::packedMatrix
const MatrixType & packedMatrix() const
Returns the internal representation of the decomposition.
Definition: HessenbergDecomposition.h:214
Eigen::HessenbergDecomposition::Index
Eigen::Index Index
Definition: HessenbergDecomposition.h:74
Eigen::RowMajor
@ RowMajor
Definition: Constants.h:321
Eigen::HessenbergDecomposition::householderCoefficients
const CoeffVectorType & householderCoefficients() const
Returns the Householder coefficients.
Definition: HessenbergDecomposition.h:179
h
const double h
Definition: testSimpleHelicopter.cpp:19
Eigen::PlainObjectBase::resize
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Definition: PlainObjectBase.h:271
Eigen::internal::HessenbergDecompositionMatrixHReturnType::evalTo
void evalTo(ResultType &result) const
Hessenberg matrix in decomposition.
Definition: HessenbergDecomposition.h:355
result
Values result
Definition: OdometryOptimize.cpp:8
beta
double beta(double a, double b)
Definition: beta.c:61
Eigen::HessenbergDecomposition::matrixH
MatrixHReturnType matrixH() const
Constructs the Hessenberg matrix H in the decomposition.
Definition: HessenbergDecomposition.h:262
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
Eigen::internal::HessenbergDecompositionMatrixHReturnType::HessenbergDecompositionMatrixHReturnType
HessenbergDecompositionMatrixHReturnType(const HessenbergDecomposition< MatrixType > &hess)
Constructor.
Definition: HessenbergDecomposition.h:347
size
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
n
int n
Definition: BiCGSTAB_simple.cpp:1
Eigen::HessenbergDecomposition::HessenbergDecomposition
HessenbergDecomposition(Index size=Size==Dynamic ? 2 :Size)
Default constructor; the decomposition will be computed later.
Definition: HessenbergDecomposition.h:100
Eigen::HessenbergDecomposition::MatrixHReturnType
internal::HessenbergDecompositionMatrixHReturnType< MatrixType > MatrixHReturnType
Definition: HessenbergDecomposition.h:87
Eigen::internal::traits< HessenbergDecompositionMatrixHReturnType< MatrixType > >::ReturnType
MatrixType ReturnType
Definition: HessenbergDecomposition.h:22
Eigen::Dynamic
const int Dynamic
Definition: Constants.h:22
Eigen::HessenbergDecomposition::Scalar
MatrixType::Scalar Scalar
Scalar type for matrices of type MatrixType.
Definition: HessenbergDecomposition.h:73
Eigen::HessenbergDecomposition::m_hCoeffs
CoeffVectorType m_hCoeffs
Definition: HessenbergDecomposition.h:276
Eigen::HessenbergDecomposition::Size
@ Size
Definition: HessenbergDecomposition.h:65
Eigen::Matrix::coeffRef
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index rowId, Index colId)
Definition: PlainObjectBase.h:175
Eigen::HessenbergDecomposition::Options
@ Options
Definition: HessenbergDecomposition.h:67
Eigen::internal::HessenbergDecompositionMatrixHReturnType
Expression type for return value of HessenbergDecomposition::matrixH()
Definition: HessenbergDecomposition.h:18
Eigen::HessenbergDecomposition::MatrixType
_MatrixType MatrixType
Synonym for the template parameter _MatrixType.
Definition: HessenbergDecomposition.h:62
Eigen::HessenbergDecomposition::HessenbergDecomposition
HessenbergDecomposition(const EigenBase< InputType > &matrix)
Constructor; computes Hessenberg decomposition of given matrix.
Definition: HessenbergDecomposition.h:119
conj
AnnoyingScalar conj(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:104
Eigen::HessenbergDecomposition::m_temp
VectorType m_temp
Definition: HessenbergDecomposition.h:277
Eigen::HessenbergDecomposition::CoeffVectorType
Matrix< Scalar, SizeMinusOne, 1, Options &~RowMajor, MaxSizeMinusOne, 1 > CoeffVectorType
Type for vector of Householder coefficients.
Definition: HessenbergDecomposition.h:82
matrix
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: gtsam/3rdparty/Eigen/blas/common.h:110
Eigen::HessenbergDecomposition::RealScalar
NumTraits< Scalar >::Real RealScalar
Definition: HessenbergDecomposition.h:271
Eigen::internal::HessenbergDecompositionMatrixHReturnType::cols
Index cols() const
Definition: HessenbergDecomposition.h:364
Eigen::HessenbergDecomposition::SizeMinusOne
@ SizeMinusOne
Definition: HessenbergDecomposition.h:66
Eigen::HessenbergDecomposition::MaxSizeMinusOne
@ MaxSizeMinusOne
Definition: HessenbergDecomposition.h:69
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
Eigen::Matrix< Scalar, SizeMinusOne, 1, Options &~RowMajor, MaxSizeMinusOne, 1 >
internal
Definition: BandTriangularSolver.h:13
Eigen::HessenbergDecomposition::m_matrix
MatrixType m_matrix
Definition: HessenbergDecomposition.h:275
triangularView< Lower >
A triangularView< Lower >().adjoint().solveInPlace(B)
Eigen::HessenbergDecomposition
Reduces a square matrix to Hessenberg form by an orthogonal similarity transformation.
Definition: HessenbergDecomposition.h:57
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:232
Eigen::HessenbergDecomposition::MaxSize
@ MaxSize
Definition: HessenbergDecomposition.h:68
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Eigen::internal::HessenbergDecompositionMatrixHReturnType::m_hess
const HessenbergDecomposition< MatrixType > & m_hess
Definition: HessenbergDecomposition.h:367
Eigen::internal::HessenbergDecompositionMatrixHReturnType::rows
Index rows() const
Definition: HessenbergDecomposition.h:363
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Eigen::HouseholderSequence
Sequence of Householder reflections acting on subspaces with decreasing size.
Definition: ForwardDeclarations.h:282


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:24