mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-05-02 16:54:10 +08:00
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.
This commit is contained in:
parent
b183a4f879
commit
014c581a5b
@ -103,9 +103,15 @@ template<typename MatrixType> class LU
|
|||||||
/** Constructor.
|
/** Constructor.
|
||||||
*
|
*
|
||||||
* \param matrix the matrix of which to compute the LU decomposition.
|
* \param matrix the matrix of which to compute the LU decomposition.
|
||||||
|
* It is required to be nonzero.
|
||||||
*/
|
*/
|
||||||
LU(const MatrixType& matrix);
|
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);
|
void compute(const MatrixType& matrix);
|
||||||
|
|
||||||
/** \returns the LU decomposition matrix: the upper-triangular part is U, the
|
/** \returns the LU decomposition matrix: the upper-triangular part is U, the
|
||||||
@ -317,6 +323,7 @@ template<typename MatrixType> class LU
|
|||||||
*/
|
*/
|
||||||
inline void computeInverse(MatrixType *result) const
|
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);
|
solve(MatrixType::Identity(m_lu.rows(), m_lu.cols()), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -461,7 +468,7 @@ template<typename MatrixType>
|
|||||||
template<typename KernelMatrixType>
|
template<typename KernelMatrixType>
|
||||||
void LU<MatrixType>::computeKernel(KernelMatrixType *result) const
|
void LU<MatrixType>::computeKernel(KernelMatrixType *result) const
|
||||||
{
|
{
|
||||||
ei_assert(!isInvertible());
|
ei_assert(m_originalMatrix != 0 && "LU is not initialized.");
|
||||||
const int dimker = dimensionOfKernel(), cols = m_lu.cols();
|
const int dimker = dimensionOfKernel(), cols = m_lu.cols();
|
||||||
result->resize(cols, dimker);
|
result->resize(cols, dimker);
|
||||||
|
|
||||||
@ -497,6 +504,7 @@ template<typename MatrixType>
|
|||||||
const typename LU<MatrixType>::KernelResultType
|
const typename LU<MatrixType>::KernelResultType
|
||||||
LU<MatrixType>::kernel() const
|
LU<MatrixType>::kernel() const
|
||||||
{
|
{
|
||||||
|
ei_assert(m_originalMatrix != 0 && "LU is not initialized.");
|
||||||
KernelResultType result(m_lu.cols(), dimensionOfKernel());
|
KernelResultType result(m_lu.cols(), dimensionOfKernel());
|
||||||
computeKernel(&result);
|
computeKernel(&result);
|
||||||
return result;
|
return result;
|
||||||
@ -506,9 +514,7 @@ template<typename MatrixType>
|
|||||||
template<typename ImageMatrixType>
|
template<typename ImageMatrixType>
|
||||||
void LU<MatrixType>::computeImage(ImageMatrixType *result) const
|
void LU<MatrixType>::computeImage(ImageMatrixType *result) const
|
||||||
{
|
{
|
||||||
// can be caused by a rank deficient matrix or by calling computeImage on an
|
ei_assert(m_originalMatrix != 0 && "LU is not initialized.");
|
||||||
// unitialized LU object
|
|
||||||
ei_assert(m_rank > 0 && "LU is not initialized or Matrix has rank zero.");
|
|
||||||
result->resize(m_originalMatrix->rows(), m_rank);
|
result->resize(m_originalMatrix->rows(), m_rank);
|
||||||
for(int i = 0; i < m_rank; ++i)
|
for(int i = 0; i < m_rank; ++i)
|
||||||
result->col(i) = m_originalMatrix->col(m_q.coeff(i));
|
result->col(i) = m_originalMatrix->col(m_q.coeff(i));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user