11 #ifndef EIGEN_TRIDIAGONALIZATION_H
12 #define EIGEN_TRIDIAGONALIZATION_H
20 template<
typename MatrixType>
struct TridiagonalizationMatrixTReturnType;
21 template<
typename MatrixType>
22 struct traits<TridiagonalizationMatrixTReturnType<
MatrixType> >
23 :
public traits<typename MatrixType::PlainObject>
29 template<
typename MatrixType,
typename CoeffVectorType>
78 Size = MatrixType::RowsAtCompileTime,
81 MaxSize = MatrixType::MaxRowsAtCompileTime,
86 typedef typename internal::plain_col_type<MatrixType, RealScalar>::type
DiagonalType;
89 typedef internal::TridiagonalizationMatrixTReturnType<MatrixTypeRealView>
MatrixTReturnType;
91 typedef std::conditional_t<NumTraits<Scalar>::IsComplex,
96 typedef std::conditional_t<NumTraits<Scalar>::IsComplex,
132 template<
typename InputType>
159 template<
typename InputType>
308 template<
typename MatrixType>
312 eigen_assert(m_isInitialized &&
"Tridiagonalization is not initialized.");
313 return m_matrix.diagonal().real();
316 template<
typename MatrixType>
320 eigen_assert(m_isInitialized &&
"Tridiagonalization is not initialized.");
321 return m_matrix.template diagonal<-1>().
real();
349 template<
typename MatrixType,
typename CoeffVectorType>
354 typedef typename MatrixType::Scalar Scalar;
365 matA.col(
i).tail(remainingSize).makeHouseholderInPlace(h, beta);
369 matA.col(
i).coeffRef(
i+1) = 1;
371 hCoeffs.tail(
n-
i-1).noalias() = (
matA.bottomRightCorner(remainingSize,remainingSize).template selfadjointView<Lower>()
372 * (
conj(h) *
matA.col(
i).tail(remainingSize)));
374 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);
376 matA.bottomRightCorner(remainingSize, remainingSize).template selfadjointView<Lower>()
377 .rankUpdate(
matA.col(
i).tail(remainingSize), hCoeffs.tail(remainingSize), Scalar(-1));
379 matA.col(
i).coeffRef(
i+1) = beta;
380 hCoeffs.coeffRef(
i) = h;
386 int Size=MatrixType::ColsAtCompileTime,
388 struct tridiagonalization_inplace_selector;
430 template<
typename MatrixType,
typename DiagonalType,
typename SubDiagonalType,
typename CoeffVectorType,
typename WorkSpaceType>
433 CoeffVectorType& hcoeffs, WorkSpaceType& workspace,
bool extractQ)
436 tridiagonalization_inplace_selector<MatrixType>::run(
mat, diag, subdiag, hcoeffs, workspace, extractQ);
442 template<
typename MatrixType,
int Size,
bool IsComplex>
443 struct tridiagonalization_inplace_selector
446 template<
typename DiagonalType,
typename SubDiagonalType,
typename CoeffVectorType,
typename WorkSpaceType>
448 void run(
MatrixType&
mat, DiagonalType& diag, SubDiagonalType& subdiag, CoeffVectorType& hCoeffs, WorkSpaceType& workspace,
bool extractQ)
451 diag =
mat.diagonal().real();
452 subdiag =
mat.template diagonal<-1>().
real();
454 HouseholderSequenceType(
mat, hCoeffs.conjugate())
455 .setLength(
mat.rows() - 1)
457 .evalTo(
mat, workspace);
466 template<
typename MatrixType>
467 struct tridiagonalization_inplace_selector<
MatrixType,3,false>
472 template<
typename DiagonalType,
typename SubDiagonalType,
typename CoeffVectorType,
typename WorkSpaceType>
473 static void run(
MatrixType&
mat, DiagonalType& diag, SubDiagonalType& subdiag, CoeffVectorType&, WorkSpaceType&,
bool extractQ)
483 subdiag[0] =
mat(1,0);
484 subdiag[1] =
mat(2,1);
491 RealScalar invBeta = RealScalar(1)/beta;
492 Scalar m01 =
mat(1,0) * invBeta;
493 Scalar m02 =
mat(2,0) * invBeta;
494 Scalar q = RealScalar(2)*m01*
mat(2,1) + m02*(
mat(2,2) -
mat(1,1));
495 diag[1] =
mat(1,1) + m02*q;
496 diag[2] =
mat(2,2) - m02*q;
498 subdiag[1] =
mat(2,1) - m01 * q;
512 template<
typename MatrixType,
bool IsComplex>
513 struct tridiagonalization_inplace_selector<
MatrixType,1,IsComplex>
517 template<
typename DiagonalType,
typename SubDiagonalType,
typename CoeffVectorType,
typename WorkSpaceType>
519 void run(
MatrixType&
mat, DiagonalType& diag, SubDiagonalType&, CoeffVectorType&, WorkSpaceType&,
bool extractQ)
523 mat(0,0) = Scalar(1);
534 template<
typename MatrixType>
struct TridiagonalizationMatrixTReturnType
535 :
public ReturnByValue<TridiagonalizationMatrixTReturnType<MatrixType> >
542 TridiagonalizationMatrixTReturnType(
const MatrixType&
mat) : m_matrix(
mat) { }
544 template <
typename ResultType>
545 inline void evalTo(ResultType& result)
const
548 result.template diagonal<1>() = m_matrix.template diagonal<-1>().
conjugate();
549 result.diagonal() = m_matrix.diagonal();
550 result.template diagonal<-1>() = m_matrix.template diagonal<-1>();
557 typename MatrixType::Nested m_matrix;
const SqrtReturnType sqrt() const
RealReturnType real() const
ConjugateReturnType conjugate() const
#define EIGEN_DEVICE_FUNC
Matrix< float, 1, Dynamic > MatrixType
NumTraits< Scalar >::Real RealScalar
internal::traits< Derived >::Scalar Scalar
Expression of a diagonal/subdiagonal/superdiagonal in a matrix.
Sequence of Householder reflections acting on subspaces with decreasing size.
Base::PlainObject PlainObject
constexpr void resize(Index rows, Index cols)
void evalTo(Dest &dst) const
Tridiagonal decomposition of a selfadjoint matrix.
Tridiagonalization(Index size=Size==Dynamic ? 2 :Size)
Default constructor.
DiagonalReturnType diagonal() const
Returns the diagonal of the tridiagonal matrix T in the decomposition.
std::conditional_t< NumTraits< Scalar >::IsComplex, internal::add_const_on_value_type_t< typename Diagonal< const MatrixType, -1 >::RealReturnType >, const Diagonal< const MatrixType, -1 > > SubDiagonalReturnType
internal::plain_col_type< MatrixType, RealScalar >::type DiagonalType
std::conditional_t< NumTraits< Scalar >::IsComplex, internal::add_const_on_value_type_t< typename Diagonal< const MatrixType >::RealReturnType >, const Diagonal< const MatrixType > > DiagonalReturnType
MatrixType_ MatrixType
Synonym for the template parameter MatrixType_.
Tridiagonalization & compute(const EigenBase< InputType > &matrix)
Computes tridiagonal decomposition of given matrix.
CoeffVectorType householderCoefficients() const
Returns the Householder coefficients.
MatrixType::Scalar Scalar
internal::remove_all_t< typename MatrixType::RealReturnType > MatrixTypeRealView
internal::TridiagonalizationMatrixTReturnType< MatrixTypeRealView > MatrixTReturnType
Matrix< Scalar, SizeMinusOne, 1, Options &~RowMajor, MaxSizeMinusOne, 1 > CoeffVectorType
CoeffVectorType m_hCoeffs
SubDiagonalReturnType subDiagonal() const
Returns the subdiagonal of the tridiagonal matrix T in the decomposition.
HouseholderSequence< MatrixType, internal::remove_all_t< typename CoeffVectorType::ConjugateReturnType > > HouseholderSequenceType
Return type of matrixQ()
HouseholderSequenceType matrixQ() const
Returns the unitary matrix Q in the decomposition.
const MatrixType & packedMatrix() const
Returns the internal representation of the decomposition.
MatrixTReturnType matrixT() const
Returns an expression of the tridiagonal matrix T in the decomposition.
Tridiagonalization(const EigenBase< InputType > &matrix)
Constructor; computes tridiagonal decomposition of given matrix.
Matrix< RealScalar, SizeMinusOne, 1, Options &~RowMajor, MaxSizeMinusOne, 1 > SubDiagonalType
NumTraits< Scalar >::Real RealScalar
bfloat16() min(const bfloat16 &a, const bfloat16 &b)
void tridiagonalization_inplace(MatrixType &matA, CoeffVectorType &hCoeffs)
typename remove_all< T >::type remove_all_t
typename add_const_on_value_type< T >::type add_const_on_value_type_t
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_conjugate_op< typename Derived::Scalar >, const Derived > conj(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_real_op< typename Derived::Scalar >, const Derived > real(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.