Introduce generic Flagged xpr, remove already Lazy.h and Temporary.h

Rename DefaultLostFlagMask --> HerediraryBits
This commit is contained in:
Benoit Jacob 2008-05-14 08:20:15 +00:00
parent fd2e9e5c3c
commit 5da60897ab
21 changed files with 80 additions and 156 deletions

View File

@ -30,9 +30,8 @@ namespace Eigen {
#include "src/Core/Coeffs.h"
#include "src/Core/Assign.h"
#include "src/Core/MatrixStorage.h"
#include "src/Core/Flagged.h"
#include "src/Core/Matrix.h"
#include "src/Core/Lazy.h"
#include "src/Core/Temporary.h"
#include "src/Core/CwiseBinaryOp.h"
#include "src/Core/CwiseUnaryOp.h"
#include "src/Core/CwiseNullaryOp.h"

View File

@ -71,7 +71,7 @@ struct ei_traits<Block<MatrixType, BlockRows, BlockCols> >
|| (ColsAtCompileTime != Dynamic && MatrixType::ColsAtCompileTime == Dynamic))
? ~LargeBit
: ~(unsigned int)0,
Flags = MatrixType::Flags & (DefaultLostFlagMask | VectorizableBit | DirectAccessBit) & FlagsMaskLargeBit,
Flags = MatrixType::Flags & (HereditaryBits | VectorizableBit | DirectAccessBit) & FlagsMaskLargeBit,
CoeffReadCost = MatrixType::CoeffReadCost
};
};

View File

@ -69,7 +69,7 @@ struct ei_traits<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
MaxRowsAtCompileTime = Lhs::MaxRowsAtCompileTime,
MaxColsAtCompileTime = Lhs::MaxColsAtCompileTime,
Flags = ((int(LhsFlags) | int(RhsFlags)) & (
DefaultLostFlagMask
HereditaryBits
| Like1DArrayBit
| (ei_functor_traits<BinaryOp>::IsVectorizable && ((int(LhsFlags) & RowMajorBit)==(int(RhsFlags) & RowMajorBit))
? int(LhsFlags) & int(RhsFlags) & VectorizableBit : 0))),

View File

@ -49,7 +49,7 @@ struct ei_traits<CwiseNullaryOp<NullaryOp, MatrixType> >
MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
Flags = (MatrixType::Flags
& (DefaultLostFlagMask | Like1DArrayBit | (ei_functor_traits<NullaryOp>::IsVectorizable ? VectorizableBit : 0)))
& (HereditaryBits | Like1DArrayBit | (ei_functor_traits<NullaryOp>::IsVectorizable ? VectorizableBit : 0)))
| (ei_functor_traits<NullaryOp>::IsRepeatable ? 0 : EvalBeforeNestingBit),
CoeffReadCost = ei_functor_traits<NullaryOp>::Cost
};

View File

@ -55,7 +55,7 @@ struct ei_traits<CwiseUnaryOp<UnaryOp, MatrixType> >
MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
Flags = (MatrixTypeFlags & (
DefaultLostFlagMask | Like1DArrayBit
HereditaryBits | Like1DArrayBit
| (ei_functor_traits<UnaryOp>::IsVectorizable ? VectorizableBit : 0))),
CoeffReadCost = MatrixTypeCoeffReadCost + ei_functor_traits<UnaryOp>::Cost
};

View File

@ -56,7 +56,7 @@ struct ei_traits<DiagonalCoeffs<MatrixType> >
MaxColsAtCompileTime = 1,
Flags = (RowsAtCompileTime == Dynamic && ColsAtCompileTime == Dynamic
? (unsigned int)_MatrixTypeNested::Flags
: (unsigned int)_MatrixTypeNested::Flags &~ LargeBit) & DefaultLostFlagMask,
: (unsigned int)_MatrixTypeNested::Flags &~ LargeBit) & HereditaryBits,
CoeffReadCost = _MatrixTypeNested::CoeffReadCost
};
};

View File

@ -49,7 +49,7 @@ struct ei_traits<DiagonalMatrix<CoeffsVectorType> >
ColsAtCompileTime = CoeffsVectorType::SizeAtCompileTime,
MaxRowsAtCompileTime = CoeffsVectorType::MaxSizeAtCompileTime,
MaxColsAtCompileTime = CoeffsVectorType::MaxSizeAtCompileTime,
Flags = _CoeffsVectorTypeTypeNested::Flags & DefaultLostFlagMask,
Flags = _CoeffsVectorTypeTypeNested::Flags & HereditaryBits,
CoeffReadCost = _CoeffsVectorTypeTypeNested::CoeffReadCost
};
};

View File

@ -1,8 +1,7 @@
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra. Eigen itself is part of the KDE project.
//
// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr>
// Copyright (C) 2008 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -23,23 +22,25 @@
// License and a copy of the GNU General Public License along with
// Eigen. If not, see <http://www.gnu.org/licenses/>.
#ifndef EIGEN_TEMPORARY_H
#define EIGEN_TEMPORARY_H
#ifndef EIGEN_FLAGGED_H
#define EIGEN_FLAGGED_H
/** \class Temporary
/** \class Flagged
*
* \brief Expression with the temporary flag set
* \brief Expression with modified flags
*
* \param ExpressionType the type of the object of which we are taking the temporary version
* \param ExpressionType the type of the object of which we are modifying the flags
* \param Added the flags added to the expression
* \param Removed the flags removed from the expression (has priority over Added).
*
* This class represents the temporary version of an expression.
* It is the return type of MatrixBase::temporary()
* This class represents an expression whose flags have been modified
* It is the return type of MatrixBase::flagged()
* and most of the time this is the only way it is used.
*
* \sa MatrixBase::temporary()
* \sa MatrixBase::flagged()
*/
template<typename ExpressionType>
struct ei_traits<Temporary<ExpressionType> >
template<typename ExpressionType, unsigned int Added, unsigned int Removed>
struct ei_traits<Flagged<ExpressionType, Added, Removed> >
{
typedef typename ExpressionType::Scalar Scalar;
enum {
@ -47,19 +48,19 @@ struct ei_traits<Temporary<ExpressionType> >
ColsAtCompileTime = ExpressionType::ColsAtCompileTime,
MaxRowsAtCompileTime = ExpressionType::MaxRowsAtCompileTime,
MaxColsAtCompileTime = ExpressionType::MaxColsAtCompileTime,
Flags = ExpressionType::Flags,
Flags = (ExpressionType::Flags | Added) & ~Removed,
CoeffReadCost = ExpressionType::CoeffReadCost
};
};
template<typename ExpressionType> class Temporary
: public MatrixBase<Temporary<ExpressionType> >
template<typename ExpressionType, unsigned int Added, unsigned int Removed> class Flagged
: public MatrixBase<Flagged<ExpressionType, Added, Removed> >
{
public:
EIGEN_GENERIC_PUBLIC_INTERFACE(Temporary)
EIGEN_GENERIC_PUBLIC_INTERFACE(Flagged)
inline Temporary(const ExpressionType& matrix) : m_expression(matrix) {}
inline Flagged(const ExpressionType& matrix) : m_expression(matrix) {}
private:
@ -71,12 +72,23 @@ template<typename ExpressionType> class Temporary
return m_expression.coeff(row, col);
}
inline Scalar& _coeffRef(int row, int col)
{
return m_expression.const_cast_derived().coeffRef(row, col);
}
template<int LoadMode>
inline const PacketScalar _packetCoeff(int row, int col) const
{
return m_expression.template packetCoeff<LoadMode>(row, col);
}
template<int LoadMode>
inline void _writePacketCoeff(int row, int col, const PacketScalar& x)
{
m_expression.const_cast_derived().template writePacketCoeff<LoadMode>(row, col, x);
}
protected:
const ExpressionType m_expression;
};
@ -84,10 +96,11 @@ template<typename ExpressionType> class Temporary
/** \returns an expression of the temporary version of *this.
*/
template<typename Derived>
inline const Temporary<Derived>
MatrixBase<Derived>::temporary() const
template<unsigned int Added, unsigned int Removed>
inline const Flagged<Derived, Added, Removed>
MatrixBase<Derived>::flagged() const
{
return Temporary<Derived>(derived());
return Flagged<Derived, Added, Removed>(derived());
}
#endif // EIGEN_TEMPORARY_H
#endif // EIGEN_FLAGGED_H

View File

@ -1,97 +0,0 @@
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra. Eigen itself is part of the KDE project.
//
// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr>
//
// 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
/** \class Lazy
*
* \brief Expression with the lazy flag set
*
* \param ExpressionType the type of the object of which we are taking the lazy version
*
* This class represents the lazy version of an expression.
* It is the return type of MatrixBase::lazy()
* and most of the time this is the only way it is used.
*
* \sa MatrixBase::lazy()
*/
template<typename ExpressionType>
struct ei_traits<Lazy<ExpressionType> >
{
typedef typename ExpressionType::Scalar Scalar;
enum {
RowsAtCompileTime = ExpressionType::RowsAtCompileTime,
ColsAtCompileTime = ExpressionType::ColsAtCompileTime,
MaxRowsAtCompileTime = ExpressionType::MaxRowsAtCompileTime,
MaxColsAtCompileTime = ExpressionType::MaxColsAtCompileTime,
Flags = ExpressionType::Flags & ~(EvalBeforeNestingBit | EvalBeforeAssigningBit),
CoeffReadCost = ExpressionType::CoeffReadCost
};
};
template<typename ExpressionType> class Lazy
: public MatrixBase<Lazy<ExpressionType> >
{
public:
EIGEN_GENERIC_PUBLIC_INTERFACE(Lazy)
inline Lazy(const ExpressionType& matrix) : m_expression(matrix) {}
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Lazy)
private:
inline int _rows() const { return m_expression.rows(); }
inline int _cols() const { return m_expression.cols(); }
inline const Scalar _coeff(int row, int col) const
{
return m_expression.coeff(row, col);
}
template<int LoadMode>
inline PacketScalar _packetCoeff(int row, int col) const
{
return m_expression.template packetCoeff<LoadMode>(row, col);
}
protected:
const ExpressionType& m_expression;
};
/** \returns an expression of the lazy version of *this.
*
* Example: \include MatrixBase_lazy.cpp
* Output: \verbinclude MatrixBase_lazy.out
*/
template<typename Derived>
inline const Lazy<Derived>
MatrixBase<Derived>::lazy() const
{
return Lazy<Derived>(derived());
}
#endif // EIGEN_LAZY_H

View File

@ -47,7 +47,7 @@ struct ei_traits<Map<MatrixType> >
ColsAtCompileTime = MatrixType::ColsAtCompileTime,
MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
Flags = MatrixType::Flags & (DefaultLostFlagMask | DirectAccessBit),
Flags = MatrixType::Flags & (HereditaryBits | DirectAccessBit),
CoeffReadCost = NumTraits<Scalar>::ReadCost
};
};

View File

@ -278,7 +278,9 @@ template<typename Derived> class MatrixBase
Transpose<Derived> transpose();
const Transpose<Derived> transpose() const;
const Transpose<Temporary<CwiseUnaryOp<ei_scalar_conjugate_op<typename ei_traits<Derived>::Scalar>, Derived> > >
const Transpose<
Flagged<CwiseUnaryOp<ei_scalar_conjugate_op<typename ei_traits<Derived>::Scalar>, Derived>
, TemporaryBit, 0> >
adjoint() const;
//@}
@ -419,8 +421,17 @@ template<typename Derived> class MatrixBase
template<typename OtherDerived>
void swap(const MatrixBase<OtherDerived>& other);
const Lazy<Derived> lazy() const;
const Temporary<Derived> temporary() const;
template<unsigned int Added, unsigned int Removed>
const Flagged<Derived, Added, Removed> flagged() const;
const Flagged<Derived, 0, EvalBeforeNestingBit | EvalBeforeAssigningBit> lazy() const
{
return derived();
}
const Flagged<Derived, TemporaryBit, 0> temporary() const
{
return derived();
}
/** \returns number of elements to skip to pass from one row (resp. column) to another
* for a row-major (resp. column-major) matrix.

View File

@ -52,7 +52,7 @@ struct ei_traits<Minor<MatrixType> >
int(MatrixType::MaxRowsAtCompileTime) - 1 : Dynamic,
MaxColsAtCompileTime = (MatrixType::MaxColsAtCompileTime != Dynamic) ?
int(MatrixType::MaxColsAtCompileTime) - 1 : Dynamic,
Flags = _MatrixTypeNested::Flags & DefaultLostFlagMask,
Flags = _MatrixTypeNested::Flags & HereditaryBits,
CoeffReadCost = _MatrixTypeNested::CoeffReadCost
};
};

View File

@ -179,7 +179,7 @@ struct ei_traits<Product<Lhs, Rhs, EvalMode> >
_Vectorizable = (_LhsVectorizable || _RhsVectorizable) ? 1 : 0,
_RowMajor = (RhsFlags & RowMajorBit)
&& (EvalMode==(int)CacheFriendlyProduct ? (int)LhsFlags & RowMajorBit : (!_LhsVectorizable)),
_LostBits = DefaultLostFlagMask & ~(
_LostBits = HereditaryBits & ~(
(_RowMajor ? 0 : RowMajorBit)
| ((RowsAtCompileTime == Dynamic || ColsAtCompileTime == Dynamic) ? 0 : LargeBit)),
Flags = ((unsigned int)(LhsFlags | RhsFlags) & _LostBits)

View File

@ -227,7 +227,7 @@ struct ei_traits<Product<Lhs, Rhs, EvalMode> >
_Vectorizable = (_LhsVectorizable || _RhsVectorizable) ? 0 : 0,
_RowMajor = (RhsFlags & RowMajorBit)
&& (EvalMode==(int)CacheFriendlyProduct ? (int)LhsFlags & RowMajorBit : (!_LhsVectorizable)),
_LostBits = DefaultLostFlagMask & ~(
_LostBits = HereditaryBits & ~(
(_RowMajor ? 0 : RowMajorBit)
| ((RowsAtCompileTime == Dynamic || ColsAtCompileTime == Dynamic) ? 0 : LargeBit)),
Flags = ((unsigned int)(LhsFlags | RhsFlags) & _LostBits)

View File

@ -96,7 +96,7 @@ struct ei_traits<PartialRedux<Direction, BinaryOp, MatrixType> >
MaxColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::MaxColsAtCompileTime,
Flags = ((int(RowsAtCompileTime) == Dynamic || int(ColsAtCompileTime) == Dynamic)
? (unsigned int)_MatrixTypeNested::Flags
: (unsigned int)_MatrixTypeNested::Flags & ~LargeBit) & DefaultLostFlagMask,
: (unsigned int)_MatrixTypeNested::Flags & ~LargeBit) & HereditaryBits,
TraversalSize = Direction==Vertical ? RowsAtCompileTime : ColsAtCompileTime,
CoeffReadCost = TraversalSize * _MatrixTypeNested::CoeffReadCost
+ (TraversalSize - 1) * ei_functor_traits<BinaryOp>::Cost

View File

@ -125,9 +125,9 @@ MatrixBase<Derived>::transpose() const
*
* \sa transpose(), conjugate(), class Transpose, class ei_scalar_conjugate_op */
template<typename Derived>
inline const Transpose<Temporary<
CwiseUnaryOp<ei_scalar_conjugate_op<typename ei_traits<Derived>::Scalar>, Derived >
> >
inline const Transpose<
Flagged<CwiseUnaryOp<ei_scalar_conjugate_op<typename ei_traits<Derived>::Scalar>, Derived >
, TemporaryBit, 0> >
MatrixBase<Derived>::adjoint() const
{
return conjugate().temporary().transpose();

View File

@ -27,7 +27,7 @@
/** \class Triangular
*
* \brief Expression of a triangular matrix from a squared matrix
* \brief Expression of a triangular matrix from a square matrix
*
* \param Mode or-ed bit field indicating the triangular part (Upper or Lower) we are taking,
* and the property of the diagonal if any (UnitDiagBit or NullDiagBit).
@ -52,7 +52,7 @@
* lower part of m1 is left unchanged, and optimal loops are employed. Note that
* m1 might also be resized.
*
* Of course, in both examples \c <any \c expression> has to be a squared matrix.
* Of course, in both examples \c <any \c expression> has to be a square matrix.
*
* \sa MatrixBase::upper(), MatrixBase::lower(), class TriangularProduct
*/
@ -89,21 +89,21 @@ template<int Mode, typename MatrixType> class Triangular
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Triangular)
/** Overloaded to keep a Triangular expression */
inline Triangular<(Upper | Lower) ^ Mode, Temporary<Transpose<MatrixType> > > transpose()
inline Triangular<(Upper | Lower) ^ Mode, Flagged<Transpose<MatrixType>,TemporaryBit,0> > transpose()
{
return Triangular<(Upper | Lower) ^ Mode, Temporary<Transpose<MatrixType> > >((m_matrix.transpose().temporary()));
return m_matrix.transpose().temporary();
}
/** Overloaded to keep a Triangular expression */
inline const Triangular<(Upper | Lower) ^ Mode, Temporary<Transpose<MatrixType> > > transpose() const
inline const Triangular<(Upper | Lower) ^ Mode, Flagged<Transpose<MatrixType>,TemporaryBit,0> > transpose() const
{
return Triangular<(Upper | Lower) ^ Mode, Temporary<Transpose<MatrixType> > >((m_matrix.transpose().temporary()));
return m_matrix.transpose().temporary();
}
/** \returns the product of the inverse of *this with \a other.
*
* This function computes the inverse-matrix matrix product inv(*this) \a other
* This process is also as forward (resp. backward) substitution if *this is an upper (resp. lower)
* This function computes the inverse-matrix matrix product inverse(*this) * \a other
* It works as a forward (resp. backward) substitution if *this is an upper (resp. lower)
* triangular matrix.
*/
template<typename OtherDerived>

View File

@ -44,13 +44,16 @@ const unsigned int UnitDiagBit = 0x80; ///< means all diagonal coefficients
const unsigned int NullLowerBit = 0x200; ///< means the strictly triangular lower part is 0
const unsigned int NullUpperBit = 0x400; ///< means the strictly triangular upper part is 0
const unsigned int DirectAccessBit = 0x800; ///< means the underlying matrix data can be direclty accessed
const unsigned int TemporaryBit = 0x1000; ///< means the expression should be copied by value when nested
enum { Upper=NullLowerBit, Lower=NullUpperBit };
enum { Aligned=0, UnAligned=1 };
// list of flags that are lost by default
const unsigned int DefaultLostFlagMask = ~(VectorizableBit | Like1DArrayBit | DirectAccessBit
| NullDiagBit | UnitDiagBit | NullLowerBit | NullUpperBit);
// list of flags that are inherited by default
const unsigned int HereditaryBits = RowMajorBit
| EvalBeforeNestingBit
| EvalBeforeAssigningBit
| LargeBit;
enum { ConditionalJumpCost = 5 };
enum CornerType { TopLeft, TopRight, BottomLeft, BottomRight };

View File

@ -34,8 +34,7 @@ template<typename _Scalar, int _Rows, int _Cols,
int _MaxRows = _Rows, int _MaxCols = _Cols>
class Matrix;
template<typename ExpressionType> class Lazy;
template<typename ExpressionType> class Temporary;
template<typename ExpressionType, unsigned int Added, unsigned int Removed> class Flagged;
template<typename MatrixType> class Minor;
template<typename MatrixType, int BlockRows=Dynamic, int BlockCols=Dynamic> class Block;
template<typename MatrixType> class Transpose;

View File

@ -135,6 +135,7 @@ typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \
typedef typename Base::PacketScalar PacketScalar; \
typedef typename Eigen::ei_nested<Derived>::type Nested; \
typedef typename Eigen::ei_eval<Derived>::type Eval; \
typedef Eigen::Flagged<Derived, TemporaryBit, 0> Temporary; \
enum { RowsAtCompileTime = Base::RowsAtCompileTime, \
ColsAtCompileTime = Base::ColsAtCompileTime, \
MaxRowsAtCompileTime = Base::MaxRowsAtCompileTime, \

View File

@ -194,12 +194,7 @@ template<typename T> struct ei_unconst<const T> { typedef T type; };
template<typename T> struct ei_is_temporary
{
enum { ret = 0 };
};
template<typename T> struct ei_is_temporary<Temporary<T> >
{
enum { ret = 1 };
enum { ret = ei_traits<T>::Flags & TemporaryBit };
};
template<typename T, int n=1> struct ei_nested