Eigen::Tridiagonalization< MatrixType_ > Class Template Reference

Tridiagonal decomposition of a selfadjoint matrix. More...

Public Types

enum  {
  Size ,
  SizeMinusOne ,
  Options ,
  MaxSize ,
  MaxSizeMinusOne
}
 
typedef Matrix< Scalar, SizeMinusOne, 1, Options &~RowMajor, MaxSizeMinusOne, 1 > CoeffVectorType
 
typedef std::conditional_t< NumTraits< Scalar >::IsComplex, internal::add_const_on_value_type_t< typename Diagonal< const MatrixType >::RealReturnType >, const Diagonal< const MatrixType > > DiagonalReturnType
 
typedef internal::plain_col_type< MatrixType, RealScalar >::type DiagonalType
 
typedef HouseholderSequence< MatrixType, internal::remove_all_t< typename CoeffVectorType::ConjugateReturnType > > HouseholderSequenceType
 Return type of matrixQ() More...
 
typedef Eigen::Index Index
 
typedef internal::TridiagonalizationMatrixTReturnType< MatrixTypeRealViewMatrixTReturnType
 
typedef MatrixType_ MatrixType
 Synonym for the template parameter MatrixType_. More...
 
typedef internal::remove_all_t< typename MatrixType::RealReturnType > MatrixTypeRealView
 
typedef NumTraits< Scalar >::Real RealScalar
 
typedef MatrixType::Scalar Scalar
 
typedef std::conditional_t< NumTraits< Scalar >::IsComplex, internal::add_const_on_value_type_t< typename Diagonal< const MatrixType, -1 >::RealReturnType >, const Diagonal< const MatrixType, -1 > > SubDiagonalReturnType
 
typedef Matrix< RealScalar, SizeMinusOne, 1, Options &~RowMajor, MaxSizeMinusOne, 1 > SubDiagonalType
 

Public Member Functions

template<typename InputType >
Tridiagonalizationcompute (const EigenBase< InputType > &matrix)
 Computes tridiagonal decomposition of given matrix. More...
 
DiagonalReturnType diagonal () const
 Returns the diagonal of the tridiagonal matrix T in the decomposition. More...
 
CoeffVectorType householderCoefficients () const
 Returns the Householder coefficients. More...
 
HouseholderSequenceType matrixQ () const
 Returns the unitary matrix Q in the decomposition. More...
 
MatrixTReturnType matrixT () const
 Returns an expression of the tridiagonal matrix T in the decomposition. More...
 
const MatrixTypepackedMatrix () const
 Returns the internal representation of the decomposition. More...
 
SubDiagonalReturnType subDiagonal () const
 Returns the subdiagonal of the tridiagonal matrix T in the decomposition. More...
 
template<typename InputType >
 Tridiagonalization (const EigenBase< InputType > &matrix)
 Constructor; computes tridiagonal decomposition of given matrix. More...
 
 Tridiagonalization (Index size=Size==Dynamic ? 2 :Size)
 Default constructor. More...
 

Protected Attributes

CoeffVectorType m_hCoeffs
 
bool m_isInitialized
 
MatrixType m_matrix
 

Detailed Description

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

Tridiagonal decomposition of a selfadjoint matrix.

This is defined in the Eigenvalues module.

Template Parameters
MatrixType_the type of the matrix of which we are computing the tridiagonal decomposition; this is expected to be an instantiation of the Matrix class template.

This class performs a tridiagonal decomposition of a selfadjoint matrix \( A \) such that: \( A = Q T Q^* \) where \( Q \) is unitary and \( T \) a real symmetric tridiagonal matrix.

A tridiagonal matrix is a matrix which has nonzero elements only on the main diagonal and the first diagonal below and above it. The Hessenberg decomposition of a selfadjoint matrix is in fact a tridiagonal decomposition. This class is used in SelfAdjointEigenSolver to compute the eigenvalues and eigenvectors of a selfadjoint matrix.

Call the function compute() to compute the tridiagonal decomposition of a given matrix. Alternatively, you can use the Tridiagonalization(const MatrixType&) constructor which computes the tridiagonal Schur decomposition at construction time. Once the decomposition is computed, you can use the matrixQ() and matrixT() functions to retrieve the matrices Q and T in the decomposition.

The documentation of Tridiagonalization(const MatrixType&) contains an example of the typical use of this class.

See also
class HessenbergDecomposition, class SelfAdjointEigenSolver

Definition at line 66 of file Tridiagonalization.h.

Member Typedef Documentation

◆ CoeffVectorType

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

Definition at line 85 of file Tridiagonalization.h.

◆ DiagonalReturnType

template<typename MatrixType_ >
typedef std::conditional_t<NumTraits<Scalar>::IsComplex, internal::add_const_on_value_type_t<typename Diagonal<const MatrixType>::RealReturnType>, const Diagonal<const MatrixType> > Eigen::Tridiagonalization< MatrixType_ >::DiagonalReturnType

Definition at line 94 of file Tridiagonalization.h.

◆ DiagonalType

template<typename MatrixType_ >
typedef internal::plain_col_type<MatrixType, RealScalar>::type Eigen::Tridiagonalization< MatrixType_ >::DiagonalType

Definition at line 86 of file Tridiagonalization.h.

◆ HouseholderSequenceType

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

Return type of matrixQ()

Definition at line 102 of file Tridiagonalization.h.

◆ Index

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

Definition at line 75 of file Tridiagonalization.h.

◆ MatrixTReturnType

template<typename MatrixType_ >
typedef internal::TridiagonalizationMatrixTReturnType<MatrixTypeRealView> Eigen::Tridiagonalization< MatrixType_ >::MatrixTReturnType

Definition at line 89 of file Tridiagonalization.h.

◆ MatrixType

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

Synonym for the template parameter MatrixType_.

Definition at line 71 of file Tridiagonalization.h.

◆ MatrixTypeRealView

template<typename MatrixType_ >
typedef internal::remove_all_t<typename MatrixType::RealReturnType> Eigen::Tridiagonalization< MatrixType_ >::MatrixTypeRealView

Definition at line 88 of file Tridiagonalization.h.

◆ RealScalar

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

Definition at line 74 of file Tridiagonalization.h.

◆ Scalar

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

Definition at line 73 of file Tridiagonalization.h.

◆ SubDiagonalReturnType

template<typename MatrixType_ >
typedef std::conditional_t<NumTraits<Scalar>::IsComplex, internal::add_const_on_value_type_t<typename Diagonal<const MatrixType, -1>::RealReturnType>, const Diagonal<const MatrixType, -1> > Eigen::Tridiagonalization< MatrixType_ >::SubDiagonalReturnType

Definition at line 99 of file Tridiagonalization.h.

◆ SubDiagonalType

template<typename MatrixType_ >
typedef Matrix<RealScalar, SizeMinusOne, 1, Options & ~RowMajor, MaxSizeMinusOne, 1> Eigen::Tridiagonalization< MatrixType_ >::SubDiagonalType

Definition at line 87 of file Tridiagonalization.h.

Member Enumeration Documentation

◆ anonymous enum

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

Definition at line 77 of file Tridiagonalization.h.

77  {
78  Size = MatrixType::RowsAtCompileTime,
79  SizeMinusOne = Size == Dynamic ? Dynamic : (Size > 1 ? Size - 1 : 1),
80  Options = MatrixType::Options,
81  MaxSize = MatrixType::MaxRowsAtCompileTime,
82  MaxSizeMinusOne = MaxSize == Dynamic ? Dynamic : (MaxSize > 1 ? MaxSize - 1 : 1)
83  };
const int Dynamic
Definition: Constants.h:24

Constructor & Destructor Documentation

◆ Tridiagonalization() [1/2]

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

Default constructor.

Parameters
[in]sizePositive integer, size of the matrix whose tridiagonal 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 116 of file Tridiagonalization.h.

116  : Size)
117  : m_matrix(size,size),
118  m_hCoeffs(size > 1 ? size-1 : 1),
119  m_isInitialized(false)
120  {}

◆ Tridiagonalization() [2/2]

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

Constructor; computes tridiagonal decomposition of given matrix.

Parameters
[in]matrixSelfadjoint matrix whose tridiagonal decomposition is to be computed.

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

Example:

MatrixXd A = X + X.transpose();
cout << "Here is a random symmetric 5x5 matrix:" << endl << A << endl << endl;
Tridiagonalization<MatrixXd> triOfA(A);
MatrixXd Q = triOfA.matrixQ();
cout << "The orthogonal matrix Q is:" << endl << Q << endl;
MatrixXd T = triOfA.matrixT();
cout << "The tridiagonal matrix T is:" << endl << T << endl << endl;
cout << "Q * T * Q^T = " << endl << Q * T * Q.transpose() << endl;
MatrixXcf A
MatrixXf Q
cout<< "Here is a random self-adjoint 4x4 matrix:"<< endl<< A<< endl<< endl;Tridiagonalization< MatrixXcd > triOfA(A)
static const RandomReturnType Random()
Definition: Random.h:114
Matrix< double, Dynamic, Dynamic > MatrixXd
Dynamic×Dynamic matrix of type double.
Definition: Matrix.h:502

Output:

Here is a random symmetric 5x5 matrix:
  1.36 -0.816  0.521   1.43 -0.144
-0.816 -0.659  0.794 -0.173 -0.406
 0.521  0.794 -0.541  0.461  0.179
  1.43 -0.173  0.461  -1.43  0.822
-0.144 -0.406  0.179  0.822  -1.37

The orthogonal matrix Q is:
       1        0        0        0        0
       0   -0.471    0.127   -0.671   -0.558
       0    0.301   -0.195    0.437   -0.825
       0    0.825   0.0459   -0.563 -0.00872
       0  -0.0832   -0.971   -0.202   0.0922
The tridiagonal matrix T is:
  1.36   1.73      0      0      0
  1.73   -1.2 -0.966      0      0
     0 -0.966  -1.28  0.214      0
     0      0  0.214  -1.69  0.345
     0      0      0  0.345  0.164

Q * T * Q^T = 
  1.36 -0.816  0.521   1.43 -0.144
-0.816 -0.659  0.794 -0.173 -0.406
 0.521  0.794 -0.541  0.461  0.179
  1.43 -0.173  0.461  -1.43  0.822
-0.144 -0.406  0.179  0.822  -1.37

Definition at line 133 of file Tridiagonalization.h.

134  : m_matrix(matrix.derived()),
135  m_hCoeffs(matrix.cols() > 1 ? matrix.cols()-1 : 1),
136  m_isInitialized(false)
137  {
139  m_isInitialized = true;
140  }
void tridiagonalization_inplace(MatrixType &matA, CoeffVectorType &hCoeffs)

Member Function Documentation

◆ compute()

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

Computes tridiagonal decomposition of given matrix.

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

The tridiagonal decomposition is computed by bringing the columns of the matrix successively in the required form using Householder reflections. The cost is \( 4n^3/3 \) flops, where \( n \) denotes the size of the given matrix.

This method reuses of the allocated data in the Tridiagonalization object, if the size of the matrix does not change.

Example:

Tridiagonalization<MatrixXf> tri;
MatrixXf A = X + X.transpose();
tri.compute(A);
cout << "The matrix T in the tridiagonal decomposition of A is: " << endl;
cout << tri.matrixT() << endl;
tri.compute(2*A); // re-use tri to compute eigenvalues of 2A
cout << "The matrix T in the tridiagonal decomposition of 2A is: " << endl;
cout << tri.matrixT() << endl;
Tridiagonalization< MatrixXf > tri
Matrix< float, Dynamic, Dynamic > MatrixXf
Dynamic×Dynamic matrix of type float.
Definition: Matrix.h:501

Output:

The matrix T in the tridiagonal decomposition of A is: 
  1.36 -0.704      0      0
-0.704 0.0147   1.71      0
     0   1.71  0.856  0.641
     0      0  0.641 -0.506
The matrix T in the tridiagonal decomposition of 2A is: 
  2.72  -1.41      0      0
 -1.41 0.0294   3.43      0
     0   3.43   1.71   1.28
     0      0   1.28  -1.01

Definition at line 160 of file Tridiagonalization.h.

161  {
162  m_matrix = matrix.derived();
163  m_hCoeffs.resize(matrix.rows()-1, 1);
165  m_isInitialized = true;
166  return *this;
167  }
constexpr void resize(Index rows, Index cols)

◆ diagonal()

template<typename MatrixType >
Tridiagonalization< MatrixType >::DiagonalReturnType Eigen::Tridiagonalization< MatrixType >::diagonal

Returns the diagonal of the tridiagonal matrix T in the decomposition.

Returns
expression representing the diagonal of T
Precondition
Either the constructor Tridiagonalization(const MatrixType&) or the member function compute(const MatrixType&) has been called before to compute the tridiagonal decomposition of a matrix.

Example:

MatrixXcd A = X + X.adjoint();
cout << "Here is a random self-adjoint 4x4 matrix:" << endl << A << endl << endl;
Tridiagonalization<MatrixXcd> triOfA(A);
MatrixXd T = triOfA.matrixT();
cout << "The tridiagonal matrix T is:" << endl << T << endl << endl;
cout << "We can also extract the diagonals of T directly ..." << endl;
VectorXd diag = triOfA.diagonal();
cout << "The diagonal is:" << endl << diag << endl;
VectorXd subdiag = triOfA.subDiagonal();
cout << "The subdiagonal is:" << endl << subdiag << endl;
Matrix< double, Dynamic, 1 > VectorXd
Dynamic×1 vector of type double.
Definition: Matrix.h:502
Matrix< std::complex< double >, Dynamic, Dynamic > MatrixXcd
Dynamic×Dynamic matrix of type std::complex<double>.
Definition: Matrix.h:504

Output:

Here is a random self-adjoint 4x4 matrix:
    (-0.422,0)  (0.705,-1.01) (-0.17,-0.552) (0.338,-0.357)
  (0.705,1.01)      (0.515,0) (0.241,-0.446)   (0.05,-1.64)
 (-0.17,0.552)  (0.241,0.446)      (-1.03,0)  (0.0449,1.72)
 (0.338,0.357)    (0.05,1.64) (0.0449,-1.72)       (1.36,0)

The tridiagonal matrix T is:
-0.422  -1.45      0      0
 -1.45   1.01  -1.42      0
     0  -1.42    1.8   -1.2
     0      0   -1.2  -1.96

We can also extract the diagonals of T directly ...
The diagonal is:
-0.422
  1.01
   1.8
 -1.96
The subdiagonal is:
-1.45
-1.42
 -1.2
See also
matrixT(), subDiagonal()

Definition at line 310 of file Tridiagonalization.h.

311 {
312  eigen_assert(m_isInitialized && "Tridiagonalization is not initialized.");
313  return m_matrix.diagonal().real();
314 }
#define eigen_assert(x)
Definition: Macros.h:902

◆ householderCoefficients()

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

Returns the Householder coefficients.

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

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

Example:

Matrix4d A = X + X.transpose();
cout << "Here is a random symmetric 4x4 matrix:" << endl << A << endl;
Tridiagonalization<Matrix4d> triOfA(A);
Vector3d hc = triOfA.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 symmetric 4x4 matrix:
   1.36   0.612   0.122   0.326
  0.612   -1.21  -0.222   0.563
  0.122  -0.222 -0.0904    1.16
  0.326   0.563    1.16    1.66
The vector of Householder coefficients is:
1.87
1.24
   0
See also
packedMatrix(), Householder module

Definition at line 185 of file Tridiagonalization.h.

186  {
187  eigen_assert(m_isInitialized && "Tridiagonalization is not initialized.");
188  return m_hCoeffs;
189  }

◆ matrixQ()

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

Returns the unitary matrix Q in the decomposition.

Returns
object representing the matrix Q
Precondition
Either the constructor Tridiagonalization(const MatrixType&) or the member function compute(const MatrixType&) has been called before to compute the tridiagonal 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
Tridiagonalization(const MatrixType&) for an example, matrixT(), class HouseholderSequence

Definition at line 243 of file Tridiagonalization.h.

244  {
245  eigen_assert(m_isInitialized && "Tridiagonalization is not initialized.");
246  return HouseholderSequenceType(m_matrix, m_hCoeffs.conjugate())
247  .setLength(m_matrix.rows() - 1)
248  .setShift(1);
249  }
HouseholderSequence< MatrixType, internal::remove_all_t< typename CoeffVectorType::ConjugateReturnType > > HouseholderSequenceType
Return type of matrixQ()

◆ matrixT()

template<typename MatrixType_ >
MatrixTReturnType Eigen::Tridiagonalization< MatrixType_ >::matrixT ( ) const
inline

Returns an expression of the tridiagonal matrix T in the decomposition.

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

Currently, this function can be used to extract the matrix T from internal data and copy it to a dense matrix object. In most cases, it may be sufficient to directly use the packed matrix or the vector expressions returned by diagonal() and subDiagonal() instead of creating a new dense copy matrix with this function.

See also
Tridiagonalization(const MatrixType&) for an example, matrixQ(), packedMatrix(), diagonal(), subDiagonal()

Definition at line 268 of file Tridiagonalization.h.

269  {
270  eigen_assert(m_isInitialized && "Tridiagonalization is not initialized.");
271  return MatrixTReturnType(m_matrix.real());
272  }
internal::TridiagonalizationMatrixTReturnType< MatrixTypeRealView > MatrixTReturnType

◆ packedMatrix()

template<typename MatrixType_ >
const MatrixType& Eigen::Tridiagonalization< 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 Tridiagonalization(const MatrixType&) or the member function compute(const MatrixType&) has been called before to compute the tridiagonal decomposition of a matrix.

The returned matrix contains the following information:

  • the strict upper triangular part is equal to the input matrix A.
  • the diagonal and lower sub-diagonal represent the real tridiagonal symmetric matrix T.
  • 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:

Matrix4d A = X + X.transpose();
cout << "Here is a random symmetric 4x4 matrix:" << endl << A << endl;
Tridiagonalization<Matrix4d> triOfA(A);
Matrix4d pm = triOfA.packedMatrix();
cout << "The packed matrix M is:" << endl << pm << endl;
cout << "The diagonal and subdiagonal corresponds to the matrix T, which is:"
<< endl << triOfA.matrixT() << endl;

Output:

Here is a random symmetric 4x4 matrix:
   1.36   0.612   0.122   0.326
  0.612   -1.21  -0.222   0.563
  0.122  -0.222 -0.0904    1.16
  0.326   0.563    1.16    1.66
The packed matrix M is:
  1.36  0.612  0.122  0.326
-0.704 0.0147 -0.222  0.563
0.0925   1.71  0.856   1.16
 0.248  0.785  0.641 -0.506
The diagonal and subdiagonal corresponds to the matrix T, which is:
  1.36 -0.704      0      0
-0.704 0.0147   1.71      0
     0   1.71  0.856  0.641
     0      0  0.641 -0.506
See also
householderCoefficients()

Definition at line 222 of file Tridiagonalization.h.

223  {
224  eigen_assert(m_isInitialized && "Tridiagonalization is not initialized.");
225  return m_matrix;
226  }

◆ subDiagonal()

template<typename MatrixType >
Tridiagonalization< MatrixType >::SubDiagonalReturnType Eigen::Tridiagonalization< MatrixType >::subDiagonal

Returns the subdiagonal of the tridiagonal matrix T in the decomposition.

Returns
expression representing the subdiagonal of T
Precondition
Either the constructor Tridiagonalization(const MatrixType&) or the member function compute(const MatrixType&) has been called before to compute the tridiagonal decomposition of a matrix.
See also
diagonal() for an example, matrixT()

Definition at line 318 of file Tridiagonalization.h.

319 {
320  eigen_assert(m_isInitialized && "Tridiagonalization is not initialized.");
321  return m_matrix.template diagonal<-1>().real();
322 }
DiagonalReturnType diagonal() const
Returns the diagonal of the tridiagonal matrix T in the decomposition.
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_real_op< typename Derived::Scalar >, const Derived > real(const Eigen::ArrayBase< Derived > &x)

Member Data Documentation

◆ m_hCoeffs

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

Definition at line 304 of file Tridiagonalization.h.

◆ m_isInitialized

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

Definition at line 305 of file Tridiagonalization.h.

◆ m_matrix

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

Definition at line 303 of file Tridiagonalization.h.


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