11#ifndef EIGEN_TRIDIAGONALIZATION_H
12#define EIGEN_TRIDIAGONALIZATION_H
18template<
typename MatrixType>
struct TridiagonalizationMatrixTReturnType;
19template<
typename MatrixType>
21 :
public traits<typename MatrixType::PlainObject>
23 typedef typename MatrixType::PlainObject ReturnType;
27template<
typename MatrixType,
typename CoeffVectorType>
29void tridiagonalization_inplace(MatrixType&
matA, CoeffVectorType& hCoeffs);
71 typedef typename MatrixType::Scalar Scalar;
76 Size = MatrixType::RowsAtCompileTime,
77 SizeMinusOne = Size ==
Dynamic ?
Dynamic : (Size > 1 ? Size - 1 : 1),
78 Options = MatrixType::Options,
79 MaxSize = MatrixType::MaxRowsAtCompileTime,
80 MaxSizeMinusOne = MaxSize ==
Dynamic ?
Dynamic : (MaxSize > 1 ? MaxSize - 1 : 1)
86 typedef typename internal::remove_all<typename MatrixType::RealReturnType>::type MatrixTypeRealView;
92 >::type DiagonalReturnType;
97 >::type SubDiagonalReturnType;
115 : m_matrix(size,size),
116 m_hCoeffs(size > 1 ? size-1 : 1),
117 m_isInitialized(
false)
130 template<
typename InputType>
132 : m_matrix(matrix.derived()),
133 m_hCoeffs(matrix.cols() > 1 ? matrix.cols()-1 : 1),
134 m_isInitialized(
false)
136 internal::tridiagonalization_inplace(m_matrix, m_hCoeffs);
137 m_isInitialized =
true;
157 template<
typename InputType>
160 m_matrix = matrix.derived();
161 m_hCoeffs.
resize(matrix.rows()-1, 1);
162 internal::tridiagonalization_inplace(m_matrix, m_hCoeffs);
163 m_isInitialized =
true;
185 eigen_assert(m_isInitialized &&
"Tridiagonalization is not initialized.");
222 eigen_assert(m_isInitialized &&
"Tridiagonalization is not initialized.");
243 eigen_assert(m_isInitialized &&
"Tridiagonalization is not initialized.");
245 .setLength(m_matrix.rows() - 1)
268 eigen_assert(m_isInitialized &&
"Tridiagonalization is not initialized.");
285 DiagonalReturnType
diagonal()
const;
302 CoeffVectorType m_hCoeffs;
303 bool m_isInitialized;
306template<
typename MatrixType>
307typename Tridiagonalization<MatrixType>::DiagonalReturnType
310 eigen_assert(m_isInitialized &&
"Tridiagonalization is not initialized.");
311 return m_matrix.diagonal().real();
314template<
typename MatrixType>
318 eigen_assert(m_isInitialized &&
"Tridiagonalization is not initialized.");
319 return m_matrix.template
diagonal<-1>().real();
347template<
typename MatrixType,
typename CoeffVectorType>
349void tridiagonalization_inplace(MatrixType&
matA, CoeffVectorType& hCoeffs)
352 typedef typename MatrixType::Scalar Scalar;
353 typedef typename MatrixType::RealScalar RealScalar;
355 eigen_assert(n==
matA.cols());
356 eigen_assert(n==hCoeffs.size()+1 || n==1);
358 for (
Index i = 0; i<n-1; ++i)
367 matA.col(i).coeffRef(i+1) = 1;
377 matA.col(i).coeffRef(i+1) = beta;
378 hCoeffs.coeffRef(i) = h;
383template<
typename MatrixType,
384 int Size=MatrixType::ColsAtCompileTime,
385 bool IsComplex=NumTraits<typename MatrixType::Scalar>::IsComplex>
386struct tridiagonalization_inplace_selector;
428template<
typename MatrixType,
typename DiagonalType,
typename SubDiagonalType,
typename CoeffVectorType>
430void tridiagonalization_inplace(MatrixType& mat, DiagonalType& diag, SubDiagonalType& subdiag,
431 CoeffVectorType& hcoeffs,
bool extractQ)
433 eigen_assert(mat.cols()==mat.rows() && diag.size()==mat.rows() && subdiag.size()==mat.rows()-1);
434 tridiagonalization_inplace_selector<MatrixType>::run(mat, diag, subdiag, hcoeffs, extractQ);
440template<
typename MatrixType,
int Size,
bool IsComplex>
444 template<
typename DiagonalType,
typename SubDiagonalType,
typename CoeffVectorType>
445 static EIGEN_DEVICE_FUNC
446 void run(MatrixType&
mat, DiagonalType&
diag, SubDiagonalType&
subdiag, CoeffVectorType& hCoeffs,
bool extractQ)
448 tridiagonalization_inplace(
mat, hCoeffs);
453 .setLength(
mat.rows() - 1)
462template<
typename MatrixType>
465 typedef typename MatrixType::Scalar Scalar;
466 typedef typename MatrixType::RealScalar RealScalar;
468 template<
typename DiagonalType,
typename SubDiagonalType,
typename CoeffVectorType>
469 static void run(MatrixType&
mat, DiagonalType&
diag, SubDiagonalType&
subdiag, CoeffVectorType&,
bool extractQ)
472 const RealScalar
tol = (std::numeric_limits<RealScalar>::min)();
486 RealScalar beta = sqrt(numext::abs2(
mat(1,0)) +
v1norm2);
487 RealScalar
invBeta = RealScalar(1)/beta;
508template<
typename MatrixType,
bool IsComplex>
511 typedef typename MatrixType::Scalar Scalar;
513 template<
typename DiagonalType,
typename SubDiagonalType,
typename CoeffVectorType>
514 static EIGEN_DEVICE_FUNC
515 void run(MatrixType&
mat, DiagonalType&
diag, SubDiagonalType&, CoeffVectorType&,
bool extractQ)
517 diag(0,0) = numext::real(
mat(0,0));
519 mat(0,0) = Scalar(1);
531:
public ReturnByValue<TridiagonalizationMatrixTReturnType<MatrixType> >
540 template <
typename ResultType>
541 inline void evalTo(ResultType& result)
const
544 result.template
diagonal<1>() = m_matrix.template diagonal<-1>().conjugate();
545 result.diagonal() = m_matrix.diagonal();
546 result.template diagonal<-1>() = m_matrix.template
diagonal<-1>();
549 EIGEN_CONSTEXPR
Index rows()
const EIGEN_NOEXCEPT {
return m_matrix.rows(); }
550 EIGEN_CONSTEXPR
Index cols() const EIGEN_NOEXCEPT {
return m_matrix.cols(); }
553 typename MatrixType::Nested m_matrix;
Expression of a diagonal/subdiagonal/superdiagonal in a matrix.
Definition Diagonal.h:65
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
EIGEN_DEVICE_FUNC void makeHouseholderInPlace(Scalar &tau, RealScalar &beta)
Computes the elementary reflector H such that: where the transformation H is: and the vector v is: ...
Definition Householder.h:43
NoAlias< Derived, Eigen::MatrixBase > EIGEN_DEVICE_FUNC noalias()
Definition NoAlias.h:102
EIGEN_DEVICE_FUNC Derived & setIdentity()
Writes the identity expression (not necessarily square) into *this.
Definition CwiseNullaryOp.h:873
EIGEN_DEVICE_FUNC DiagonalReturnType diagonal()
Definition Diagonal.h:187
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Resizes *this to a rows x cols matrix.
Definition PlainObjectBase.h:271
Definition ReturnByValue.h:52
\eigenvalues_module
Definition Tridiagonalization.h:65
HouseholderSequenceType matrixQ() const
Returns the unitary matrix Q in the decomposition.
Definition Tridiagonalization.h:241
Tridiagonalization(const EigenBase< InputType > &matrix)
Constructor; computes tridiagonal decomposition of given matrix.
Definition Tridiagonalization.h:131
DiagonalReturnType diagonal() const
Returns the diagonal of the tridiagonal matrix T in the decomposition.
Definition Tridiagonalization.h:308
MatrixTReturnType matrixT() const
Returns an expression of the tridiagonal matrix T in the decomposition.
Definition Tridiagonalization.h:266
Eigen::Index Index
Definition Tridiagonalization.h:73
const MatrixType & packedMatrix() const
Returns the internal representation of the decomposition.
Definition Tridiagonalization.h:220
Tridiagonalization & compute(const EigenBase< InputType > &matrix)
Computes tridiagonal decomposition of given matrix.
Definition Tridiagonalization.h:158
Tridiagonalization(Index size=Size==Dynamic ? 2 :Size)
Default constructor.
Definition Tridiagonalization.h:114
SubDiagonalReturnType subDiagonal() const
Returns the subdiagonal of the tridiagonal matrix T in the decomposition.
Definition Tridiagonalization.h:316
CoeffVectorType householderCoefficients() const
Returns the Householder coefficients.
Definition Tridiagonalization.h:183
_MatrixType MatrixType
Synonym for the template parameter _MatrixType.
Definition Tridiagonalization.h:69
HouseholderSequence< MatrixType, typename internal::remove_all< typename CoeffVectorType::ConjugateReturnType >::type > HouseholderSequenceType
Return type of matrixQ()
Definition Tridiagonalization.h:100
Namespace containing all symbols from the Eigen library.
Definition LDLT.h:16
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time,...
Definition Constants.h:22
Definition Tridiagonalization.h:532
TridiagonalizationMatrixTReturnType(const MatrixType &mat)
Constructor.
Definition Tridiagonalization.h:538
Definition ForwardDeclarations.h:17
Definition Tridiagonalization.h:442