diff options
author | 2010-02-04 18:28:09 +0100 | |
---|---|---|
committer | 2010-02-04 18:28:09 +0100 | |
commit | 73eb0e633c506e86f20fa231269b5cd81ebd083c (patch) | |
tree | 2a0b10d92246f613831d0292022bba847f026a24 /Eigen/src | |
parent | b44240180fdefc07fb576cc107c99aa60989eba9 (diff) |
* resurected Flagged from Eigen2Support
* reimplement .diagonal() for ProductBase to make (A*B).diagonal() more efficient!
Diffstat (limited to 'Eigen/src')
-rw-r--r-- | Eigen/src/Core/Flagged.h (renamed from Eigen/src/Eigen2Support/Flagged.h) | 58 | ||||
-rw-r--r-- | Eigen/src/Core/Product.h | 2 | ||||
-rw-r--r-- | Eigen/src/Core/ProductBase.h | 28 | ||||
-rw-r--r-- | Eigen/src/Eigen2Support/Lazy.h | 82 |
4 files changed, 110 insertions, 60 deletions
diff --git a/Eigen/src/Eigen2Support/Flagged.h b/Eigen/src/Core/Flagged.h index 470db1d7b..af00a68be 100644 --- a/Eigen/src/Eigen2Support/Flagged.h +++ b/Eigen/src/Core/Flagged.h @@ -25,9 +25,7 @@ #ifndef EIGEN_FLAGGED_H #define EIGEN_FLAGGED_H -/** \deprecated it is only used by lazy() which is deprecated - * - * \class Flagged +/** \class Flagged * * \brief Expression with modified flags * @@ -120,58 +118,4 @@ template<typename ExpressionType, unsigned int Added, unsigned int Removed> clas ExpressionTypeNested m_matrix; }; -/** \deprecated it is only used by lazy() which is deprecated - * - * \returns an expression of *this with added flags - * - * Example: \include MatrixBase_marked.cpp - * Output: \verbinclude MatrixBase_marked.out - * - * \sa class Flagged, extract(), part() - */ -template<typename Derived> -template<unsigned int Added> -inline const Flagged<Derived, Added, 0> -MatrixBase<Derived>::marked() const -{ - return derived(); -} - -/** \deprecated use MatrixBase::noalias() - * - * \returns an expression of *this with the EvalBeforeAssigningBit flag removed. - * - * Example: \include MatrixBase_lazy.cpp - * Output: \verbinclude MatrixBase_lazy.out - * - * \sa class Flagged, marked() - */ -template<typename Derived> -inline const Flagged<Derived, 0, EvalBeforeAssigningBit> -MatrixBase<Derived>::lazy() const -{ - return derived(); -} - - -/** \internal - * Overloaded to perform an efficient C += (A*B).lazy() */ -template<typename Derived> -template<typename ProductDerived, typename Lhs, typename Rhs> -Derived& MatrixBase<Derived>::operator+=(const Flagged<ProductBase<ProductDerived, Lhs,Rhs>, 0, - EvalBeforeAssigningBit>& other) -{ - other._expression().derived().addTo(derived()); return derived(); -} - -/** \internal - * Overloaded to perform an efficient C -= (A*B).lazy() */ -template<typename Derived> -template<typename ProductDerived, typename Lhs, typename Rhs> -Derived& MatrixBase<Derived>::operator-=(const Flagged<ProductBase<ProductDerived, Lhs,Rhs>, 0, - EvalBeforeAssigningBit>& other) -{ - other._expression().derived().subTo(derived()); return derived(); -} - #endif // EIGEN_FLAGGED_H diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h index 7cfdee6cf..d7f17dd28 100644 --- a/Eigen/src/Core/Product.h +++ b/Eigen/src/Core/Product.h @@ -54,8 +54,6 @@ enum { Small = Dynamic/2 }; -enum { OuterProduct, InnerProduct, UnrolledProduct, GemvProduct, GemmProduct }; - template<typename Lhs, typename Rhs> struct ei_product_type { typedef typename ei_cleantype<Lhs>::type _Lhs; diff --git a/Eigen/src/Core/ProductBase.h b/Eigen/src/Core/ProductBase.h index 4e5490d6a..ef986baaa 100644 --- a/Eigen/src/Core/ProductBase.h +++ b/Eigen/src/Core/ProductBase.h @@ -25,6 +25,8 @@ #ifndef EIGEN_PRODUCTBASE_H #define EIGEN_PRODUCTBASE_H +enum { OuterProduct, InnerProduct, UnrolledProduct, GemvProduct, GemmProduct }; + /** \class ProductBase * */ @@ -69,7 +71,7 @@ class ProductBase : public MatrixBase<Derived> public: typedef MatrixBase<Derived> Base; EIGEN_DENSE_PUBLIC_INTERFACE(ProductBase) - + protected: typedef typename Lhs::Nested LhsNested; typedef typename ei_cleantype<LhsNested>::type _LhsNested; typedef ei_blas_traits<_LhsNested> LhsBlasTraits; @@ -82,6 +84,10 @@ class ProductBase : public MatrixBase<Derived> typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType; typedef typename ei_cleantype<ActualRhsType>::type _ActualRhsType; + typedef typename ProductReturnType<Lhs,Rhs,UnrolledProduct>::Type CoeffBaseProductType; + typedef Flagged<CoeffBaseProductType,0,EvalBeforeNestingBit> LazyCoeffBaseProductType; + public: + typedef typename Base::PlainMatrixType PlainMatrixType; ProductBase(const Lhs& lhs, const Rhs& rhs) @@ -113,6 +119,26 @@ 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 Diagonal<LazyCoeffBaseProductType,0>(CoeffBaseProductType(m_lhs, m_rhs)); } + + Diagonal<LazyCoeffBaseProductType,0> diagonal() + { return Diagonal<LazyCoeffBaseProductType,0>(CoeffBaseProductType(m_lhs, m_rhs)); } + + template<int Index> + const Diagonal<LazyCoeffBaseProductType,Index> diagonal() const + { return Diagonal<LazyCoeffBaseProductType,Index>(CoeffBaseProductType(m_lhs, m_rhs)); } + + template<int Index> + Diagonal<LazyCoeffBaseProductType,Index> diagonal() + { return Diagonal<LazyCoeffBaseProductType,Index>(CoeffBaseProductType(m_lhs, m_rhs)); } + + const Diagonal<LazyCoeffBaseProductType,Dynamic> diagonal(int index) const + { return Diagonal<LazyCoeffBaseProductType,Dynamic>(LazyCoeffBaseProductType(CoeffBaseProductType(m_lhs, m_rhs))).diagonal(index); } + + Diagonal<LazyCoeffBaseProductType,Dynamic> diagonal(int index) + { return Diagonal<LazyCoeffBaseProductType,Dynamic>(LazyCoeffBaseProductType(CoeffBaseProductType(m_lhs, m_rhs))).diagonal(index); } + protected: const LhsNested m_lhs; diff --git a/Eigen/src/Eigen2Support/Lazy.h b/Eigen/src/Eigen2Support/Lazy.h index e69de29bb..c4288ede2 100644 --- a/Eigen/src/Eigen2Support/Lazy.h +++ b/Eigen/src/Eigen2Support/Lazy.h @@ -0,0 +1,82 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com> +// +// Eigen is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// Alternatively, you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License and a copy of the GNU General Public License along with +// Eigen. If not, see <http://www.gnu.org/licenses/>. + +#ifndef EIGEN_LAZY_H +#define EIGEN_LAZY_H + +/** \deprecated it is only used by lazy() which is deprecated + * + * \returns an expression of *this with added flags + * + * Example: \include MatrixBase_marked.cpp + * Output: \verbinclude MatrixBase_marked.out + * + * \sa class Flagged, extract(), part() + */ +template<typename Derived> +template<unsigned int Added> +inline const Flagged<Derived, Added, 0> +MatrixBase<Derived>::marked() const +{ + return derived(); +} + +/** \deprecated use MatrixBase::noalias() + * + * \returns an expression of *this with the EvalBeforeAssigningBit flag removed. + * + * Example: \include MatrixBase_lazy.cpp + * Output: \verbinclude MatrixBase_lazy.out + * + * \sa class Flagged, marked() + */ +template<typename Derived> +inline const Flagged<Derived, 0, EvalBeforeAssigningBit> +MatrixBase<Derived>::lazy() const +{ + return derived(); +} + + +/** \internal + * Overloaded to perform an efficient C += (A*B).lazy() */ +template<typename Derived> +template<typename ProductDerived, typename Lhs, typename Rhs> +Derived& MatrixBase<Derived>::operator+=(const Flagged<ProductBase<ProductDerived, Lhs,Rhs>, 0, + EvalBeforeAssigningBit>& other) +{ + other._expression().derived().addTo(derived()); return derived(); +} + +/** \internal + * Overloaded to perform an efficient C -= (A*B).lazy() */ +template<typename Derived> +template<typename ProductDerived, typename Lhs, typename Rhs> +Derived& MatrixBase<Derived>::operator-=(const Flagged<ProductBase<ProductDerived, Lhs,Rhs>, 0, + EvalBeforeAssigningBit>& other) +{ + other._expression().derived().subTo(derived()); return derived(); +} + +#endif // EIGEN_LAZY_H |