From 840977529fd0e674e46a7cb6c5a5519c403b05bc Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 9 Feb 2010 14:34:31 +0100 Subject: * as promised, remove the "optimization" for Product::diagonal() * add MatrixBase::lazyProduct --- Eigen/src/Core/MatrixBase.h | 4 ++++ Eigen/src/Core/Product.h | 25 +++++++++++++++++++++++++ Eigen/src/Core/ProductBase.h | 25 ------------------------- Eigen/src/Core/products/CoeffBasedProduct.h | 4 ---- 4 files changed, 29 insertions(+), 29 deletions(-) (limited to 'Eigen/src') diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index e599a9e03..65b3bfb7c 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -188,6 +188,10 @@ template class MatrixBase const typename ProductReturnType::Type operator*(const MatrixBase &other) const; + template + const typename ProductReturnType::Type + lazyProduct(const MatrixBase &other) const; + template Derived& operator*=(const AnyMatrixBase& other); diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h index 07aeae165..304dbc3ee 100644 --- a/Eigen/src/Core/Product.h +++ b/Eigen/src/Core/Product.h @@ -445,4 +445,29 @@ MatrixBase::operator*(const MatrixBase &other) const return typename ProductReturnType::Type(derived(), other.derived()); } + +template +template +const typename ProductReturnType::Type +MatrixBase::lazyProduct(const MatrixBase &other) const +{ + enum { + ProductIsValid = Derived::ColsAtCompileTime==Dynamic + || OtherDerived::RowsAtCompileTime==Dynamic + || int(Derived::ColsAtCompileTime)==int(OtherDerived::RowsAtCompileTime), + AreVectors = Derived::IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime, + SameSizes = EIGEN_PREDICATE_SAME_MATRIX_SIZE(Derived,OtherDerived) + }; + // note to the lost user: + // * for a dot product use: v1.dot(v2) + // * for a coeff-wise product use: v1.cwiseProduct(v2) + EIGEN_STATIC_ASSERT(ProductIsValid || !(AreVectors && SameSizes), + INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS) + EIGEN_STATIC_ASSERT(ProductIsValid || !(SameSizes && !AreVectors), + INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION) + EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT) + + return typename ProductReturnType::Type(derived(), other.derived()); +} + #endif // EIGEN_PRODUCT_H diff --git a/Eigen/src/Core/ProductBase.h b/Eigen/src/Core/ProductBase.h index 4c95684f0..bbd77f059 100644 --- a/Eigen/src/Core/ProductBase.h +++ b/Eigen/src/Core/ProductBase.h @@ -83,11 +83,6 @@ class ProductBase : public MatrixBase typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType; typedef typename ei_cleantype::type _ActualRhsType; - // here we don't use ProductReturnType::Type because we must nest it by value. - typedef typename ei_nested<_LhsNested, _RhsNested::ColsAtCompileTime, typename ei_plain_matrix_type<_LhsNested>::type >::type LazyLhsNested; - typedef typename ei_nested<_RhsNested, _LhsNested::RowsAtCompileTime, typename ei_plain_matrix_type<_RhsNested>::type >::type LazyRhsNested; - typedef CoeffBasedProduct NestedByValueLazyCoeffBaseProductType; - public: typedef typename Base::PlainMatrixType PlainMatrixType; @@ -118,26 +113,6 @@ class ProductBase : public MatrixBase const _LhsNested& lhs() const { return m_lhs; } const _RhsNested& rhs() const { return m_rhs; } - const Diagonal diagonal() const - { return NestedByValueLazyCoeffBaseProductType(m_lhs, m_rhs); } - - Diagonal diagonal() - { return NestedByValueLazyCoeffBaseProductType(m_lhs, m_rhs); } - - template - const Diagonal diagonal() const - { return NestedByValueLazyCoeffBaseProductType(m_lhs, m_rhs); } - - template - Diagonal diagonal() - { return NestedByValueLazyCoeffBaseProductType(m_lhs, m_rhs); } - - const Diagonal diagonal(int index) const - { return NestedByValueLazyCoeffBaseProductType(m_lhs, m_rhs).diagonal(index); } - - Diagonal diagonal(int index) - { return NestedByValueLazyCoeffBaseProductType(m_lhs, m_rhs).diagonal(index); } - // Implicit convertion to the nested type (trigger the evaluation of the product) operator const PlainMatrixType& () const { diff --git a/Eigen/src/Core/products/CoeffBasedProduct.h b/Eigen/src/Core/products/CoeffBasedProduct.h index af0d2e2a2..c9d333072 100644 --- a/Eigen/src/Core/products/CoeffBasedProduct.h +++ b/Eigen/src/Core/products/CoeffBasedProduct.h @@ -129,10 +129,6 @@ class CoeffBasedProduct public: - inline CoeffBasedProduct(const CoeffBasedProduct& other) - : Base(), m_lhs(other.m_lhs), m_rhs(other.m_rhs) - {} - template inline CoeffBasedProduct(const Lhs& lhs, const Rhs& rhs) : m_lhs(lhs), m_rhs(rhs) -- cgit v1.2.3