Add matrixR() to get the triangular factor from the Householder QR

This commit is contained in:
Desire NUENTSA 2013-02-20 13:58:26 +01:00
parent 962c99d462
commit bc18e06fe3

View File

@ -145,7 +145,21 @@ template<typename _MatrixType> class ColPivHouseholderQR
eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized."); eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized.");
return m_qr; return m_qr;
} }
/** \returns a reference to the matrix where the Householder QR is stored
* To get the triangular factor R, use
* \code matrixR().template triangularView<Upper>() \endcode
* For rank-deficient matrices, use
* \code
* matrixR().topLeftCorner(rank(), rank()).template triangularView<Upper>()
* \endcode
*/
const MatrixType& matrixR() const
{
eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized.");
return m_qr;
}
ColPivHouseholderQR& compute(const MatrixType& matrix); ColPivHouseholderQR& compute(const MatrixType& matrix);
const PermutationType& colsPermutation() const const PermutationType& colsPermutation() const
@ -336,6 +350,18 @@ template<typename _MatrixType> class ColPivHouseholderQR
* diagonal coefficient of R. * diagonal coefficient of R.
*/ */
RealScalar maxPivot() const { return m_maxpivot; } RealScalar maxPivot() const { return m_maxpivot; }
/** \brief Reports whether the QR factorization was succesful.
*
* \note This routine is provided for uniformity with other factorization modules
* \returns \c Success if computation was succesful,
* \c NumericalIssue if the QR can not be computed
*/
ComputationInfo info() const
{
eigen_assert(m_isInitialized && "Decomposition is not initialized.");
return Success;
}
protected: protected:
MatrixType m_qr; MatrixType m_qr;
@ -345,6 +371,7 @@ template<typename _MatrixType> class ColPivHouseholderQR
RowVectorType m_temp; RowVectorType m_temp;
RealRowVectorType m_colSqNorms; RealRowVectorType m_colSqNorms;
bool m_isInitialized, m_usePrescribedThreshold; bool m_isInitialized, m_usePrescribedThreshold;
mutable ComputationInfo m_info;
RealScalar m_prescribedThreshold, m_maxpivot; RealScalar m_prescribedThreshold, m_maxpivot;
Index m_nonzero_pivots; Index m_nonzero_pivots;
Index m_det_pq; Index m_det_pq;
@ -488,7 +515,7 @@ struct solve_retval<ColPivHouseholderQR<_MatrixType>, Rhs>
.transpose() .transpose()
); );
dec().matrixQR() dec().matrixR()
.topLeftCorner(nonzero_pivots, nonzero_pivots) .topLeftCorner(nonzero_pivots, nonzero_pivots)
.template triangularView<Upper>() .template triangularView<Upper>()
.solveInPlace(c.topRows(nonzero_pivots)); .solveInPlace(c.topRows(nonzero_pivots));