11 #ifndef EIGEN_HESSENBERGDECOMPOSITION_H
12 #define EIGEN_HESSENBERGDECOMPOSITION_H
14 #include "./InternalHeaderCheck.h"
20 template<
typename MatrixType>
struct HessenbergDecompositionMatrixHReturnType;
21 template<
typename MatrixType>
22 struct traits<HessenbergDecompositionMatrixHReturnType<MatrixType> >
24 typedef MatrixType ReturnType;
67 Size = MatrixType::RowsAtCompileTime,
69 Options = MatrixType::Options,
70 MaxSize = MatrixType::MaxRowsAtCompileTime,
75 typedef typename MatrixType::Scalar
Scalar;
89 typedef internal::HessenbergDecompositionMatrixHReturnType<MatrixType> MatrixHReturnType;
103 : m_matrix(size,size),
105 m_isInitialized(false)
120 template<
typename InputType>
122 : m_matrix(matrix.derived()),
123 m_temp(matrix.rows()),
124 m_isInitialized(false)
128 m_isInitialized =
true;
132 _compute(m_matrix, m_hCoeffs, m_temp);
133 m_isInitialized =
true;
153 template<
typename InputType>
159 m_isInitialized =
true;
163 _compute(m_matrix, m_hCoeffs, m_temp);
164 m_isInitialized =
true;
183 eigen_assert(m_isInitialized &&
"HessenbergDecomposition is not initialized.");
218 eigen_assert(m_isInitialized &&
"HessenbergDecomposition is not initialized.");
238 eigen_assert(m_isInitialized &&
"HessenbergDecomposition is not initialized.");
240 .setLength(m_matrix.rows() - 1)
266 eigen_assert(m_isInitialized &&
"HessenbergDecomposition is not initialized.");
267 return MatrixHReturnType(*
this);
280 bool m_isInitialized;
295 template<
typename MatrixType>
296 void HessenbergDecomposition<MatrixType>::_compute(MatrixType& matA, CoeffVectorType& hCoeffs, VectorType& temp)
298 eigen_assert(matA.rows()==matA.cols());
299 Index n = matA.rows();
301 for (Index i = 0; i<n-1; ++i)
304 Index remainingSize = n-i-1;
307 matA.col(i).tail(remainingSize).makeHouseholderInPlace(h, beta);
308 matA.col(i).coeffRef(i+1) = beta;
309 hCoeffs.coeffRef(i) = h;
315 matA.bottomRightCorner(remainingSize, remainingSize)
316 .applyHouseholderOnTheLeft(matA.col(i).tail(remainingSize-1), h, &temp.coeffRef(0));
319 matA.rightCols(remainingSize)
320 .applyHouseholderOnTheRight(matA.col(i).tail(remainingSize-1), numext::conj(h), &temp.coeffRef(0));
341 template<
typename MatrixType>
struct HessenbergDecompositionMatrixHReturnType
342 :
public ReturnByValue<HessenbergDecompositionMatrixHReturnType<MatrixType> >
349 HessenbergDecompositionMatrixHReturnType(
const HessenbergDecomposition<MatrixType>& hess) : m_hess(hess) { }
356 template <
typename ResultType>
357 inline void evalTo(ResultType& result)
const
359 result = m_hess.packedMatrix();
360 Index n = result.rows();
362 result.bottomLeftCorner(n-2, n-2).template triangularView<Lower>().setZero();
365 Index rows()
const {
return m_hess.packedMatrix().rows(); }
366 Index cols()
const {
return m_hess.packedMatrix().cols(); }
369 const HessenbergDecomposition<MatrixType>& m_hess;
Reduces a square matrix to Hessenberg form by an orthogonal similarity transformation.
Definition: HessenbergDecomposition.h:60
Matrix< Scalar, SizeMinusOne, 1, Options &~RowMajor, MaxSizeMinusOne, 1 > CoeffVectorType
Type for vector of Householder coefficients.
Definition: HessenbergDecomposition.h:84
const CoeffVectorType & householderCoefficients() const
Returns the Householder coefficients.
Definition: HessenbergDecomposition.h:181
HessenbergDecomposition(Index size=Size==Dynamic ? 2 :Size)
Default constructor; the decomposition will be computed later.
Definition: HessenbergDecomposition.h:102
MatrixType::Scalar Scalar
Scalar type for matrices of type MatrixType.
Definition: HessenbergDecomposition.h:75
HessenbergDecomposition & compute(const EigenBase< InputType > &matrix)
Computes Hessenberg decomposition of given matrix.
Definition: HessenbergDecomposition.h:154
HessenbergDecomposition(const EigenBase< InputType > &matrix)
Constructor; computes Hessenberg decomposition of given matrix.
Definition: HessenbergDecomposition.h:121
MatrixHReturnType matrixH() const
Constructs the Hessenberg matrix H in the decomposition.
Definition: HessenbergDecomposition.h:264
HouseholderSequenceType matrixQ() const
Reconstructs the orthogonal matrix Q in the decomposition.
Definition: HessenbergDecomposition.h:236
const MatrixType & packedMatrix() const
Returns the internal representation of the decomposition.
Definition: HessenbergDecomposition.h:216
HouseholderSequence< MatrixType, internal::remove_all_t< typename CoeffVectorType::ConjugateReturnType > > HouseholderSequenceType
Return type of matrixQ()
Definition: HessenbergDecomposition.h:87
Eigen::Index Index
Definition: HessenbergDecomposition.h:76
MatrixType_ MatrixType
Synonym for the template parameter MatrixType_.
Definition: HessenbergDecomposition.h:64
Sequence of Householder reflections acting on subspaces with decreasing size.
Definition: HouseholderSequence.h:123
void resize(Index rows, Index cols)
Definition: PlainObjectBase.h:283
@ RowMajor
Definition: Constants.h:323
Namespace containing all symbols from the Eigen library.
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
const int Dynamic
Definition: Constants.h:24
Definition: EigenBase.h:32
Derived & derived()
Definition: EigenBase.h:48
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: EigenBase.h:62
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:231