mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
Fix bugs reported by Timothy Hunter:
* CholeskyWithoutSqrt with 1x1 matrices * .part<Diagonal>() Updated unit tests to handle these cases
This commit is contained in:
parent
e14aa8c8aa
commit
c29c7b0ea9
@ -96,6 +96,12 @@ void CholeskyWithoutSquareRoot<MatrixType>::compute(const MatrixType& a)
|
||||
m_isPositiveDefinite = true;
|
||||
const RealScalar eps = ei_sqrt(precision<Scalar>());
|
||||
|
||||
if (size<=1)
|
||||
{
|
||||
m_matrix = a;
|
||||
return;
|
||||
}
|
||||
|
||||
// Let's preallocate a temporay vector to evaluate the matrix-vector product into it.
|
||||
// Unlike the standard Cholesky decomposition, here we cannot evaluate it to the destination
|
||||
// matrix because it a sub-row which is not compatible suitable for efficient packet evaluation.
|
||||
|
@ -88,7 +88,7 @@ template<typename MatrixType, unsigned int Mode> class Part
|
||||
|
||||
inline Scalar coeff(int row, int col) const
|
||||
{
|
||||
if(Flags & LowerTriangularBit ? col>row : row>col)
|
||||
if( (Flags & LowerTriangularBit) && (col>row) || (Flags & UpperTriangularBit) && (row>col) )
|
||||
return (Flags & SelfAdjointBit) ? ei_conj(m_matrix.coeff(col, row)) : (Scalar)0;
|
||||
if(Flags & UnitDiagBit)
|
||||
return col==row ? (Scalar)1 : m_matrix.coeff(row, col);
|
||||
|
@ -79,7 +79,6 @@ template<typename MatrixType> void cholesky(const MatrixType& m)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (rows>1)
|
||||
{
|
||||
CholeskyWithoutSquareRoot<SquareMatrixType> cholnosqrt(symm);
|
||||
VERIFY(cholnosqrt.isPositiveDefinite());
|
||||
|
@ -81,6 +81,8 @@ template<typename MatrixType> void triangular(const MatrixType& m)
|
||||
m1.template part<Eigen::Lower>() = (m2.transpose() * m2).lazy();
|
||||
VERIFY_IS_APPROX(m3.template part<Eigen::Lower>(), m1);
|
||||
|
||||
VERIFY_IS_APPROX(m3.template part<Diagonal>(), m3.diagonal().asDiagonal());
|
||||
|
||||
m1 = MatrixType::Random(rows, cols);
|
||||
for (int i=0; i<rows; ++i)
|
||||
while (ei_abs2(m1(i,i))<1e-3) m1(i,i) = ei_random<Scalar>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user