mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-03-31 19:00:35 +08:00
bugfix in CholeskyWithoutSquareRoot::solve found by Timothy Hunter
This commit is contained in:
parent
d9d69de382
commit
5546e963c9
@ -25,6 +25,8 @@ namespace Eigen {
|
||||
* \endcode
|
||||
*/
|
||||
|
||||
#include "src/Array/CwiseOperators.h"
|
||||
#include "src/Array/Functors.h"
|
||||
#include "src/Cholesky/Cholesky.h"
|
||||
#include "src/Cholesky/CholeskyWithoutSquareRoot.h"
|
||||
|
||||
|
@ -149,10 +149,9 @@ typename Derived::Eval CholeskyWithoutSquareRoot<MatrixType>::solve(const Matrix
|
||||
|
||||
return m_matrix.adjoint().template part<UnitUpper>()
|
||||
.solveTriangular(
|
||||
(matrixL()
|
||||
.solveTriangular(b))
|
||||
.cwise()/m_matrix.diagonal()
|
||||
);
|
||||
( m_matrix.cwise().inverse().diagonal().asDiagonal()
|
||||
* matrixL().solveTriangular(b))
|
||||
);
|
||||
}
|
||||
|
||||
/** \cholesky_module
|
||||
|
@ -39,16 +39,19 @@ template<typename MatrixType> void cholesky(const MatrixType& m)
|
||||
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
|
||||
|
||||
MatrixType a = MatrixType::Random(rows,cols);
|
||||
VectorType b = VectorType::Random(rows);
|
||||
VectorType vecB = VectorType::Random(rows);
|
||||
MatrixType matB = MatrixType::Random(rows,cols);
|
||||
SquareMatrixType covMat = a * a.adjoint();
|
||||
|
||||
CholeskyWithoutSquareRoot<SquareMatrixType> cholnosqrt(covMat);
|
||||
VERIFY_IS_APPROX(covMat, cholnosqrt.matrixL() * cholnosqrt.vectorD().asDiagonal() * cholnosqrt.matrixL().adjoint());
|
||||
VERIFY_IS_APPROX(covMat * cholnosqrt.solve(b), b);
|
||||
VERIFY_IS_APPROX(covMat * cholnosqrt.solve(vecB), vecB);
|
||||
VERIFY_IS_APPROX(covMat * cholnosqrt.solve(matB), matB);
|
||||
|
||||
Cholesky<SquareMatrixType> chol(covMat);
|
||||
VERIFY_IS_APPROX(covMat, chol.matrixL() * chol.matrixL().adjoint());
|
||||
VERIFY_IS_APPROX(covMat * chol.solve(b), b);
|
||||
VERIFY_IS_APPROX(covMat * chol.solve(vecB), vecB);
|
||||
VERIFY_IS_APPROX(covMat * chol.solve(matB), matB);
|
||||
}
|
||||
|
||||
void test_cholesky()
|
||||
|
Loading…
x
Reference in New Issue
Block a user