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.
This commit is contained in:
Gael Guennebaud 2010-02-09 14:28:22 +01:00
parent 0a680a9857
commit 9ce1212d7c
2 changed files with 21 additions and 13 deletions

View File

@ -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

View File

@ -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)