11#ifndef EIGEN_HESSENBERGDECOMPOSITION_H
12#define EIGEN_HESSENBERGDECOMPOSITION_H
15#include "./InternalHeaderCheck.h"
21template <
typename MatrixType>
22struct HessenbergDecompositionMatrixHReturnType;
23template <
typename MatrixType>
24struct traits<HessenbergDecompositionMatrixHReturnType<MatrixType>> {
25 typedef MatrixType ReturnType;
60template <
typename MatrixType_>
67 Size = MatrixType::RowsAtCompileTime,
69 Options = internal::traits<MatrixType>::Options,
70 MaxSize = MatrixType::MaxRowsAtCompileTime,
75 typedef typename MatrixType::Scalar
Scalar;
90 typedef internal::HessenbergDecompositionMatrixHReturnType<MatrixType> MatrixHReturnType;
104 : m_matrix(size, size), m_temp(size), m_isInitialized(false) {
105 if (size > 1) m_hCoeffs.
resize(size - 1);
117 template <
typename InputType>
119 : m_matrix(matrix.derived()), m_temp(matrix.rows()), m_isInitialized(false) {
120 if (matrix.
rows() < 2) {
121 m_isInitialized =
true;
125 _compute(m_matrix, m_hCoeffs, m_temp);
126 m_isInitialized =
true;
146 template <
typename InputType>
149 if (matrix.
rows() < 2) {
150 m_isInitialized =
true;
154 _compute(m_matrix, m_hCoeffs, m_temp);
155 m_isInitialized =
true;
173 eigen_assert(m_isInitialized &&
"HessenbergDecomposition is not initialized.");
207 eigen_assert(m_isInitialized &&
"HessenbergDecomposition is not initialized.");
226 eigen_assert(m_isInitialized &&
"HessenbergDecomposition is not initialized.");
251 eigen_assert(m_isInitialized &&
"HessenbergDecomposition is not initialized.");
252 return MatrixHReturnType(*
this);
257 typedef typename NumTraits<Scalar>::Real RealScalar;
264 bool m_isInitialized;
279template <
typename MatrixType>
280void HessenbergDecomposition<MatrixType>::_compute(MatrixType& matA, CoeffVectorType& hCoeffs, VectorType& temp) {
281 eigen_assert(matA.rows() == matA.cols());
282 Index n = matA.rows();
284 for (Index i = 0; i < n - 1; ++i) {
286 Index remainingSize = n - i - 1;
289 matA.col(i).tail(remainingSize).makeHouseholderInPlace(h, beta);
290 matA.col(i).coeffRef(i + 1) = beta;
291 hCoeffs.coeffRef(i) = h;
297 matA.bottomRightCorner(remainingSize, remainingSize)
298 .applyHouseholderOnTheLeft(matA.col(i).tail(remainingSize - 1), h, &temp.coeffRef(0));
301 matA.rightCols(remainingSize)
302 .applyHouseholderOnTheRight(matA.col(i).tail(remainingSize - 1), numext::conj(h), &temp.coeffRef(0));
323template <
typename MatrixType>
324struct HessenbergDecompositionMatrixHReturnType
325 :
public ReturnByValue<HessenbergDecompositionMatrixHReturnType<MatrixType>> {
331 HessenbergDecompositionMatrixHReturnType(
const HessenbergDecomposition<MatrixType>& hess) : m_hess(hess) {}
338 template <
typename ResultType>
339 inline void evalTo(ResultType& result)
const {
340 result = m_hess.packedMatrix();
341 Index n = result.rows();
342 if (n > 2) result.bottomLeftCorner(n - 2, n - 2).template triangularView<Lower>().setZero();
345 Index rows()
const {
return m_hess.packedMatrix().rows(); }
346 Index cols()
const {
return m_hess.packedMatrix().cols(); }
349 const HessenbergDecomposition<MatrixType>& m_hess;
Reduces a square matrix to Hessenberg form by an orthogonal similarity transformation.
Definition HessenbergDecomposition.h:61
Matrix< Scalar, SizeMinusOne, 1, Options &~RowMajor, MaxSizeMinusOne, 1 > CoeffVectorType
Type for vector of Householder coefficients.
Definition HessenbergDecomposition.h:84
HessenbergDecomposition(Index size=Size==Dynamic ? 2 :Size)
Default constructor; the decomposition will be computed later.
Definition HessenbergDecomposition.h:103
MatrixType::Scalar Scalar
Scalar type for matrices of type MatrixType.
Definition HessenbergDecomposition.h:75
HouseholderSequence< MatrixType, internal::remove_all_t< typename CoeffVectorType::ConjugateReturnType > > HouseholderSequenceType
Return type of matrixQ()
Definition HessenbergDecomposition.h:88
HessenbergDecomposition(const EigenBase< InputType > &matrix)
Constructor; computes Hessenberg decomposition of given matrix.
Definition HessenbergDecomposition.h:118
const MatrixType & packedMatrix() const
Returns the internal representation of the decomposition.
Definition HessenbergDecomposition.h:206
MatrixHReturnType matrixH() const
Constructs the Hessenberg matrix H in the decomposition.
Definition HessenbergDecomposition.h:250
HouseholderSequenceType matrixQ() const
Reconstructs the orthogonal matrix Q in the decomposition.
Definition HessenbergDecomposition.h:225
Eigen::Index Index
Definition HessenbergDecomposition.h:76
HessenbergDecomposition & compute(const EigenBase< InputType > &matrix)
Computes Hessenberg decomposition of given matrix.
Definition HessenbergDecomposition.h:147
MatrixType_ MatrixType
Synonym for the template parameter MatrixType_.
Definition HessenbergDecomposition.h:64
const CoeffVectorType & householderCoefficients() const
Returns the Householder coefficients.
Definition HessenbergDecomposition.h:172
Sequence of Householder reflections acting on subspaces with decreasing size.
Definition HouseholderSequence.h:117
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:186
constexpr void resize(Index rows, Index cols)
Definition PlainObjectBase.h:294
@ RowMajor
Definition Constants.h:320
Namespace containing all symbols from the Eigen library.
Definition Core:137
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:83
const int Dynamic
Definition Constants.h:25
Definition EigenBase.h:33
Derived & derived()
Definition EigenBase.h:49
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition EigenBase.h:59