diff --git a/Eigen/src/Core/ArrayWrapper.h b/Eigen/src/Core/ArrayWrapper.h index 8774b8b29..1e021b0b9 100644 --- a/Eigen/src/Core/ArrayWrapper.h +++ b/Eigen/src/Core/ArrayWrapper.h @@ -121,6 +121,13 @@ class ArrayWrapper : public ArrayBase > return m_expression; } + /** Forwards the resizing request to the nested expression + * \sa DenseBase::resize(Index) */ + void resize(Index newSize) { m_expression.const_cast_derived().resize(newSize); } + /** Forwards the resizing request to the nested expression + * \sa DenseBase::resize(Index,Index)*/ + void resize(Index nbRows, Index nbCols) { m_expression.const_cast_derived().resize(nbRows,nbCols); } + protected: NestedExpressionType m_expression; }; @@ -231,6 +238,13 @@ class MatrixWrapper : public MatrixBase > return m_expression; } + /** Forwards the resizing request to the nested expression + * \sa DenseBase::resize(Index) */ + void resize(Index newSize) { m_expression.const_cast_derived().resize(newSize); } + /** Forwards the resizing request to the nested expression + * \sa DenseBase::resize(Index,Index)*/ + void resize(Index nbRows, Index nbCols) { m_expression.const_cast_derived().resize(nbRows,nbCols); } + protected: NestedExpressionType m_expression; }; diff --git a/test/array_for_matrix.cpp b/test/array_for_matrix.cpp index 4b637c3a6..a9cd54294 100644 --- a/test/array_for_matrix.cpp +++ b/test/array_for_matrix.cpp @@ -170,6 +170,32 @@ template void cwise_min_max(const MatrixType& m) } +template void resize(const MatrixTraits& t) +{ + typedef typename MatrixTraits::Index Index; + typedef typename MatrixTraits::Scalar Scalar; + typedef Matrix MatrixType; + typedef Array Array2DType; + typedef Matrix VectorType; + typedef Array Array1DType; + + Index rows = t.rows(), cols = t.cols(); + + MatrixType m(rows,cols); + VectorType v(rows); + Array2DType a2(rows,cols); + Array1DType a1(rows); + + m.array().resize(rows+1,cols+1); + VERIFY(m.rows()==rows+1 && m.cols()==cols+1); + a2.matrix().resize(rows+1,cols+1); + VERIFY(a2.rows()==rows+1 && a2.cols()==cols+1); + v.array().resize(cols); + VERIFY(v.size()==cols); + a1.matrix().resize(cols); + VERIFY(a1.size()==cols); +} + void test_array_for_matrix() { for(int i = 0; i < g_repeat; i++) { @@ -202,4 +228,9 @@ void test_array_for_matrix() CALL_SUBTEST_5( lpNorm(VectorXf(internal::random(1,EIGEN_TEST_MAX_SIZE))) ); CALL_SUBTEST_4( lpNorm(VectorXcf(internal::random(1,EIGEN_TEST_MAX_SIZE))) ); } + for(int i = 0; i < g_repeat; i++) { + CALL_SUBTEST_4( resize(MatrixXcf(internal::random(1,EIGEN_TEST_MAX_SIZE), internal::random(1,EIGEN_TEST_MAX_SIZE))) ); + 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))) ); + } }