finally here is a simple solution making (a*b).diagonal() even faster than a.lazyProduct(b).diagonal() !!

This commit is contained in:
Gael Guennebaud
2010-02-10 14:08:47 +01:00
parent 71b64d3498
commit 0ca67afe6a
4 changed files with 40 additions and 12 deletions

View File

@@ -83,6 +83,9 @@ class ProductBase : public MatrixBase<Derived>
typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType;
typedef typename ei_cleantype<ActualRhsType>::type _ActualRhsType;
// Diagonal of a product: no need to evaluate the arguments because they are going to be evaluated only once
typedef CoeffBasedProduct<LhsNested, RhsNested, 0> FullyLazyCoeffBaseProductType;
public:
typedef typename Base::PlainMatrixType PlainMatrixType;
@@ -121,6 +124,16 @@ class ProductBase : public MatrixBase<Derived>
return m_result;
}
const Diagonal<FullyLazyCoeffBaseProductType,0> diagonal() const
{ return FullyLazyCoeffBaseProductType(m_lhs, m_rhs); }
template<int Index>
const Diagonal<FullyLazyCoeffBaseProductType,Index> diagonal() const
{ return FullyLazyCoeffBaseProductType(m_lhs, m_rhs); }
const Diagonal<FullyLazyCoeffBaseProductType,Dynamic> diagonal(int index) const
{ return FullyLazyCoeffBaseProductType(m_lhs, m_rhs).diagonal(index); }
protected:
const LhsNested m_lhs;