fix the multiple temporary issue for nested products

This commit is contained in:
Gael Guennebaud 2010-02-09 09:58:34 +01:00
parent 8b016e717f
commit c076fec734
2 changed files with 21 additions and 2 deletions

View File

@ -490,7 +490,7 @@ class DenseStorageBase : public _Base<Derived>
return ei_assign_selector<Derived,OtherDerived,false>::run(this->derived(), other.derived());
}
static EIGEN_STRONG_INLINE void _check_template_params()
EIGEN_STRONG_INLINE void _check_template_params()
{
#ifdef EIGEN_DEBUG_MATRIX_CTOR
EIGEN_DEBUG_MATRIX_CTOR;

View File

@ -42,7 +42,8 @@ struct ei_traits<ProductBase<Derived,_Lhs,_Rhs> > //: ei_traits<typename ei_clea
ColsAtCompileTime = ei_traits<Rhs>::ColsAtCompileTime,
MaxRowsAtCompileTime = ei_traits<Lhs>::MaxRowsAtCompileTime,
MaxColsAtCompileTime = ei_traits<Rhs>::MaxColsAtCompileTime,
Flags = EvalBeforeNestingBit | EvalBeforeAssigningBit,
Flags = EvalBeforeNestingBit | EvalBeforeAssigningBit | NestByRefBit, // Note that EvalBeforeNestingBit and NestByRefBit
// are not used in practice because ei_nested is overloaded for products
CoeffReadCost = 0 // FIXME why is it needed ?
};
};
@ -137,11 +138,21 @@ class ProductBase : public MatrixBase<Derived>
Diagonal<LazyCoeffBaseProductType,Dynamic> diagonal(int index)
{ return Diagonal<LazyCoeffBaseProductType,Dynamic>(LazyCoeffBaseProductType(CoeffBaseProductType(m_lhs, m_rhs))).diagonal(index); }
// Implicit convertion to the nested type (trigger the evaluation of the product)
operator const PlainMatrixType& () const
{
m_result.resize(m_lhs.rows(), m_rhs.cols());
this->evalTo(m_result);
return m_result;
}
protected:
const LhsNested m_lhs;
const RhsNested m_rhs;
mutable PlainMatrixType m_result;
private:
// discard coeff methods
@ -151,6 +162,14 @@ class ProductBase : public MatrixBase<Derived>
void coeffRef(int);
};
// here we need to overload the nested rule for products
// such that the nested type is a const reference to a plain matrix
template<typename Lhs, typename Rhs, int Mode, int N, typename PlainMatrixType>
struct ei_nested<GeneralProduct<Lhs,Rhs,Mode>, N, PlainMatrixType>
{
typedef PlainMatrixType const& type;
};
template<typename NestedProduct>
class ScaledProduct;