diff options
author | Gael Guennebaud <g.gael@free.fr> | 2010-02-09 09:58:34 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2010-02-09 09:58:34 +0100 |
commit | c076fec7340c35120f807d7a5fd7111064a30737 (patch) | |
tree | 45594589787a72560e2beb06bb96c18c14052fac /Eigen/src | |
parent | 8b016e717fdcbf4f9be34997bb857f52ca34a5b8 (diff) |
fix the multiple temporary issue for nested products
Diffstat (limited to 'Eigen/src')
-rw-r--r-- | Eigen/src/Core/DenseStorageBase.h | 2 | ||||
-rw-r--r-- | Eigen/src/Core/ProductBase.h | 21 |
2 files changed, 21 insertions, 2 deletions
diff --git a/Eigen/src/Core/DenseStorageBase.h b/Eigen/src/Core/DenseStorageBase.h index f3d6e8944..313ac037c 100644 --- a/Eigen/src/Core/DenseStorageBase.h +++ b/Eigen/src/Core/DenseStorageBase.h @@ -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; diff --git a/Eigen/src/Core/ProductBase.h b/Eigen/src/Core/ProductBase.h index 5c51ea27c..fa3207f65 100644 --- a/Eigen/src/Core/ProductBase.h +++ b/Eigen/src/Core/ProductBase.h @@ -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; |