11#ifndef EIGEN_HESSENBERGDECOMPOSITION_H
12#define EIGEN_HESSENBERGDECOMPOSITION_H
18template<
typename MatrixType>
struct HessenbergDecompositionMatrixHReturnType;
19template<
typename MatrixType>
20struct traits<HessenbergDecompositionMatrixHReturnType<MatrixType> >
22 typedef MatrixType ReturnType;
65 Size = MatrixType::RowsAtCompileTime,
66 SizeMinusOne = Size == Dynamic ? Dynamic : Size - 1,
67 Options = MatrixType::Options,
68 MaxSize = MatrixType::MaxRowsAtCompileTime,
69 MaxSizeMinusOne = MaxSize == Dynamic ? Dynamic : MaxSize - 1
73 typedef typename MatrixType::Scalar
Scalar;
74 typedef typename MatrixType::Index Index;
87 typedef internal::HessenbergDecompositionMatrixHReturnType<MatrixType> MatrixHReturnType;
101 : m_matrix(size,size),
103 m_isInitialized(false)
106 m_hCoeffs.resize(size-1);
120 m_temp(matrix.rows()),
121 m_isInitialized(false)
125 m_isInitialized = true;
128 m_hCoeffs.resize(matrix.rows()-1,1);
129 _compute(m_matrix, m_hCoeffs, m_temp);
130 m_isInitialized =
true;
155 m_isInitialized =
true;
158 m_hCoeffs.resize(matrix.rows()-1,1);
159 _compute(m_matrix, m_hCoeffs, m_temp);
160 m_isInitialized =
true;
179 eigen_assert(m_isInitialized &&
"HessenbergDecomposition is not initialized.");
214 eigen_assert(m_isInitialized &&
"HessenbergDecomposition is not initialized.");
234 eigen_assert(m_isInitialized &&
"HessenbergDecomposition is not initialized.");
262 eigen_assert(m_isInitialized &&
"HessenbergDecomposition is not initialized.");
263 return MatrixHReturnType(*
this);
269 typedef typename NumTraits<Scalar>::Real RealScalar;
276 bool m_isInitialized;
291template<
typename MatrixType>
292void HessenbergDecomposition<MatrixType>::_compute(MatrixType& matA, CoeffVectorType& hCoeffs, VectorType& temp)
294 assert(matA.rows()==matA.cols());
295 Index n = matA.rows();
297 for (Index i = 0; i<n-1; ++i)
300 Index remainingSize = n-i-1;
303 matA.col(i).tail(remainingSize).makeHouseholderInPlace(h, beta);
304 matA.col(i).coeffRef(i+1) = beta;
305 hCoeffs.coeffRef(i) = h;
311 matA.bottomRightCorner(remainingSize, remainingSize)
312 .applyHouseholderOnTheLeft(matA.col(i).tail(remainingSize-1), h, &temp.coeffRef(0));
315 matA.rightCols(remainingSize)
316 .applyHouseholderOnTheRight(matA.col(i).tail(remainingSize-1).conjugate(), internal::conj(h), &temp.coeffRef(0));
337template<
typename MatrixType>
struct HessenbergDecompositionMatrixHReturnType
338:
public ReturnByValue<HessenbergDecompositionMatrixHReturnType<MatrixType> >
340 typedef typename MatrixType::Index Index;
346 HessenbergDecompositionMatrixHReturnType(
const HessenbergDecomposition<MatrixType>& hess) : m_hess(hess) { }
353 template <
typename ResultType>
354 inline void evalTo(ResultType& result)
const
356 result = m_hess.packedMatrix();
357 Index n = result.rows();
359 result.bottomLeftCorner(n-2, n-2).template triangularView<Lower>().setZero();
362 Index rows()
const {
return m_hess.packedMatrix().rows(); }
363 Index cols()
const {
return m_hess.packedMatrix().cols(); }
366 const HessenbergDecomposition<MatrixType>& m_hess;
const CoeffVectorType & householderCoefficients() const
Returns the Householder coefficients.
Definition HessenbergDecomposition.h:177
MatrixHReturnType matrixH() const
Constructs the Hessenberg matrix H in the decomposition.
Definition HessenbergDecomposition.h:260
const MatrixType & packedMatrix() const
Returns the internal representation of the decomposition.
Definition HessenbergDecomposition.h:212
Matrix< Scalar, SizeMinusOne, 1, Options &~RowMajor, MaxSizeMinusOne, 1 > CoeffVectorType
Type for vector of Householder coefficients.
Definition HessenbergDecomposition.h:82
HessenbergDecomposition(Index size=Size==Dynamic ? 2 :Size)
Default constructor; the decomposition will be computed later.
Definition HessenbergDecomposition.h:100
MatrixType::Scalar Scalar
Scalar type for matrices of type MatrixType.
Definition HessenbergDecomposition.h:73
HessenbergDecomposition & compute(const MatrixType &matrix)
Computes Hessenberg decomposition of given matrix.
Definition HessenbergDecomposition.h:150
HessenbergDecomposition(const MatrixType &matrix)
Constructor; computes Hessenberg decomposition of given matrix.
Definition HessenbergDecomposition.h:118
HouseholderSequence< MatrixType, CoeffVectorType >::ConjugateReturnType HouseholderSequenceType
Return type of matrixQ()
Definition HessenbergDecomposition.h:85
_MatrixType MatrixType
Synonym for the template parameter _MatrixType.
Definition HessenbergDecomposition.h:62
HouseholderSequenceType matrixQ() const
Reconstructs the orthogonal matrix Q in the decomposition.
Definition HessenbergDecomposition.h:232
HouseholderSequence & setShift(Index shift)
Sets the shift of the Householder sequence.
Definition HouseholderSequence.h:363
HouseholderSequence & setLength(Index length)
Sets the length of the Householder sequence.
Definition HouseholderSequence.h:346
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:129