* resurected Flagged from Eigen2Support

* reimplement .diagonal() for ProductBase to make (A*B).diagonal() more efficient!
This commit is contained in:
Gael Guennebaud 2010-02-04 18:28:09 +01:00
parent b44240180f
commit 73eb0e633c
6 changed files with 111 additions and 61 deletions

View File

@ -199,6 +199,7 @@ struct Dense {};
#include "src/Core/IO.h"
#include "src/Core/Swap.h"
#include "src/Core/CommaInitializer.h"
#include "src/Core/Flagged.h"
#include "src/Core/ProductBase.h"
#include "src/Core/Product.h"
#include "src/Core/TriangularMatrix.h"

View File

@ -42,7 +42,6 @@ namespace Eigen {
*
*/
#include "src/Eigen2Support/Flagged.h"
#include "src/Eigen2Support/Lazy.h"
#include "src/Eigen2Support/Cwise.h"
#include "src/Eigen2Support/CwiseOperators.h"

View File

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

View File

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

View File

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

View File

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