From 014c581a5b32330e202e52fc5f9d98d383461da0 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Wed, 5 Aug 2009 10:15:28 +0200 Subject: [PATCH] fix assertions, improve docs. we never assert on conditions that depend on the result of a computation!! also the assertion that rank>0 amounts to matrix!=0 which we have to leave under the responsibility of the user. --- Eigen/src/LU/LU.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Eigen/src/LU/LU.h b/Eigen/src/LU/LU.h index 2bdcc4512..7d688c238 100644 --- a/Eigen/src/LU/LU.h +++ b/Eigen/src/LU/LU.h @@ -103,9 +103,15 @@ template class LU /** Constructor. * * \param matrix the matrix of which to compute the LU decomposition. + * It is required to be nonzero. */ LU(const MatrixType& matrix); + /** Computes the LU decomposition of the given matrix. + * + * \param matrix the matrix of which to compute the LU decomposition. + * It is required to be nonzero. + */ void compute(const MatrixType& matrix); /** \returns the LU decomposition matrix: the upper-triangular part is U, the @@ -317,6 +323,7 @@ template class LU */ inline void computeInverse(MatrixType *result) const { + ei_assert(m_originalMatrix != 0 && "LU is not initialized."); solve(MatrixType::Identity(m_lu.rows(), m_lu.cols()), result); } @@ -461,7 +468,7 @@ template template void LU::computeKernel(KernelMatrixType *result) const { - ei_assert(!isInvertible()); + ei_assert(m_originalMatrix != 0 && "LU is not initialized."); const int dimker = dimensionOfKernel(), cols = m_lu.cols(); result->resize(cols, dimker); @@ -497,6 +504,7 @@ template const typename LU::KernelResultType LU::kernel() const { + ei_assert(m_originalMatrix != 0 && "LU is not initialized."); KernelResultType result(m_lu.cols(), dimensionOfKernel()); computeKernel(&result); return result; @@ -506,9 +514,7 @@ template template void LU::computeImage(ImageMatrixType *result) const { - // can be caused by a rank deficient matrix or by calling computeImage on an - // unitialized LU object - ei_assert(m_rank > 0 && "LU is not initialized or Matrix has rank zero."); + ei_assert(m_originalMatrix != 0 && "LU is not initialized."); result->resize(m_originalMatrix->rows(), m_rank); for(int i = 0; i < m_rank; ++i) result->col(i) = m_originalMatrix->col(m_q.coeff(i));