From 9ce1212d7cf1574d989a5e6269f0a614b4ce17ed Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 9 Feb 2010 14:28:22 +0100 Subject: [PATCH] For the record, here is a solution for (a*b).diagonal, at the cost of extra copies if a and/or b as to be evaluated. So in the next commit I'll remove it. A nice solution would be to evaluate the lhs/rhs into member of the initial product, but that would be overkill. --- Eigen/src/Core/ProductBase.h | 30 ++++++++++++--------- Eigen/src/Core/products/CoeffBasedProduct.h | 4 +++ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Eigen/src/Core/ProductBase.h b/Eigen/src/Core/ProductBase.h index 9fdb74f1c..4c95684f0 100644 --- a/Eigen/src/Core/ProductBase.h +++ b/Eigen/src/Core/ProductBase.h @@ -83,7 +83,11 @@ class ProductBase : public MatrixBase typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType; typedef typename ei_cleantype::type _ActualRhsType; - typedef typename ProductReturnType::Type LazyCoeffBaseProductType; + // 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; @@ -114,25 +118,25 @@ class ProductBase : public MatrixBase const _LhsNested& lhs() const { return m_lhs; } const _RhsNested& rhs() const { return m_rhs; } - const Diagonal diagonal() const - { return LazyCoeffBaseProductType(m_lhs, m_rhs); } + const Diagonal diagonal() const + { return NestedByValueLazyCoeffBaseProductType(m_lhs, m_rhs); } - Diagonal diagonal() - { return LazyCoeffBaseProductType(m_lhs, m_rhs); } + Diagonal diagonal() + { return NestedByValueLazyCoeffBaseProductType(m_lhs, m_rhs); } template - const Diagonal diagonal() const - { return LazyCoeffBaseProductType(m_lhs, m_rhs); } + const Diagonal diagonal() const + { return NestedByValueLazyCoeffBaseProductType(m_lhs, m_rhs); } template - Diagonal diagonal() - { return LazyCoeffBaseProductType(m_lhs, m_rhs); } + Diagonal diagonal() + { return NestedByValueLazyCoeffBaseProductType(m_lhs, m_rhs); } - const Diagonal diagonal(int index) const - { return LazyCoeffBaseProductType(m_lhs, m_rhs).diagonal(index); } + const Diagonal diagonal(int index) const + { return NestedByValueLazyCoeffBaseProductType(m_lhs, m_rhs).diagonal(index); } - Diagonal diagonal(int index) - { return LazyCoeffBaseProductType(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 c9d333072..af0d2e2a2 100644 --- a/Eigen/src/Core/products/CoeffBasedProduct.h +++ b/Eigen/src/Core/products/CoeffBasedProduct.h @@ -129,6 +129,10 @@ 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)