From a443b3d98df5e92804db8b0818f3d0bdf5f3772d Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sat, 7 Sep 2013 00:01:04 +0200 Subject: [PATCH] Fix bug #654: allow implicit transposition in Array to Matrix and Matrix to Array constructors (grafted from 07417bd03f501efd276302123eb77b2f5a1a67b7 ) --- Eigen/src/Core/Array.h | 2 +- Eigen/src/Core/Matrix.h | 2 +- test/array_for_matrix.cpp | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Eigen/src/Core/Array.h b/Eigen/src/Core/Array.h index 497efff66..0ab03eff0 100644 --- a/Eigen/src/Core/Array.h +++ b/Eigen/src/Core/Array.h @@ -210,7 +210,7 @@ class Array : Base(other.derived().rows() * other.derived().cols(), other.derived().rows(), other.derived().cols()) { Base::_check_template_params(); - Base::resize(other.rows(), other.cols()); + Base::_resize_to_match(other); *this = other; } diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h index 0ba5d90cc..d7d0b5b9a 100644 --- a/Eigen/src/Core/Matrix.h +++ b/Eigen/src/Core/Matrix.h @@ -304,7 +304,7 @@ class Matrix : Base(other.derived().rows() * other.derived().cols(), other.derived().rows(), other.derived().cols()) { Base::_check_template_params(); - Base::resize(other.rows(), other.cols()); + Base::_resize_to_match(other); // FIXME/CHECK: isn't *this = other.derived() more efficient. it allows to // go for pure _set() implementations, right? *this = other; diff --git a/test/array_for_matrix.cpp b/test/array_for_matrix.cpp index 1250c9ff5..67e7a2a44 100644 --- a/test/array_for_matrix.cpp +++ b/test/array_for_matrix.cpp @@ -202,6 +202,12 @@ template void resize(const MatrixTraits& t) VERIFY(a1.size()==cols); } +void regression_bug_654() +{ + ArrayXf a = RowVectorXf(3); + VectorXf v = Array(3); +} + void test_array_for_matrix() { for(int i = 0; i < g_repeat; i++) { @@ -239,4 +245,5 @@ void test_array_for_matrix() CALL_SUBTEST_5( resize(MatrixXf(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); CALL_SUBTEST_6( resize(MatrixXi(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); } + CALL_SUBTEST_6( regression_bug_654() ); }