diff --git a/Eigen/src/Core/SelfAdjointView.h b/Eigen/src/Core/SelfAdjointView.h index 92d58b9f8..0e9872bf5 100644 --- a/Eigen/src/Core/SelfAdjointView.h +++ b/Eigen/src/Core/SelfAdjointView.h @@ -46,14 +46,14 @@ template struct traits > : traits { typedef typename nested::type MatrixTypeNested; - typedef typename remove_reference::type _MatrixTypeNested; + typedef typename remove_all::type MatrixTypeNestedCleaned; typedef MatrixType ExpressionType; typedef typename MatrixType::PlainObject DenseMatrixType; enum { Mode = UpLo | SelfAdjoint, - Flags = _MatrixTypeNested::Flags & (HereditaryBits) + Flags = MatrixTypeNestedCleaned::Flags & (HereditaryBits) & (~(PacketAccessBit | DirectAccessBit | LinearAccessBit)), // FIXME these flags should be preserved - CoeffReadCost = _MatrixTypeNested::CoeffReadCost + CoeffReadCost = MatrixTypeNestedCleaned::CoeffReadCost }; }; } @@ -69,6 +69,8 @@ template class SelfAdjointView public: typedef TriangularBase Base; + typedef typename internal::traits::MatrixTypeNested MatrixTypeNested; + typedef typename internal::traits::MatrixTypeNestedCleaned MatrixTypeNestedCleaned; /** \brief The type of coefficients in this matrix */ typedef typename internal::traits::Scalar Scalar; @@ -107,10 +109,10 @@ template class SelfAdjointView } /** \internal */ - const MatrixType& _expression() const { return m_matrix; } + const MatrixTypeNestedCleaned& _expression() const { return m_matrix; } - const MatrixType& nestedExpression() const { return m_matrix; } - MatrixType& nestedExpression() { return const_cast(m_matrix); } + const MatrixTypeNestedCleaned& nestedExpression() const { return m_matrix; } + MatrixTypeNestedCleaned& nestedExpression() { return *const_cast(&m_matrix); } /** Efficient self-adjoint matrix times vector/matrix product */ template @@ -197,7 +199,7 @@ template class SelfAdjointView #endif protected: - const typename MatrixType::Nested m_matrix; + const MatrixTypeNested m_matrix; }; diff --git a/Eigen/src/Core/TriangularMatrix.h b/Eigen/src/Core/TriangularMatrix.h index 714d56a5b..62586058b 100644 --- a/Eigen/src/Core/TriangularMatrix.h +++ b/Eigen/src/Core/TriangularMatrix.h @@ -143,13 +143,14 @@ template struct traits > : traits { typedef typename nested::type MatrixTypeNested; - typedef typename remove_reference::type _MatrixTypeNested; + typedef typename remove_reference::type MatrixTypeNestedNonRef; + typedef typename remove_all::type MatrixTypeNestedCleaned; typedef MatrixType ExpressionType; typedef typename MatrixType::PlainObject DenseMatrixType; enum { Mode = _Mode, - Flags = (_MatrixTypeNested::Flags & (HereditaryBits) & (~(PacketAccessBit | DirectAccessBit | LinearAccessBit))) | Mode, - CoeffReadCost = _MatrixTypeNested::CoeffReadCost + Flags = (MatrixTypeNestedCleaned::Flags & (HereditaryBits) & (~(PacketAccessBit | DirectAccessBit | LinearAccessBit))) | Mode, + CoeffReadCost = MatrixTypeNestedCleaned::CoeffReadCost }; }; } @@ -171,8 +172,10 @@ template class TriangularView typedef typename internal::traits::DenseMatrixType DenseMatrixType; protected: - typedef typename MatrixType::Nested MatrixTypeNested; - typedef typename internal::remove_all::type _MatrixTypeNested; + typedef typename internal::traits::MatrixTypeNested MatrixTypeNested; + typedef typename internal::traits::MatrixTypeNestedNonRef MatrixTypeNestedNonRef; + typedef typename internal::traits::MatrixTypeNestedCleaned MatrixTypeNestedCleaned; + typedef typename internal::remove_all::type MatrixConjugateReturnType; public: @@ -344,15 +347,15 @@ template class TriangularView void solveInPlace(const MatrixBase& other) const { return solveInPlace(other); } - const SelfAdjointView<_MatrixTypeNested,Mode> selfadjointView() const + const SelfAdjointView selfadjointView() const { EIGEN_STATIC_ASSERT((Mode&UnitDiag)==0,PROGRAMMING_ERROR); - return SelfAdjointView<_MatrixTypeNested,Mode>(m_matrix); + return SelfAdjointView(m_matrix); } - SelfAdjointView<_MatrixTypeNested,Mode> selfadjointView() + SelfAdjointView selfadjointView() { EIGEN_STATIC_ASSERT((Mode&UnitDiag)==0,PROGRAMMING_ERROR); - return SelfAdjointView<_MatrixTypeNested,Mode>(m_matrix); + return SelfAdjointView(m_matrix); } template @@ -694,7 +697,7 @@ void TriangularBase::evalToLazy(MatrixBase &other) const eigen_assert(this->rows() == other.rows() && this->cols() == other.cols()); internal::triangular_assignment_selector - ::ExpressionType, Derived::Mode, + ::MatrixTypeNestedCleaned, Derived::Mode, unroll ? int(DenseDerived::SizeAtCompileTime) : Dynamic, true // clear the opposite triangular part >::run(other.derived(), derived().nestedExpression()); diff --git a/test/selfadjoint.cpp b/test/selfadjoint.cpp index a92ad96b5..622045f20 100644 --- a/test/selfadjoint.cpp +++ b/test/selfadjoint.cpp @@ -52,6 +52,11 @@ template void selfadjoint(const MatrixType& m) VERIFY_IS_APPROX(m3, m3.adjoint()); } +void bug_159() +{ + Matrix3d m = Matrix3d::Random().selfadjointView(); +} + void test_selfadjoint() { for(int i = 0; i < g_repeat ; i++) @@ -64,4 +69,6 @@ void test_selfadjoint() CALL_SUBTEST_4( selfadjoint(MatrixXcd(s,s)) ); CALL_SUBTEST_5( selfadjoint(Matrix(s, s)) ); } + + CALL_SUBTEST_1( bug_159() ); }