From 313eea8f10b79eca013d5fc983f2e7f9fea1eb5b Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Wed, 26 Jan 2011 10:01:18 -0500 Subject: [PATCH] fix the remainder of bug #159 --- Eigen/src/Core/TriangularMatrix.h | 4 ++-- test/eigen2/eigen2_triangular.cpp | 6 ++++++ test/triangular.cpp | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Eigen/src/Core/TriangularMatrix.h b/Eigen/src/Core/TriangularMatrix.h index 62586058b..40dd2e4bc 100644 --- a/Eigen/src/Core/TriangularMatrix.h +++ b/Eigen/src/Core/TriangularMatrix.h @@ -238,8 +238,8 @@ template class TriangularView return m_matrix.const_cast_derived().coeffRef(row, col); } - 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); } /** Assigns a triangular matrix to a triangular part of a dense matrix */ template diff --git a/test/eigen2/eigen2_triangular.cpp b/test/eigen2/eigen2_triangular.cpp index 43b42e3a5..30ef1b20b 100644 --- a/test/eigen2/eigen2_triangular.cpp +++ b/test/eigen2/eigen2_triangular.cpp @@ -150,6 +150,12 @@ void selfadjoint() ref3 << 1, 0, 0, 4; VERIFY(m3 == ref3); + + // example inspired from bug 159 + int array[] = {1, 2, 3, 4}; + Matrix2i::Map(array).part() = Matrix2i::Random().part(); + + std::cout << "hello\n" << array << std::endl; } void test_eigen2_triangular() diff --git a/test/triangular.cpp b/test/triangular.cpp index 0c69749e0..69decb793 100644 --- a/test/triangular.cpp +++ b/test/triangular.cpp @@ -235,6 +235,11 @@ template void triangular_rect(const MatrixType& m) VERIFY_IS_APPROX(m2,m3); } +void bug_159() +{ + Matrix3d m = Matrix3d::Random().triangularView(); +} + void test_triangular() { for(int i = 0; i < g_repeat ; i++) @@ -255,4 +260,6 @@ void test_triangular() CALL_SUBTEST_5( triangular_rect(MatrixXcd(r, c)) ); CALL_SUBTEST_6( triangular_rect(Matrix(r, c)) ); } + + CALL_SUBTEST_1( bug_159() ); }