From c29c7b0ea95b86f73d77224efb26f96abdc189ac Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 3 Sep 2008 20:52:26 +0000 Subject: [PATCH] Fix bugs reported by Timothy Hunter: * CholeskyWithoutSqrt with 1x1 matrices * .part() Updated unit tests to handle these cases --- Eigen/src/Cholesky/CholeskyWithoutSquareRoot.h | 6 ++++++ Eigen/src/Core/Part.h | 2 +- test/cholesky.cpp | 1 - test/triangular.cpp | 2 ++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Eigen/src/Cholesky/CholeskyWithoutSquareRoot.h b/Eigen/src/Cholesky/CholeskyWithoutSquareRoot.h index db33b04f9..4040869b0 100644 --- a/Eigen/src/Cholesky/CholeskyWithoutSquareRoot.h +++ b/Eigen/src/Cholesky/CholeskyWithoutSquareRoot.h @@ -96,6 +96,12 @@ void CholeskyWithoutSquareRoot::compute(const MatrixType& a) m_isPositiveDefinite = true; const RealScalar eps = ei_sqrt(precision()); + 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. diff --git a/Eigen/src/Core/Part.h b/Eigen/src/Core/Part.h index 4d39c4c08..931933575 100644 --- a/Eigen/src/Core/Part.h +++ b/Eigen/src/Core/Part.h @@ -88,7 +88,7 @@ template 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); diff --git a/test/cholesky.cpp b/test/cholesky.cpp index 36a11c723..80614346c 100644 --- a/test/cholesky.cpp +++ b/test/cholesky.cpp @@ -79,7 +79,6 @@ template void cholesky(const MatrixType& m) } #endif - if (rows>1) { CholeskyWithoutSquareRoot cholnosqrt(symm); VERIFY(cholnosqrt.isPositiveDefinite()); diff --git a/test/triangular.cpp b/test/triangular.cpp index 22a19f974..2ada0dd90 100644 --- a/test/triangular.cpp +++ b/test/triangular.cpp @@ -81,6 +81,8 @@ template void triangular(const MatrixType& m) m1.template part() = (m2.transpose() * m2).lazy(); VERIFY_IS_APPROX(m3.template part(), m1); + VERIFY_IS_APPROX(m3.template part(), m3.diagonal().asDiagonal()); + m1 = MatrixType::Random(rows, cols); for (int i=0; i();