implement other variants

This commit is contained in:
Gael Guennebaud 2010-06-17 10:11:38 +02:00
parent db160f2e0b
commit 43086d12d2
2 changed files with 49 additions and 19 deletions

View File

@ -185,28 +185,58 @@ compute(const MatrixType& matA, const MatrixType& matB, int options)
ei_assert(matA.cols()==matA.rows() && matB.rows()==matA.rows() && matB.cols()==matB.rows());
ei_assert((options&~(EigVecMask|GenEigMask))==0
&& (options&EigVecMask)!=EigVecMask
&& ((options&GenEigMask)==Ax_lBx || (options&GenEigMask)==ABx_lx || (options&GenEigMask)==BAx_lx)
&& ((options&GenEigMask)==0 || (options&GenEigMask)==Ax_lBx
|| (options&GenEigMask)==ABx_lx || (options&GenEigMask)==BAx_lx)
&& "invalid option parameter");
ei_assert((options&GenEigMask)==Ax_lBx && "other variants are not implemented yet, sorry.");
// TODO implements other variants !!
bool computeEigVecs = (options&EigVecMask)==ComputeEigenvectors;
bool computeEigVecs = ((options&EigVecMask)==0) || ((options&EigVecMask)==ComputeEigenvectors);
// Compute the cholesky decomposition of matB = L L' = U'U
LLT<MatrixType> cholB(matB);
int type = (options&GenEigMask);
if(type==0)
type = Ax_lBx;
if(type==Ax_lBx)
{
// compute C = inv(L) A inv(L')
MatrixType matC = matA.template selfadjointView<Lower>();
cholB.matrixL().template solveInPlace<OnTheLeft>(matC);
cholB.matrixU().template solveInPlace<OnTheRight>(matC);
Base::compute(matC, options&EigVecMask);
Base::compute(matC, computeEigVecs ? ComputeEigenvectors : EigenvaluesOnly );
// transform back the eigen vectors: evecs = inv(U) * evecs
if(computeEigVecs)
cholB.matrixU().solveInPlace(Base::m_eivec);
}
else if(type==ABx_lx)
{
// compute C = L' A L
MatrixType matC = matA.template selfadjointView<Lower>();
matC = matC * cholB.matrixL();
matC = cholB.matrixU() * matC;
Base::compute(matC, computeEigVecs ? ComputeEigenvectors : EigenvaluesOnly);
// transform back the eigen vectors: evecs = inv(U) * evecs
if(computeEigVecs)
cholB.matrixU().solveInPlace(Base::m_eivec);
}
else if(type==BAx_lx)
{
// compute C = L' A L
MatrixType matC = matA.template selfadjointView<Lower>();
matC = matC * cholB.matrixL();
matC = cholB.matrixU() * matC;
Base::compute(matC, computeEigVecs ? ComputeEigenvectors : EigenvaluesOnly);
// transform back the eigen vectors: evecs = L * evecs
if(computeEigVecs)
Base::m_eivec = cholB.matrixL() * Base::m_eivec;
}
return *this;
}

View File

@ -1,7 +1,7 @@
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
// Copyright (C) 2008-2010 Gael Guennebaud <g.gael@free.fr>
// Copyright (C) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk>
//
// Eigen is free software; you can redistribute it and/or