11#ifndef EIGEN_TRIDIAGONALIZATION_H
12#define EIGEN_TRIDIAGONALIZATION_H
18template<
typename MatrixType>
struct TridiagonalizationMatrixTReturnType;
19template<
typename MatrixType>
21 :
public traits<typename MatrixType::PlainObject>
27template<
typename MatrixType,
typename CoeffVectorType>
71 typedef typename MatrixType::Scalar
Scalar;
76 Size = MatrixType::RowsAtCompileTime,
79 MaxSize = MatrixType::MaxRowsAtCompileTime,
130 template<
typename InputType>
133 m_hCoeffs(matrix.cols() > 1 ? matrix.cols()-1 : 1),
157 template<
typename InputType>
306template<
typename MatrixType>
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>
352 typedef typename MatrixType::Scalar Scalar;
353 typedef typename MatrixType::RealScalar RealScalar;
354 Index n = matA.rows();
358 for (
Index i = 0; i<n-1; ++i)
360 Index remainingSize = n-i-1;
363 matA.col(i).tail(remainingSize).makeHouseholderInPlace(
h,
beta);
367 matA.col(i).coeffRef(i+1) = 1;
369 hCoeffs.tail(n-i-1).noalias() = (matA.bottomRightCorner(remainingSize,remainingSize).template selfadjointView<Lower>()
370 * (conj(
h) * matA.col(i).tail(remainingSize)));
372 hCoeffs.tail(n-i-1) += (conj(
h)*RealScalar(-0.5)*(hCoeffs.tail(remainingSize).dot(matA.col(i).tail(remainingSize)))) * matA.col(i).tail(n-i-1);
374 matA.bottomRightCorner(remainingSize, remainingSize).template selfadjointView<Lower>()
375 .rankUpdate(matA.col(i).tail(remainingSize), hCoeffs.tail(remainingSize), Scalar(-1));
377 matA.col(i).coeffRef(i+1) =
beta;
378 hCoeffs.coeffRef(i) =
h;
383template<
typename MatrixType,
384 int Size=MatrixType::ColsAtCompileTime,
386struct tridiagonalization_inplace_selector;
428template<
typename MatrixType,
typename DiagonalType,
typename SubDiagonalType,
typename CoeffVectorType>
431 CoeffVectorType& hcoeffs,
bool extractQ)
433 eigen_assert(mat.cols()==mat.rows() && diag.size()==mat.rows() && subdiag.size()==mat.rows()-1);
440template<
typename MatrixType,
int Size,
bool IsComplex>
445 template<
typename DiagonalType,
typename SubDiagonalType>
447 void run(MatrixType& mat, DiagonalType& diag, SubDiagonalType& subdiag,
CoeffVectorType& hCoeffs,
bool extractQ)
450 diag = mat.diagonal().real();
451 subdiag = mat.template diagonal<-1>().
real();
463template<
typename MatrixType>
466 typedef typename MatrixType::Scalar
Scalar;
469 template<
typename DiagonalType,
typename SubDiagonalType,
typename CoeffVectorType>
470 static void run(MatrixType& mat, DiagonalType& diag, SubDiagonalType& subdiag,
CoeffVectorType&,
bool extractQ)
480 subdiag[0] = mat(1,0);
481 subdiag[1] = mat(2,1);
489 Scalar m01 = mat(1,0) * invBeta;
490 Scalar m02 = mat(2,0) * invBeta;
492 diag[1] = mat(1,1) + m02*q;
493 diag[2] = mat(2,2) - m02*q;
495 subdiag[1] = mat(2,1) - m01 * q;
509template<
typename MatrixType,
bool IsComplex>
512 typedef typename MatrixType::Scalar
Scalar;
514 template<
typename DiagonalType,
typename SubDiagonalType,
typename CoeffVectorType>
532:
public ReturnByValue<TridiagonalizationMatrixTReturnType<MatrixType> >
541 template <
typename ResultType>
547 result.template diagonal<-1>() =
m_matrix.template diagonal<-1>();
EIGEN_DEVICE_FUNC RealReturnType real() const
Definition: CommonCwiseUnaryOps.h:100
internal::conditional< NumTraits< Scalar >::IsComplex, constCwiseUnaryOp< internal::scalar_real_op< Scalar >, constDerived >, constDerived & >::type RealReturnType
Definition: CommonCwiseUnaryOps.h:24
EIGEN_DEVICE_FUNC ConjugateReturnType conjugate() const
Definition: CommonCwiseUnaryOps.h:74
#define EIGEN_NOEXCEPT
Definition: Macros.h:1428
#define EIGEN_CONSTEXPR
Definition: Macros.h:797
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:986
#define eigen_assert(x)
Definition: Macros.h:1047
constexpr common_return_t< T1, T2 > beta(const T1 a, const T2 b) noexcept
Compile-time beta function.
Definition: beta.hpp:36
Expression of a diagonal/subdiagonal/superdiagonal in a matrix.
Definition: Diagonal.h:65
\householder_module
Definition: HouseholderSequence.h:121
EIGEN_DEVICE_FUNC HouseholderSequence & setShift(Index shift)
Sets the shift of the Householder sequence.
Definition: HouseholderSequence.h:461
EIGEN_DEVICE_FUNC HouseholderSequence & setLength(Index length)
Sets the length of the Householder sequence.
Definition: HouseholderSequence.h:443
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
internal::remove_all< typenameMatrixType::RealReturnType >::type MatrixTypeRealView
Definition: Tridiagonalization.h:86
Matrix< RealScalar, SizeMinusOne, 1, Options &~RowMajor, MaxSizeMinusOne, 1 > SubDiagonalType
Definition: Tridiagonalization.h:85
internal::conditional< NumTraits< Scalar >::IsComplex, typenameinternal::add_const_on_value_type< typenameDiagonal< constMatrixType >::RealReturnType >::type, constDiagonal< constMatrixType > >::type DiagonalReturnType
Definition: Tridiagonalization.h:92
MatrixTReturnType matrixT() const
Returns an expression of the tridiagonal matrix T in the decomposition.
Definition: Tridiagonalization.h:266
CoeffVectorType m_hCoeffs
Definition: Tridiagonalization.h:302
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
NumTraits< Scalar >::Real RealScalar
Definition: Tridiagonalization.h:72
Tridiagonalization(Index size=Size==Dynamic ? 2 :Size)
Default constructor.
Definition: Tridiagonalization.h:114
internal::conditional< NumTraits< Scalar >::IsComplex, typenameinternal::add_const_on_value_type< typenameDiagonal< constMatrixType,-1 >::RealReturnType >::type, constDiagonal< constMatrixType,-1 > >::type SubDiagonalReturnType
Definition: Tridiagonalization.h:97
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
bool m_isInitialized
Definition: Tridiagonalization.h:303
MatrixType m_matrix
Definition: Tridiagonalization.h:301
@ Size
Definition: Tridiagonalization.h:76
@ MaxSize
Definition: Tridiagonalization.h:79
@ MaxSizeMinusOne
Definition: Tridiagonalization.h:80
@ SizeMinusOne
Definition: Tridiagonalization.h:77
@ Options
Definition: Tridiagonalization.h:78
Matrix< Scalar, SizeMinusOne, 1, Options &~RowMajor, MaxSizeMinusOne, 1 > CoeffVectorType
Definition: Tridiagonalization.h:83
_MatrixType MatrixType
Synonym for the template parameter _MatrixType.
Definition: Tridiagonalization.h:69
internal::plain_col_type< MatrixType, RealScalar >::type DiagonalType
Definition: Tridiagonalization.h:84
HouseholderSequence< MatrixType, typename internal::remove_all< typename CoeffVectorType::ConjugateReturnType >::type > HouseholderSequenceType
Return type of matrixQ()
Definition: Tridiagonalization.h:100
MatrixType::Scalar Scalar
Definition: Tridiagonalization.h:71
internal::TridiagonalizationMatrixTReturnType< MatrixTypeRealView > MatrixTReturnType
Definition: Tridiagonalization.h:87
type
Definition: core.h:575
auto sqrt(const UnitType &value) noexcept -> unit_t< square_root< typename units::traits::unit_t_traits< UnitType >::unit_type >, typename units::traits::unit_t_traits< UnitType >::underlying_type, linear_scale >
computes the square root of value
Definition: math.h:483
constexpr common_t< T1, T2 > min(const T1 x, const T2 y) noexcept
Compile-time pairwise minimum function.
Definition: min.hpp:35
EIGEN_DEVICE_FUNC void tridiagonalization_inplace(MatrixType &matA, CoeffVectorType &hCoeffs)
Definition: Tridiagonalization.h:349
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
EIGEN_DEVICE_FUNC bool abs2(bool x)
Definition: MathFunctions.h:1292
Namespace containing all symbols from the Eigen library.
Definition: Core:141
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
result
Definition: format.h:2564
Definition: Eigen_Colamd.h:50
static constexpr const unit_t< compound_unit< energy::joule, time::seconds > > h(6.626070040e-34)
Planck constant.
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition: EigenBase.h:30
EIGEN_DEVICE_FUNC Derived & derived()
Definition: EigenBase.h:46
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: EigenBase.h:60
Holds information about the various numeric (i.e.
Definition: NumTraits.h:233
Definition: Tridiagonalization.h:533
MatrixType::Nested m_matrix
Definition: Tridiagonalization.h:554
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: Tridiagonalization.h:551
void evalTo(ResultType &result) const
Definition: Tridiagonalization.h:542
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: Tridiagonalization.h:550
TridiagonalizationMatrixTReturnType(const MatrixType &mat)
Constructor.
Definition: Tridiagonalization.h:539
T type
Definition: Meta.h:126
MatrixType::PlainObject ReturnType
Definition: Tridiagonalization.h:23
Definition: ForwardDeclarations.h:17
MatrixType::Scalar Scalar
Definition: Tridiagonalization.h:512
static EIGEN_DEVICE_FUNC void run(MatrixType &mat, DiagonalType &diag, SubDiagonalType &, CoeffVectorType &, bool extractQ)
Definition: Tridiagonalization.h:516
static void run(MatrixType &mat, DiagonalType &diag, SubDiagonalType &subdiag, CoeffVectorType &, bool extractQ)
Definition: Tridiagonalization.h:470
MatrixType::Scalar Scalar
Definition: Tridiagonalization.h:466
MatrixType::RealScalar RealScalar
Definition: Tridiagonalization.h:467
Definition: Tridiagonalization.h:442
static EIGEN_DEVICE_FUNC void run(MatrixType &mat, DiagonalType &diag, SubDiagonalType &subdiag, CoeffVectorType &hCoeffs, bool extractQ)
Definition: Tridiagonalization.h:447
Tridiagonalization< MatrixType >::CoeffVectorType CoeffVectorType
Definition: Tridiagonalization.h:443
Tridiagonalization< MatrixType >::HouseholderSequenceType HouseholderSequenceType
Definition: Tridiagonalization.h:444