Eigen::HessenbergDecomposition< MatrixType_ > Class Template Reference

Reduces a square matrix to Hessenberg form by an orthogonal similarity transformation. More...

Public Types

enum  {
  Size ,
  SizeMinusOne ,
  Options ,
  MaxSize ,
  MaxSizeMinusOne
}
 
typedef Matrix< Scalar, SizeMinusOne, 1, Options &~RowMajor, MaxSizeMinusOne, 1 > CoeffVectorType
 Type for vector of Householder coefficients. More...
 
typedef HouseholderSequence< MatrixType, internal::remove_all_t< typename CoeffVectorType::ConjugateReturnType > > HouseholderSequenceType
 Return type of matrixQ() More...
 
typedef Eigen::Index Index
 
typedef internal::HessenbergDecompositionMatrixHReturnType< MatrixTypeMatrixHReturnType
 
typedef MatrixType_ MatrixType
 Synonym for the template parameter MatrixType_. More...
 
typedef MatrixType::Scalar Scalar
 Scalar type for matrices of type MatrixType. More...
 

Public Member Functions

template<typename InputType >
HessenbergDecompositioncompute (const EigenBase< InputType > &matrix)
 Computes Hessenberg decomposition of given matrix. More...
 
template<typename InputType >
 HessenbergDecomposition (const EigenBase< InputType > &matrix)
 Constructor; computes Hessenberg decomposition of given matrix. More...
 
 HessenbergDecomposition (Index size=Size==Dynamic ? 2 :Size)
 Default constructor; the decomposition will be computed later. More...
 
const CoeffVectorTypehouseholderCoefficients () const
 Returns the Householder coefficients. More...
 
MatrixHReturnType matrixH () const
 Constructs the Hessenberg matrix H in the decomposition. More...
 
HouseholderSequenceType matrixQ () const
 Reconstructs the orthogonal matrix Q in the decomposition. More...
 
const MatrixTypepackedMatrix () const
 Returns the internal representation of the decomposition. More...
 

Protected Attributes

CoeffVectorType m_hCoeffs
 
bool m_isInitialized
 
MatrixType m_matrix
 
VectorType m_temp
 

Private Types

typedef NumTraits< Scalar >::Real RealScalar
 
typedef Matrix< Scalar, 1, Size, int(Options)|int(RowMajor), 1, MaxSizeVectorType
 

Static Private Member Functions

static void _compute (MatrixType &matA, CoeffVectorType &hCoeffs, VectorType &temp)
 

Detailed Description

template<typename MatrixType_>
class Eigen::HessenbergDecomposition< MatrixType_ >

Reduces a square matrix to Hessenberg form by an orthogonal similarity transformation.

This is defined in the Eigenvalues module.

Template Parameters
MatrixType_the type of the matrix of which we are computing the Hessenberg decomposition

This class performs an Hessenberg decomposition of a matrix \( A \). In the real case, the Hessenberg decomposition consists of an orthogonal matrix \( Q \) and a Hessenberg matrix \( H \) such that \( A = Q H Q^T \). An orthogonal matrix is a matrix whose inverse equals its transpose ( \( Q^{-1} = Q^T \)). A Hessenberg matrix has zeros below the subdiagonal, so it is almost upper triangular. The Hessenberg decomposition of a complex matrix is \( A = Q H Q^* \) with \( Q \) unitary (that is, \( Q^{-1} = Q^* \)).

Call the function compute() to compute the Hessenberg decomposition of a given matrix. Alternatively, you can use the HessenbergDecomposition(const MatrixType&) constructor which computes the Hessenberg decomposition at construction time. Once the decomposition is computed, you can use the matrixH() and matrixQ() functions to construct the matrices H and Q in the decomposition.

The documentation for matrixH() contains an example of the typical use of this class.

See also
class ComplexSchur, class Tridiagonalization, QR Module

Definition at line 59 of file HessenbergDecomposition.h.

Member Typedef Documentation

◆ CoeffVectorType

template<typename MatrixType_ >
typedef Matrix<Scalar, SizeMinusOne, 1, Options & ~RowMajor, MaxSizeMinusOne, 1> Eigen::HessenbergDecomposition< MatrixType_ >::CoeffVectorType

Type for vector of Householder coefficients.

This is column vector with entries of type Scalar. The length of the vector is one less than the size of MatrixType, if it is a fixed-side type.

Definition at line 84 of file HessenbergDecomposition.h.

◆ HouseholderSequenceType

template<typename MatrixType_ >
typedef HouseholderSequence<MatrixType,internal::remove_all_t<typename CoeffVectorType::ConjugateReturnType> > Eigen::HessenbergDecomposition< MatrixType_ >::HouseholderSequenceType

Return type of matrixQ()

Definition at line 87 of file HessenbergDecomposition.h.

◆ Index

template<typename MatrixType_ >
typedef Eigen::Index Eigen::HessenbergDecomposition< MatrixType_ >::Index
Deprecated:
since Eigen 3.3

Definition at line 76 of file HessenbergDecomposition.h.

◆ MatrixHReturnType

template<typename MatrixType_ >
typedef internal::HessenbergDecompositionMatrixHReturnType<MatrixType> Eigen::HessenbergDecomposition< MatrixType_ >::MatrixHReturnType

Definition at line 89 of file HessenbergDecomposition.h.

◆ MatrixType

template<typename MatrixType_ >
typedef MatrixType_ Eigen::HessenbergDecomposition< MatrixType_ >::MatrixType

Synonym for the template parameter MatrixType_.

Definition at line 64 of file HessenbergDecomposition.h.

◆ RealScalar

template<typename MatrixType_ >
typedef NumTraits<Scalar>::Real Eigen::HessenbergDecomposition< MatrixType_ >::RealScalar
private

Definition at line 273 of file HessenbergDecomposition.h.

◆ Scalar

template<typename MatrixType_ >
typedef MatrixType::Scalar Eigen::HessenbergDecomposition< MatrixType_ >::Scalar

Scalar type for matrices of type MatrixType.

Definition at line 75 of file HessenbergDecomposition.h.

◆ VectorType

template<typename MatrixType_ >
typedef Matrix<Scalar, 1, Size, int(Options) | int(RowMajor), 1, MaxSize> Eigen::HessenbergDecomposition< MatrixType_ >::VectorType
private

Definition at line 272 of file HessenbergDecomposition.h.

Member Enumeration Documentation

◆ anonymous enum

template<typename MatrixType_ >
anonymous enum
Enumerator
Size 
SizeMinusOne 
Options 
MaxSize 
MaxSizeMinusOne 

Definition at line 66 of file HessenbergDecomposition.h.

66  {
67  Size = MatrixType::RowsAtCompileTime,
68  SizeMinusOne = Size == Dynamic ? Dynamic : Size - 1,
69  Options = MatrixType::Options,
70  MaxSize = MatrixType::MaxRowsAtCompileTime,
72  };
const int Dynamic
Definition: Constants.h:24

Constructor & Destructor Documentation

◆ HessenbergDecomposition() [1/2]

template<typename MatrixType_ >
Eigen::HessenbergDecomposition< MatrixType_ >::HessenbergDecomposition ( Index  size = Size==Dynamic ? 2 : Size)
inlineexplicit

Default constructor; the decomposition will be computed later.

Parameters
[in]sizeThe size of the matrix whose Hessenberg decomposition will be computed.

The default constructor is useful in cases in which the user intends to perform decompositions via compute(). The size parameter is only used as a hint. It is not an error to give a wrong size, but it may impair performance.

See also
compute() for an example.

Definition at line 102 of file HessenbergDecomposition.h.

102  : Size)
103  : m_matrix(size,size),
104  m_temp(size),
105  m_isInitialized(false)
106  {
107  if(size>1)
108  m_hCoeffs.resize(size-1);
109  }
constexpr void resize(Index rows, Index cols)

◆ HessenbergDecomposition() [2/2]

template<typename MatrixType_ >
template<typename InputType >
Eigen::HessenbergDecomposition< MatrixType_ >::HessenbergDecomposition ( const EigenBase< InputType > &  matrix)
inlineexplicit

Constructor; computes Hessenberg decomposition of given matrix.

Parameters
[in]matrixSquare matrix whose Hessenberg decomposition is to be computed.

This constructor calls compute() to compute the Hessenberg decomposition.

See also
matrixH() for an example.

Definition at line 121 of file HessenbergDecomposition.h.

122  : m_matrix(matrix.derived()),
123  m_temp(matrix.rows()),
124  m_isInitialized(false)
125  {
126  if(matrix.rows()<2)
127  {
128  m_isInitialized = true;
129  return;
130  }
131  m_hCoeffs.resize(matrix.rows()-1,1);
133  m_isInitialized = true;
134  }
static void _compute(MatrixType &matA, CoeffVectorType &hCoeffs, VectorType &temp)

Member Function Documentation

◆ _compute()

template<typename MatrixType >
void Eigen::HessenbergDecomposition< MatrixType >::_compute ( MatrixType matA,
CoeffVectorType hCoeffs,
VectorType temp 
)
staticprivate

Definition at line 296 of file HessenbergDecomposition.h.

297 {
298  eigen_assert(matA.rows()==matA.cols());
299  Index n = matA.rows();
300  temp.resize(n);
301  for (Index i = 0; i<n-1; ++i)
302  {
303  // let's consider the vector v = i-th column starting at position i+1
304  Index remainingSize = n-i-1;
305  RealScalar beta;
306  Scalar h;
307  matA.col(i).tail(remainingSize).makeHouseholderInPlace(h, beta);
308  matA.col(i).coeffRef(i+1) = beta;
309  hCoeffs.coeffRef(i) = h;
310 
311  // Apply similarity transformation to remaining columns,
312  // i.e., compute A = H A H'
313 
314  // A = H A
315  matA.bottomRightCorner(remainingSize, remainingSize)
316  .applyHouseholderOnTheLeft(matA.col(i).tail(remainingSize-1), h, &temp.coeffRef(0));
317 
318  // A = A H'
319  matA.rightCols(remainingSize)
320  .applyHouseholderOnTheRight(matA.col(i).tail(remainingSize-1), numext::conj(h), &temp.coeffRef(0));
321  }
322 }
int n
#define eigen_assert(x)
Definition: Macros.h:902
MatrixXf matA(2, 2)
MatrixType::Scalar Scalar
Scalar type for matrices of type MatrixType.
NumTraits< Scalar >::Real RealScalar
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_conjugate_op< typename Derived::Scalar >, const Derived > conj(const Eigen::ArrayBase< Derived > &x)

◆ compute()

template<typename MatrixType_ >
template<typename InputType >
HessenbergDecomposition& Eigen::HessenbergDecomposition< MatrixType_ >::compute ( const EigenBase< InputType > &  matrix)
inline

Computes Hessenberg decomposition of given matrix.

Parameters
[in]matrixSquare matrix whose Hessenberg decomposition is to be computed.
Returns
Reference to *this

The Hessenberg decomposition is computed by bringing the columns of the matrix successively in the required form using Householder reflections (see, e.g., Algorithm 7.4.2 in Golub & Van Loan, Matrix Computations). The cost is \( 10n^3/3 \) flops, where \( n \) denotes the size of the given matrix.

This method reuses of the allocated data in the HessenbergDecomposition object.

Example:

HessenbergDecomposition<MatrixXcf> hd(4);
hd.compute(A);
cout << "The matrix H in the decomposition of A is:" << endl << hd.matrixH() << endl;
hd.compute(2*A); // re-use hd to compute and store decomposition of 2A
cout << "The matrix H in the decomposition of 2A is:" << endl << hd.matrixH() << endl;
MatrixXcf A
HessenbergDecomposition< MatrixXcf > hd(4)
static const RandomReturnType Random()
Definition: Random.h:114
Matrix< std::complex< float >, Dynamic, Dynamic > MatrixXcf
Dynamic×Dynamic matrix of type std::complex<float>.
Definition: Matrix.h:503

Output:

The matrix H in the decomposition of A is:
    (-0.211,0.68)     (0.346,0.216)  (-0.688,0.00979)    (0.0451,0.584)
        (-1.45,0) (-0.0574,-0.0123)    (-0.196,0.385)     (0.395,0.389)
            (0,0)          (1.68,0)   (-0.397,-0.552)    (0.156,-0.241)
            (0,0)             (0,0)          (1.56,0)    (0.876,-0.423)
The matrix H in the decomposition of 2A is:
   (-0.422,1.36)    (0.691,0.431)   (-1.38,0.0196)    (0.0902,1.17)
       (-2.91,0) (-0.115,-0.0246)    (-0.392,0.77)    (0.791,0.777)
           (0,0)         (3.36,0)    (-0.795,-1.1)   (0.311,-0.482)
           (0,0)            (0,0)         (3.12,0)    (1.75,-0.846)

Definition at line 154 of file HessenbergDecomposition.h.

155  {
156  m_matrix = matrix.derived();
157  if(matrix.rows()<2)
158  {
159  m_isInitialized = true;
160  return *this;
161  }
162  m_hCoeffs.resize(matrix.rows()-1,1);
164  m_isInitialized = true;
165  return *this;
166  }

◆ householderCoefficients()

template<typename MatrixType_ >
const CoeffVectorType& Eigen::HessenbergDecomposition< MatrixType_ >::householderCoefficients ( ) const
inline

Returns the Householder coefficients.

Returns
a const reference to the vector of Householder coefficients
Precondition
Either the constructor HessenbergDecomposition(const MatrixType&) or the member function compute(const MatrixType&) has been called before to compute the Hessenberg decomposition of a matrix.

The Householder coefficients allow the reconstruction of the matrix \( Q \) in the Hessenberg decomposition from the packed data.

See also
packedMatrix(), Householder module

Definition at line 181 of file HessenbergDecomposition.h.

182  {
183  eigen_assert(m_isInitialized && "HessenbergDecomposition is not initialized.");
184  return m_hCoeffs;
185  }

◆ matrixH()

template<typename MatrixType_ >
MatrixHReturnType Eigen::HessenbergDecomposition< MatrixType_ >::matrixH ( ) const
inline

Constructs the Hessenberg matrix H in the decomposition.

Returns
expression object representing the matrix H
Precondition
Either the constructor HessenbergDecomposition(const MatrixType&) or the member function compute(const MatrixType&) has been called before to compute the Hessenberg decomposition of a matrix.

The object returned by this function constructs the Hessenberg matrix H when it is assigned to a matrix or otherwise evaluated. The matrix H is constructed from the packed matrix as returned by packedMatrix(): The upper part (including the subdiagonal) of the packed matrix contains the matrix H. It may sometimes be better to directly use the packed matrix instead of constructing the matrix H.

Example:

cout << "Here is a random 4x4 matrix:" << endl << A << endl;
HessenbergDecomposition<MatrixXf> hessOfA(A);
MatrixXf H = hessOfA.matrixH();
cout << "The Hessenberg matrix H is:" << endl << H << endl;
MatrixXf Q = hessOfA.matrixQ();
cout << "The orthogonal matrix Q is:" << endl << Q << endl;
cout << "Q H Q^T is:" << endl << Q * H * Q.transpose() << endl;
cout<< "Here is a random 4x4 matrix:"<< endl<< A<< endl;HessenbergDecomposition< MatrixXf > hessOfA(A)
MatrixXf Q
Matrix< float, 4, 4 > Matrix4f
4×4 matrix of type float.
Definition: Matrix.h:501
Matrix< float, Dynamic, Dynamic > MatrixXf
Dynamic×Dynamic matrix of type float.
Definition: Matrix.h:501

Output:

Here is a random 4x4 matrix:
   0.68   0.823  -0.444   -0.27
 -0.211  -0.605   0.108  0.0268
  0.566   -0.33 -0.0452   0.904
  0.597   0.536   0.258   0.832
The Hessenberg matrix H is:
   0.68  -0.691  -0.645   0.235
  0.849   0.836  -0.419   0.794
      0  -0.469  -0.547 -0.0731
      0       0  -0.559  -0.107
The orthogonal matrix Q is:
      1       0       0       0
      0  -0.249  -0.958   0.144
      0   0.667  -0.277  -0.692
      0   0.703 -0.0761   0.707
Q H Q^T is:
   0.68   0.823  -0.444   -0.27
 -0.211  -0.605   0.108  0.0268
  0.566   -0.33 -0.0452   0.904
  0.597   0.536   0.258   0.832
See also
matrixQ(), packedMatrix()

Definition at line 264 of file HessenbergDecomposition.h.

265  {
266  eigen_assert(m_isInitialized && "HessenbergDecomposition is not initialized.");
267  return MatrixHReturnType(*this);
268  }
internal::HessenbergDecompositionMatrixHReturnType< MatrixType > MatrixHReturnType

◆ matrixQ()

template<typename MatrixType_ >
HouseholderSequenceType Eigen::HessenbergDecomposition< MatrixType_ >::matrixQ ( ) const
inline

Reconstructs the orthogonal matrix Q in the decomposition.

Returns
object representing the matrix Q
Precondition
Either the constructor HessenbergDecomposition(const MatrixType&) or the member function compute(const MatrixType&) has been called before to compute the Hessenberg decomposition of a matrix.

This function returns a light-weight object of template class HouseholderSequence. You can either apply it directly to a matrix or you can convert it to a matrix of type MatrixType.

See also
matrixH() for an example, class HouseholderSequence

Definition at line 236 of file HessenbergDecomposition.h.

237  {
238  eigen_assert(m_isInitialized && "HessenbergDecomposition is not initialized.");
239  return HouseholderSequenceType(m_matrix, m_hCoeffs.conjugate())
240  .setLength(m_matrix.rows() - 1)
241  .setShift(1);
242  }
HouseholderSequence< MatrixType, internal::remove_all_t< typename CoeffVectorType::ConjugateReturnType > > HouseholderSequenceType
Return type of matrixQ()

◆ packedMatrix()

template<typename MatrixType_ >
const MatrixType& Eigen::HessenbergDecomposition< MatrixType_ >::packedMatrix ( ) const
inline

Returns the internal representation of the decomposition.

Returns
a const reference to a matrix with the internal representation of the decomposition.
Precondition
Either the constructor HessenbergDecomposition(const MatrixType&) or the member function compute(const MatrixType&) has been called before to compute the Hessenberg decomposition of a matrix.

The returned matrix contains the following information:

  • the upper part and lower sub-diagonal represent the Hessenberg matrix H
  • the rest of the lower part contains the Householder vectors that, combined with Householder coefficients returned by householderCoefficients(), allows to reconstruct the matrix Q as \( Q = H_{N-1} \ldots H_1 H_0 \). Here, the matrices \( H_i \) are the Householder transformations \( H_i = (I - h_i v_i v_i^T) \) where \( h_i \) is the \( i \)th Householder coefficient and \( v_i \) is the Householder vector defined by \( v_i = [ 0, \ldots, 0, 1, M(i+2,i), \ldots, M(N-1,i) ]^T \) with M the matrix returned by this function.

See LAPACK for further details on this packed storage.

Example:

cout << "Here is a random 4x4 matrix:" << endl << A << endl;
HessenbergDecomposition<Matrix4d> hessOfA(A);
Matrix4d pm = hessOfA.packedMatrix();
cout << "The packed matrix M is:" << endl << pm << endl;
cout << "The upper Hessenberg part corresponds to the matrix H, which is:"
<< endl << hessOfA.matrixH() << endl;
Vector3d hc = hessOfA.householderCoefficients();
cout << "The vector of Householder coefficients is:" << endl << hc << endl;
Matrix< double, 4, 4 > Matrix4d
4×4 matrix of type double.
Definition: Matrix.h:502
Matrix< double, 3, 1 > Vector3d
3×1 vector of type double.
Definition: Matrix.h:502

Output:

Here is a random 4x4 matrix:
   0.68   0.823  -0.444   -0.27
 -0.211  -0.605   0.108  0.0268
  0.566   -0.33 -0.0452   0.904
  0.597   0.536   0.258   0.832
The packed matrix M is:
   0.68  -0.691  -0.645   0.235
  0.849   0.836  -0.419   0.794
 -0.534  -0.469  -0.547 -0.0731
 -0.563   0.344  -0.559  -0.107
The upper Hessenberg part corresponds to the matrix H, which is:
   0.68  -0.691  -0.645   0.235
  0.849   0.836  -0.419   0.794
      0  -0.469  -0.547 -0.0731
      0       0  -0.559  -0.107
The vector of Householder coefficients is:
1.25
1.79
   0
See also
householderCoefficients()

Definition at line 216 of file HessenbergDecomposition.h.

217  {
218  eigen_assert(m_isInitialized && "HessenbergDecomposition is not initialized.");
219  return m_matrix;
220  }

Member Data Documentation

◆ m_hCoeffs

template<typename MatrixType_ >
CoeffVectorType Eigen::HessenbergDecomposition< MatrixType_ >::m_hCoeffs
protected

Definition at line 278 of file HessenbergDecomposition.h.

◆ m_isInitialized

template<typename MatrixType_ >
bool Eigen::HessenbergDecomposition< MatrixType_ >::m_isInitialized
protected

Definition at line 280 of file HessenbergDecomposition.h.

◆ m_matrix

template<typename MatrixType_ >
MatrixType Eigen::HessenbergDecomposition< MatrixType_ >::m_matrix
protected

Definition at line 277 of file HessenbergDecomposition.h.

◆ m_temp

template<typename MatrixType_ >
VectorType Eigen::HessenbergDecomposition< MatrixType_ >::m_temp
protected

Definition at line 279 of file HessenbergDecomposition.h.


The documentation for this class was generated from the following file: