From aec07827197cbfa6457c1ef13a66061dc5991ffb Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Thu, 9 Dec 2010 03:47:35 -0500 Subject: [PATCH] fix the build of eigensolver_complex test. it was calling the .value() method on an inner product, and that was blocked in bad zero-sized case. fixed by adding the .value() method to DenseBase for all 1x1 expressions, and allowing coeff accessors in ProductBase for 1x1 expressions. --- Eigen/src/Core/DenseBase.h | 8 +++++++ Eigen/src/Core/Product.h | 2 -- Eigen/src/Core/ProductBase.h | 37 +++++++++++++++++++++++------- Eigen/src/Core/util/StaticAssert.h | 8 ++++++- 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/Eigen/src/Core/DenseBase.h b/Eigen/src/Core/DenseBase.h index 6e028cfac..bdd1291cf 100644 --- a/Eigen/src/Core/DenseBase.h +++ b/Eigen/src/Core/DenseBase.h @@ -422,6 +422,14 @@ template class DenseBase inline const WithFormat format(const IOFormat& fmt) const; + /** \returns the unique coefficient of a 1x1 expression */ + CoeffReturnType value() const + { + EIGEN_STATIC_ASSERT_SIZE_1x1(Derived) + eigen_assert(this->rows() == 1 && this->cols() == 1); + return derived().coeff(0,0); + } + /////////// Array module /////////// bool all(void) const; diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h index 35ed1cbd7..eacdccb9a 100644 --- a/Eigen/src/Core/Product.h +++ b/Eigen/src/Core/Product.h @@ -224,8 +224,6 @@ class GeneralProduct Base::coeffRef(0,0) = (lhs.transpose().cwiseProduct(rhs)).sum(); } - typename Base::Scalar value() const { return Base::coeff(0,0); } - /** Convertion to scalar */ operator const typename Base::Scalar() const { return Base::coeff(0,0); diff --git a/Eigen/src/Core/ProductBase.h b/Eigen/src/Core/ProductBase.h index db1de7f62..f4272e56f 100644 --- a/Eigen/src/Core/ProductBase.h +++ b/Eigen/src/Core/ProductBase.h @@ -142,20 +142,41 @@ class ProductBase : public MatrixBase const Diagonal diagonal(Index index) const { return FullyLazyCoeffBaseProductType(m_lhs, m_rhs).diagonal(index); } + // restrict coeff accessors to 1x1 expressions. No need to care about mutators here since this isnt a Lvalue expression + typename Base::CoeffReturnType coeff(Index row, Index col) const + { + EIGEN_STATIC_ASSERT_SIZE_1x1(Derived) + eigen_assert(this->rows() == 1 && this->cols() == 1); + return derived().coeff(row,col); + } + + typename Base::CoeffReturnType coeff(Index i) const + { + EIGEN_STATIC_ASSERT_SIZE_1x1(Derived) + eigen_assert(this->rows() == 1 && this->cols() == 1); + return derived().coeff(i); + } + + const Scalar& coeffRef(Index row, Index col) const + { + EIGEN_STATIC_ASSERT_SIZE_1x1(Derived) + eigen_assert(this->rows() == 1 && this->cols() == 1); + return derived().coeffRef(row,col); + } + + const Scalar& coeffRef(Index i) const + { + EIGEN_STATIC_ASSERT_SIZE_1x1(Derived) + eigen_assert(this->rows() == 1 && this->cols() == 1); + return derived().coeffRef(i); + } + protected: const LhsNested m_lhs; const RhsNested m_rhs; mutable PlainObject m_result; - - private: - - // discard coeff methods - void coeff(Index,Index) const; - void coeffRef(Index,Index); - void coeff(Index) const; - void coeffRef(Index); }; // here we need to overload the nested rule for products diff --git a/Eigen/src/Core/util/StaticAssert.h b/Eigen/src/Core/util/StaticAssert.h index 71e8eef1b..dbdf8b209 100644 --- a/Eigen/src/Core/util/StaticAssert.h +++ b/Eigen/src/Core/util/StaticAssert.h @@ -92,7 +92,8 @@ PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1, THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS, YOU_CANNOT_MIX_ARRAYS_AND_MATRICES, - YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION + YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION, + THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS }; }; @@ -177,4 +178,9 @@ EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1),\ YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES) +#define EIGEN_STATIC_ASSERT_SIZE_1x1(TYPE) \ + EIGEN_STATIC_ASSERT((TYPE::RowsAtCompileTime == 1 || TYPE::RowsAtCompileTime == Dynamic) && \ + (TYPE::ColsAtCompileTime == 1 || TYPE::ColsAtCompileTime == Dynamic), \ + THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS) + #endif // EIGEN_STATIC_ASSERT_H