From 0543cb51b58bfc5130bcb0b83969f2854f30d58e Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 18 Feb 2014 14:51:41 +0100 Subject: Product::coeff method are also OK for lazy products (including diagonal products) --- Eigen/src/Core/Product.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'Eigen/src/Core/Product.h') diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h index 12726ed12..31730983f 100644 --- a/Eigen/src/Core/Product.h +++ b/Eigen/src/Core/Product.h @@ -117,27 +117,38 @@ template class ProductImpl : public internal::dense_product_base { - typedef Product Derived; + typedef Product Derived; + public: typedef typename internal::dense_product_base Base; EIGEN_DENSE_PUBLIC_INTERFACE(Derived) + protected: + enum { + IsOneByOne = (RowsAtCompileTime == 1 || RowsAtCompileTime == Dynamic) && + (ColsAtCompileTime == 1 || ColsAtCompileTime == Dynamic), + EnableCoeff = IsOneByOne || Option==LazyProduct + }; + public: + Scalar coeff(Index row, Index col) const { - EIGEN_STATIC_ASSERT_SIZE_1x1(Derived) - eigen_assert(this->rows() == 1 && this->cols() == 1); + EIGEN_STATIC_ASSERT(EnableCoeff, THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS); + eigen_assert( (Option==LazyProduct) || (this->rows() == 1 && this->cols() == 1) ); return typename internal::evaluator::type(derived()).coeff(row,col); } Scalar coeff(Index i) const { - EIGEN_STATIC_ASSERT_SIZE_1x1(Derived) - eigen_assert(this->rows() == 1 && this->cols() == 1); + EIGEN_STATIC_ASSERT(EnableCoeff, THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS); + eigen_assert( (Option==LazyProduct) || (this->rows() == 1 && this->cols() == 1) ); return typename internal::evaluator::type(derived()).coeff(i); } + + }; /*************************************************************************** -- cgit v1.2.3