diff options
author | Gael Guennebaud <g.gael@free.fr> | 2010-02-09 14:28:22 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2010-02-09 14:28:22 +0100 |
commit | 9ce1212d7cf1574d989a5e6269f0a614b4ce17ed (patch) | |
tree | 57eba763ba1120b0ec07553d07636ea63608e8fd /Eigen | |
parent | 0a680a9857033dd0c3c86ca06e1357881124959f (diff) |
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.
Diffstat (limited to 'Eigen')
-rw-r--r-- | Eigen/src/Core/ProductBase.h | 30 | ||||
-rw-r--r-- | 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<Derived> typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType; typedef typename ei_cleantype<ActualRhsType>::type _ActualRhsType; - typedef typename ProductReturnType<Lhs,Rhs,LazyCoeffBasedProductMode>::Type LazyCoeffBaseProductType; + // here we don't use ProductReturnType<LazyCoeffBasedProductMode>::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<LazyLhsNested, LazyRhsNested, 0> NestedByValueLazyCoeffBaseProductType; + public: typedef typename Base::PlainMatrixType PlainMatrixType; @@ -114,25 +118,25 @@ class ProductBase : public MatrixBase<Derived> const _LhsNested& lhs() const { return m_lhs; } const _RhsNested& rhs() const { return m_rhs; } - const Diagonal<LazyCoeffBaseProductType,0> diagonal() const - { return LazyCoeffBaseProductType(m_lhs, m_rhs); } + const Diagonal<NestedByValueLazyCoeffBaseProductType,0> diagonal() const + { return NestedByValueLazyCoeffBaseProductType(m_lhs, m_rhs); } - Diagonal<LazyCoeffBaseProductType,0> diagonal() - { return LazyCoeffBaseProductType(m_lhs, m_rhs); } + Diagonal<NestedByValueLazyCoeffBaseProductType,0> diagonal() + { return NestedByValueLazyCoeffBaseProductType(m_lhs, m_rhs); } template<int Index> - const Diagonal<LazyCoeffBaseProductType,Index> diagonal() const - { return LazyCoeffBaseProductType(m_lhs, m_rhs); } + const Diagonal<NestedByValueLazyCoeffBaseProductType,Index> diagonal() const + { return NestedByValueLazyCoeffBaseProductType(m_lhs, m_rhs); } template<int Index> - Diagonal<LazyCoeffBaseProductType,Index> diagonal() - { return LazyCoeffBaseProductType(m_lhs, m_rhs); } + Diagonal<NestedByValueLazyCoeffBaseProductType,Index> diagonal() + { return NestedByValueLazyCoeffBaseProductType(m_lhs, m_rhs); } - const Diagonal<LazyCoeffBaseProductType,Dynamic> diagonal(int index) const - { return LazyCoeffBaseProductType(m_lhs, m_rhs).diagonal(index); } + const Diagonal<NestedByValueLazyCoeffBaseProductType,Dynamic> diagonal(int index) const + { return NestedByValueLazyCoeffBaseProductType(m_lhs, m_rhs).diagonal(index); } - Diagonal<LazyCoeffBaseProductType,Dynamic> diagonal(int index) - { return LazyCoeffBaseProductType(m_lhs, m_rhs).diagonal(index); } + Diagonal<NestedByValueLazyCoeffBaseProductType,Dynamic> 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<typename Lhs, typename Rhs> inline CoeffBasedProduct(const Lhs& lhs, const Rhs& rhs) : m_lhs(lhs), m_rhs(rhs) |