fix compilation of "somedensematrix.llt().matrixL().transpose()" (missing constness on the return types)

This commit is contained in:
Gael Guennebaud 2012-04-10 15:40:36 +02:00
parent 311c5b87a3
commit b0cf95619e
4 changed files with 19 additions and 9 deletions

View File

@ -419,16 +419,16 @@ template<> struct ldlt_inplace<Upper>
template<typename MatrixType> struct LDLT_Traits<MatrixType,Lower> template<typename MatrixType> struct LDLT_Traits<MatrixType,Lower>
{ {
typedef TriangularView<const MatrixType, UnitLower> MatrixL; typedef const TriangularView<const MatrixType, UnitLower> MatrixL;
typedef TriangularView<const typename MatrixType::AdjointReturnType, UnitUpper> MatrixU; typedef const TriangularView<const typename MatrixType::AdjointReturnType, UnitUpper> MatrixU;
static inline MatrixL getL(const MatrixType& m) { return m; } static inline MatrixL getL(const MatrixType& m) { return m; }
static inline MatrixU getU(const MatrixType& m) { return m.adjoint(); } static inline MatrixU getU(const MatrixType& m) { return m.adjoint(); }
}; };
template<typename MatrixType> struct LDLT_Traits<MatrixType,Upper> template<typename MatrixType> struct LDLT_Traits<MatrixType,Upper>
{ {
typedef TriangularView<const typename MatrixType::AdjointReturnType, UnitLower> MatrixL; typedef const TriangularView<const typename MatrixType::AdjointReturnType, UnitLower> MatrixL;
typedef TriangularView<const MatrixType, UnitUpper> MatrixU; typedef const TriangularView<const MatrixType, UnitUpper> MatrixU;
static inline MatrixL getL(const MatrixType& m) { return m.adjoint(); } static inline MatrixL getL(const MatrixType& m) { return m.adjoint(); }
static inline MatrixU getU(const MatrixType& m) { return m; } static inline MatrixU getU(const MatrixType& m) { return m; }
}; };

View File

@ -365,8 +365,8 @@ template<typename Scalar> struct llt_inplace<Scalar, Upper>
template<typename MatrixType> struct LLT_Traits<MatrixType,Lower> template<typename MatrixType> struct LLT_Traits<MatrixType,Lower>
{ {
typedef TriangularView<const MatrixType, Lower> MatrixL; typedef const TriangularView<const MatrixType, Lower> MatrixL;
typedef TriangularView<const typename MatrixType::AdjointReturnType, Upper> MatrixU; typedef const TriangularView<const typename MatrixType::AdjointReturnType, Upper> MatrixU;
static inline MatrixL getL(const MatrixType& m) { return m; } static inline MatrixL getL(const MatrixType& m) { return m; }
static inline MatrixU getU(const MatrixType& m) { return m.adjoint(); } static inline MatrixU getU(const MatrixType& m) { return m.adjoint(); }
static bool inplace_decomposition(MatrixType& m) static bool inplace_decomposition(MatrixType& m)
@ -375,8 +375,8 @@ template<typename MatrixType> struct LLT_Traits<MatrixType,Lower>
template<typename MatrixType> struct LLT_Traits<MatrixType,Upper> template<typename MatrixType> struct LLT_Traits<MatrixType,Upper>
{ {
typedef TriangularView<const typename MatrixType::AdjointReturnType, Lower> MatrixL; typedef const TriangularView<const typename MatrixType::AdjointReturnType, Lower> MatrixL;
typedef TriangularView<const MatrixType, Upper> MatrixU; typedef const TriangularView<const MatrixType, Upper> MatrixU;
static inline MatrixL getL(const MatrixType& m) { return m.adjoint(); } static inline MatrixL getL(const MatrixType& m) { return m.adjoint(); }
static inline MatrixU getU(const MatrixType& m) { return m; } static inline MatrixU getU(const MatrixType& m) { return m; }
static bool inplace_decomposition(MatrixType& m) static bool inplace_decomposition(MatrixType& m)

View File

@ -71,7 +71,7 @@ template<> struct llt_inplace<EIGTYPE, Lower> \
} \ } \
template<typename MatrixType, typename VectorType> \ template<typename MatrixType, typename VectorType> \
static typename MatrixType::Index rankUpdate(MatrixType& mat, const VectorType& vec, const typename MatrixType::RealScalar& sigma) \ static typename MatrixType::Index rankUpdate(MatrixType& mat, const VectorType& vec, const typename MatrixType::RealScalar& sigma) \
{ return llt_rank_update_lower(mat, vec, sigma); } \ { return Eigen::internal::llt_rank_update_lower(mat, vec, sigma); } \
}; \ }; \
template<> struct llt_inplace<EIGTYPE, Upper> \ template<> struct llt_inplace<EIGTYPE, Upper> \
{ \ { \

View File

@ -124,6 +124,11 @@ template<typename MatrixType> void cholesky(const MatrixType& m)
MatrixType neg = -symmLo; MatrixType neg = -symmLo;
chollo.compute(neg); chollo.compute(neg);
VERIFY(chollo.info()==NumericalIssue); VERIFY(chollo.info()==NumericalIssue);
VERIFY_IS_APPROX(MatrixType(chollo.matrixL().transpose().conjugate()), MatrixType(chollo.matrixU()));
VERIFY_IS_APPROX(MatrixType(chollo.matrixU().transpose().conjugate()), MatrixType(chollo.matrixL()));
VERIFY_IS_APPROX(MatrixType(cholup.matrixL().transpose().conjugate()), MatrixType(cholup.matrixU()));
VERIFY_IS_APPROX(MatrixType(cholup.matrixU().transpose().conjugate()), MatrixType(cholup.matrixL()));
} }
// LDLT // LDLT
@ -152,6 +157,11 @@ template<typename MatrixType> void cholesky(const MatrixType& m)
matX = ldltup.solve(matB); matX = ldltup.solve(matB);
VERIFY_IS_APPROX(symm * matX, matB); VERIFY_IS_APPROX(symm * matX, matB);
VERIFY_IS_APPROX(MatrixType(ldltlo.matrixL().transpose().conjugate()), MatrixType(ldltlo.matrixU()));
VERIFY_IS_APPROX(MatrixType(ldltlo.matrixU().transpose().conjugate()), MatrixType(ldltlo.matrixL()));
VERIFY_IS_APPROX(MatrixType(ldltup.matrixL().transpose().conjugate()), MatrixType(ldltup.matrixU()));
VERIFY_IS_APPROX(MatrixType(ldltup.matrixU().transpose().conjugate()), MatrixType(ldltup.matrixL()));
if(MatrixType::RowsAtCompileTime==Dynamic) if(MatrixType::RowsAtCompileTime==Dynamic)
{ {
// note : each inplace permutation requires a small temporary vector (mask) // note : each inplace permutation requires a small temporary vector (mask)