mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-14 20:56:00 +08:00
Avoid memory allocation in tridiagonalization_inplace_selector::run.
(cherry picked from commit a5a7faeb455efd7f6edb1138eda2e37546039b7d)
This commit is contained in:
parent
1e9f623f3e
commit
4e0357c6dd
@ -125,6 +125,7 @@ template<typename _MatrixType> class SelfAdjointEigenSolver
|
||||
: m_eivec(),
|
||||
m_eivalues(),
|
||||
m_subdiag(),
|
||||
m_hcoeffs(),
|
||||
m_info(InvalidInput),
|
||||
m_isInitialized(false),
|
||||
m_eigenvectorsOk(false)
|
||||
@ -147,6 +148,7 @@ template<typename _MatrixType> class SelfAdjointEigenSolver
|
||||
: m_eivec(size, size),
|
||||
m_eivalues(size),
|
||||
m_subdiag(size > 1 ? size - 1 : 1),
|
||||
m_hcoeffs(size > 1 ? size - 1 : 1),
|
||||
m_isInitialized(false),
|
||||
m_eigenvectorsOk(false)
|
||||
{}
|
||||
@ -172,6 +174,7 @@ template<typename _MatrixType> class SelfAdjointEigenSolver
|
||||
: m_eivec(matrix.rows(), matrix.cols()),
|
||||
m_eivalues(matrix.cols()),
|
||||
m_subdiag(matrix.rows() > 1 ? matrix.rows() - 1 : 1),
|
||||
m_hcoeffs(matrix.cols() > 1 ? matrix.cols() - 1 : 1),
|
||||
m_isInitialized(false),
|
||||
m_eigenvectorsOk(false)
|
||||
{
|
||||
@ -378,6 +381,7 @@ template<typename _MatrixType> class SelfAdjointEigenSolver
|
||||
EigenvectorsType m_eivec;
|
||||
RealVectorType m_eivalues;
|
||||
typename TridiagonalizationType::SubDiagonalType m_subdiag;
|
||||
typename TridiagonalizationType::CoeffVectorType m_hcoeffs;
|
||||
ComputationInfo m_info;
|
||||
bool m_isInitialized;
|
||||
bool m_eigenvectorsOk;
|
||||
@ -450,7 +454,8 @@ SelfAdjointEigenSolver<MatrixType>& SelfAdjointEigenSolver<MatrixType>
|
||||
if(scale==RealScalar(0)) scale = RealScalar(1);
|
||||
mat.template triangularView<Lower>() /= scale;
|
||||
m_subdiag.resize(n-1);
|
||||
internal::tridiagonalization_inplace(mat, diag, m_subdiag, computeEigenvectors);
|
||||
m_hcoeffs.resize(n-1);
|
||||
internal::tridiagonalization_inplace(mat, diag, m_subdiag, m_hcoeffs, computeEigenvectors);
|
||||
|
||||
m_info = internal::computeFromTridiagonal_impl(diag, m_subdiag, m_maxIterations, computeEigenvectors, m_eivec);
|
||||
|
||||
|
@ -425,12 +425,13 @@ struct tridiagonalization_inplace_selector;
|
||||
*
|
||||
* \sa class Tridiagonalization
|
||||
*/
|
||||
template<typename MatrixType, typename DiagonalType, typename SubDiagonalType>
|
||||
template<typename MatrixType, typename DiagonalType, typename SubDiagonalType, typename CoeffVectorType>
|
||||
EIGEN_DEVICE_FUNC
|
||||
void tridiagonalization_inplace(MatrixType& mat, DiagonalType& diag, SubDiagonalType& subdiag, bool extractQ)
|
||||
void tridiagonalization_inplace(MatrixType& mat, DiagonalType& diag, SubDiagonalType& subdiag,
|
||||
CoeffVectorType& hcoeffs, bool extractQ)
|
||||
{
|
||||
eigen_assert(mat.cols()==mat.rows() && diag.size()==mat.rows() && subdiag.size()==mat.rows()-1);
|
||||
tridiagonalization_inplace_selector<MatrixType>::run(mat, diag, subdiag, extractQ);
|
||||
tridiagonalization_inplace_selector<MatrixType>::run(mat, diag, subdiag, hcoeffs, extractQ);
|
||||
}
|
||||
|
||||
/** \internal
|
||||
@ -443,10 +444,9 @@ struct tridiagonalization_inplace_selector
|
||||
typedef typename Tridiagonalization<MatrixType>::HouseholderSequenceType HouseholderSequenceType;
|
||||
template<typename DiagonalType, typename SubDiagonalType>
|
||||
static EIGEN_DEVICE_FUNC
|
||||
void run(MatrixType& mat, DiagonalType& diag, SubDiagonalType& subdiag, bool extractQ)
|
||||
void run(MatrixType& mat, DiagonalType& diag, SubDiagonalType& subdiag, CoeffVectorType& hCoeffs, bool extractQ)
|
||||
{
|
||||
CoeffVectorType hCoeffs(mat.cols()-1);
|
||||
tridiagonalization_inplace(mat,hCoeffs);
|
||||
tridiagonalization_inplace(mat, hCoeffs);
|
||||
diag = mat.diagonal().real();
|
||||
subdiag = mat.template diagonal<-1>().real();
|
||||
if(extractQ)
|
||||
@ -466,8 +466,8 @@ struct tridiagonalization_inplace_selector<MatrixType,3,false>
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
typedef typename MatrixType::RealScalar RealScalar;
|
||||
|
||||
template<typename DiagonalType, typename SubDiagonalType>
|
||||
static void run(MatrixType& mat, DiagonalType& diag, SubDiagonalType& subdiag, bool extractQ)
|
||||
template<typename DiagonalType, typename SubDiagonalType, typename CoeffVectorType>
|
||||
static void run(MatrixType& mat, DiagonalType& diag, SubDiagonalType& subdiag, CoeffVectorType&, bool extractQ)
|
||||
{
|
||||
using std::sqrt;
|
||||
const RealScalar tol = (std::numeric_limits<RealScalar>::min)();
|
||||
@ -511,9 +511,9 @@ struct tridiagonalization_inplace_selector<MatrixType,1,IsComplex>
|
||||
{
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
|
||||
template<typename DiagonalType, typename SubDiagonalType>
|
||||
template<typename DiagonalType, typename SubDiagonalType, typename CoeffVectorType>
|
||||
static EIGEN_DEVICE_FUNC
|
||||
void run(MatrixType& mat, DiagonalType& diag, SubDiagonalType&, bool extractQ)
|
||||
void run(MatrixType& mat, DiagonalType& diag, SubDiagonalType&, CoeffVectorType&, bool extractQ)
|
||||
{
|
||||
diag(0,0) = numext::real(mat(0,0));
|
||||
if(extractQ)
|
||||
|
Loading…
x
Reference in New Issue
Block a user