diff --git a/Eigen/src/Core/AssignEvaluator.h b/Eigen/src/Core/AssignEvaluator.h index 7d1bb5cdd..9ae463018 100644 --- a/Eigen/src/Core/AssignEvaluator.h +++ b/Eigen/src/Core/AssignEvaluator.h @@ -3,7 +3,7 @@ // // Copyright (C) 2011 Benoit Jacob // Copyright (C) 2011 Gael Guennebaud -// Copyright (C) 2011 Jitse Niesen +// Copyright (C) 2011-2012 Jitse Niesen // // Eigen is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -606,11 +606,36 @@ struct copy_using_evaluator_impl -const DstXprType& copy_using_evaluator(const DstXprType& dst, const SrcXprType& src) +EIGEN_STRONG_INLINE +const DstXprType& copy_using_evaluator(const PlainObjectBase& dst, const EigenBase& src) { #ifdef EIGEN_DEBUG_ASSIGN internal::copy_using_evaluator_traits::debug(); #endif +#ifdef EIGEN_NO_AUTOMATIC_RESIZING + eigen_assert((dst.size()==0 || (IsVectorAtCompileTime ? (dst.size() == src.size()) + : (dst.rows() == src.rows() && dst.cols() == src.cols()))) + && "Size mismatch. Automatic resizing is disabled because EIGEN_NO_AUTOMATIC_RESIZING is defined"); +#else + dst.const_cast_derived().resizeLike(src.derived()); +#endif + return copy_using_evaluator_without_resizing(dst.const_cast_derived(), src.derived()); +} + +template +EIGEN_STRONG_INLINE +const DstXprType& copy_using_evaluator(const EigenBase& dst, const EigenBase& src) +{ + return copy_using_evaluator_without_resizing(dst.const_cast_derived(), src.derived()); +} + +template +const DstXprType& copy_using_evaluator_without_resizing(const DstXprType& dst, const SrcXprType& src) +{ +#ifdef EIGEN_DEBUG_ASSIGN + internal::copy_using_evaluator_traits::debug(); +#endif + eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); copy_using_evaluator_impl::run(const_cast(dst), src); return dst; } diff --git a/test/evaluators.cpp b/test/evaluators.cpp index 53556ae17..267509c91 100644 --- a/test/evaluators.cpp +++ b/test/evaluators.cpp @@ -88,6 +88,12 @@ void test_evaluators() ArrayXXd arr1(6,6), arr2(6,6); VERIFY_IS_APPROX_EVALUATOR(arr1, ArrayXXd::Constant(6,6, 3.0)); VERIFY_IS_APPROX_EVALUATOR(arr2, arr1); + + // test automatic resizing + mat2.resize(3,3); + VERIFY_IS_APPROX_EVALUATOR(mat2, mat1); + arr2.resize(9,9); + VERIFY_IS_APPROX_EVALUATOR(arr2, arr1); // test direct traversal Matrix3f m3; @@ -199,6 +205,8 @@ void test_evaluators() VERIFY_IS_APPROX_EVALUATOR(arr2, arr1.rowwise().reverse()); arr2.reverse() = arr1; VERIFY_IS_APPROX(arr2, arr1.reverse()); + mat2.array() = mat1.array().reverse(); + VERIFY_IS_APPROX(mat2.array(), mat1.array().reverse()); // test Diagonal VERIFY_IS_APPROX_EVALUATOR(vec1, mat1.diagonal());