more ET refactoring:

* extend Cwise for multiple storage base class
* a lot of cleaning in the Sparse module
This commit is contained in:
Gael Guennebaud
2009-11-17 16:04:19 +01:00
parent 63bcc1c0fb
commit 1e62e0b0d8
27 changed files with 180 additions and 552 deletions

View File

@@ -71,7 +71,7 @@
*
* \sa MatrixBase::cwise() const, MatrixBase::cwise()
*/
template<typename ExpressionType> class Cwise
template<typename ExpressionType, template<typename> class StorageBase> class Cwise
{
public:
@@ -91,15 +91,15 @@ template<typename ExpressionType> class Cwise
template<typename OtherDerived>
const EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_quotient_op)
operator/(const MatrixBase<OtherDerived> &other) const;
operator/(const StorageBase<OtherDerived> &other) const;
template<typename OtherDerived>
const EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_min_op)
min(const MatrixBase<OtherDerived> &other) const;
min(const StorageBase<OtherDerived> &other) const;
template<typename OtherDerived>
const EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_max_op)
max(const MatrixBase<OtherDerived> &other) const;
max(const StorageBase<OtherDerived> &other) const;
const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_abs_op) abs() const;
const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_abs2_op) abs2() const;
@@ -129,28 +129,28 @@ template<typename ExpressionType> class Cwise
ExpressionType& operator-=(const Scalar& scalar);
template<typename OtherDerived>
inline ExpressionType& operator*=(const MatrixBase<OtherDerived> &other);
inline ExpressionType& operator*=(const StorageBase<OtherDerived> &other);
template<typename OtherDerived>
inline ExpressionType& operator/=(const MatrixBase<OtherDerived> &other);
inline ExpressionType& operator/=(const StorageBase<OtherDerived> &other);
template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less)
operator<(const MatrixBase<OtherDerived>& other) const;
operator<(const StorageBase<OtherDerived>& other) const;
template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal)
operator<=(const MatrixBase<OtherDerived>& other) const;
operator<=(const StorageBase<OtherDerived>& other) const;
template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)
operator>(const MatrixBase<OtherDerived>& other) const;
operator>(const StorageBase<OtherDerived>& other) const;
template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)
operator>=(const MatrixBase<OtherDerived>& other) const;
operator>=(const StorageBase<OtherDerived>& other) const;
template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to)
operator==(const MatrixBase<OtherDerived>& other) const;
operator==(const StorageBase<OtherDerived>& other) const;
template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to)
operator!=(const MatrixBase<OtherDerived>& other) const;
operator!=(const StorageBase<OtherDerived>& other) const;
// comparisons to a scalar value
const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less)

View File

@@ -95,7 +95,7 @@ class CwiseBinaryOp : ei_no_assignment_operator,
typename ei_promote_storage_type<typename ei_traits<Lhs>::StorageType,
typename ei_traits<Rhs>::StorageType>::ret>::Base Base;
EIGEN_GENERIC_PUBLIC_INTERFACE_NEW(CwiseBinaryOp)
typedef typename ei_traits<CwiseBinaryOp>::LhsNested LhsNested;
typedef typename ei_traits<CwiseBinaryOp>::RhsNested RhsNested;
typedef typename ei_traits<CwiseBinaryOp>::_LhsNested _LhsNested;
@@ -232,10 +232,10 @@ MatrixBase<Derived>::operator+=(const MatrixBase<OtherDerived>& other)
*
* \sa class CwiseBinaryOp, operator/(), square()
*/
template<typename ExpressionType>
template<typename ExpressionType,template <typename> class StorageBase>
template<typename OtherDerived>
EIGEN_STRONG_INLINE const EIGEN_CWISE_PRODUCT_RETURN_TYPE
Cwise<ExpressionType>::operator*(const AnyMatrixBase<OtherDerived> &other) const
Cwise<ExpressionType,StorageBase>::operator*(const AnyMatrixBase<OtherDerived> &other) const
{
return EIGEN_CWISE_PRODUCT_RETURN_TYPE(_expression(), other.derived());
}
@@ -247,10 +247,10 @@ Cwise<ExpressionType>::operator*(const AnyMatrixBase<OtherDerived> &other) const
*
* \sa class CwiseBinaryOp, operator*(), inverse()
*/
template<typename ExpressionType>
template<typename ExpressionType,template <typename> class StorageBase>
template<typename OtherDerived>
EIGEN_STRONG_INLINE const EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_quotient_op)
Cwise<ExpressionType>::operator/(const MatrixBase<OtherDerived> &other) const
Cwise<ExpressionType,StorageBase>::operator/(const StorageBase<OtherDerived> &other) const
{
return EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_quotient_op)(_expression(), other.derived());
}
@@ -262,9 +262,9 @@ Cwise<ExpressionType>::operator/(const MatrixBase<OtherDerived> &other) const
*
* \sa operator*(), operator/=()
*/
template<typename ExpressionType>
template<typename ExpressionType,template <typename> class StorageBase>
template<typename OtherDerived>
inline ExpressionType& Cwise<ExpressionType>::operator*=(const MatrixBase<OtherDerived> &other)
inline ExpressionType& Cwise<ExpressionType,StorageBase>::operator*=(const StorageBase<OtherDerived> &other)
{
return m_matrix.const_cast_derived() = *this * other;
}
@@ -276,9 +276,9 @@ inline ExpressionType& Cwise<ExpressionType>::operator*=(const MatrixBase<OtherD
*
* \sa operator/(), operator*=()
*/
template<typename ExpressionType>
template<typename ExpressionType,template <typename> class StorageBase>
template<typename OtherDerived>
inline ExpressionType& Cwise<ExpressionType>::operator/=(const MatrixBase<OtherDerived> &other)
inline ExpressionType& Cwise<ExpressionType,StorageBase>::operator/=(const StorageBase<OtherDerived> &other)
{
return m_matrix.const_cast_derived() = *this / other;
}
@@ -290,10 +290,10 @@ inline ExpressionType& Cwise<ExpressionType>::operator/=(const MatrixBase<OtherD
*
* \sa class CwiseBinaryOp
*/
template<typename ExpressionType>
template<typename ExpressionType,template <typename> class StorageBase>
template<typename OtherDerived>
EIGEN_STRONG_INLINE const EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_min_op)
Cwise<ExpressionType>::min(const MatrixBase<OtherDerived> &other) const
Cwise<ExpressionType,StorageBase>::min(const StorageBase<OtherDerived> &other) const
{
return EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_min_op)(_expression(), other.derived());
}
@@ -305,10 +305,10 @@ Cwise<ExpressionType>::min(const MatrixBase<OtherDerived> &other) const
*
* \sa class CwiseBinaryOp
*/
template<typename ExpressionType>
template<typename ExpressionType,template <typename> class StorageBase>
template<typename OtherDerived>
EIGEN_STRONG_INLINE const EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_max_op)
Cwise<ExpressionType>::max(const MatrixBase<OtherDerived> &other) const
Cwise<ExpressionType,StorageBase>::max(const StorageBase<OtherDerived> &other) const
{
return EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_max_op)(_expression(), other.derived());
}

View File

@@ -135,9 +135,9 @@ class CwiseUnaryOpImpl<UnaryOp,MatrixType,Dense> : public MatrixBase<CwiseUnaryO
*
* \sa abs2()
*/
template<typename ExpressionType>
template<typename ExpressionType,template <typename> class StorageBase>
EIGEN_STRONG_INLINE const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_abs_op)
Cwise<ExpressionType>::abs() const
Cwise<ExpressionType,StorageBase>::abs() const
{
return _expression();
}
@@ -149,9 +149,9 @@ Cwise<ExpressionType>::abs() const
*
* \sa abs(), square()
*/
template<typename ExpressionType>
template<typename ExpressionType,template <typename> class StorageBase>
EIGEN_STRONG_INLINE const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_abs2_op)
Cwise<ExpressionType>::abs2() const
Cwise<ExpressionType,StorageBase>::abs2() const
{
return _expression();
}
@@ -163,9 +163,9 @@ Cwise<ExpressionType>::abs2() const
*
* \sa pow(), log(), sin(), cos()
*/
template<typename ExpressionType>
template<typename ExpressionType,template <typename> class StorageBase>
inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_exp_op)
Cwise<ExpressionType>::exp() const
Cwise<ExpressionType,StorageBase>::exp() const
{
return _expression();
}
@@ -177,9 +177,9 @@ Cwise<ExpressionType>::exp() const
*
* \sa exp()
*/
template<typename ExpressionType>
template<typename ExpressionType,template <typename> class StorageBase>
inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_log_op)
Cwise<ExpressionType>::log() const
Cwise<ExpressionType,StorageBase>::log() const
{
return _expression();
}

View File

@@ -66,11 +66,11 @@ operator*(const std::complex<Scalar>& scalar) const
}
inline friend const ScalarMultipleReturnType
operator*(const Scalar& scalar, const Self& matrix)
operator*(const Scalar& scalar, const StorageBaseType& matrix)
{ return matrix*scalar; }
inline friend const CwiseUnaryOp<ei_scalar_multiple2_op<Scalar,std::complex<Scalar> >, Derived>
operator*(const std::complex<Scalar>& scalar, const Self& matrix)
operator*(const std::complex<Scalar>& scalar, const StorageBaseType& matrix)
{ return matrix*scalar; }
/** \returns an expression of *this with the \a Scalar type casted to
@@ -163,7 +163,7 @@ imag() { return derived(); }
*
* \sa class Cwise, cwise()
*/
inline const Cwise<Derived> cwise() const
inline const Cwise<Derived,EIGEN_CURRENT_STORAGE_BASE_CLASS> cwise() const
{
return derived();
}
@@ -175,7 +175,7 @@ inline const Cwise<Derived> cwise() const
*
* \sa class Cwise, cwise() const
*/
inline Cwise<Derived> cwise()
inline Cwise<Derived,EIGEN_CURRENT_STORAGE_BASE_CLASS> cwise()
{
return derived();
}

View File

@@ -51,9 +51,6 @@
}
* \endcode
*/
struct Dense {};
template<typename Derived> class MatrixBase
#ifndef EIGEN_PARSED_BY_DOXYGEN
: public ei_special_scalar_op_base<Derived,typename ei_traits<Derived>::Scalar,
@@ -62,7 +59,9 @@ template<typename Derived> class MatrixBase
{
public:
#ifndef EIGEN_PARSED_BY_DOXYGEN
typedef MatrixBase Self;
/** The base class for a given storage type. */
typedef MatrixBase StorageBaseType;
using ei_special_scalar_op_base<Derived,typename ei_traits<Derived>::Scalar,
typename NumTraits<typename ei_traits<Derived>::Scalar>::Real>::operator*;
@@ -246,7 +245,9 @@ template<typename Derived> class MatrixBase
ei_traits<Derived>::ColsAtCompileTime> BasisReturnType;
#endif // not EIGEN_PARSED_BY_DOXYGEN
#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::MatrixBase
#include "CwiseUnaryOps.h"
#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
/** Copies \a other into *this. \returns a reference to *this. */
template<typename OtherDerived>
@@ -563,7 +564,7 @@ template<typename Derived> class MatrixBase
const Flagged<Derived, Added, 0> marked() const;
const Flagged<Derived, 0, EvalBeforeAssigningBit> lazy() const;
NoAlias<Derived> noalias();
NoAlias<Derived,Eigen::MatrixBase > noalias();
/** \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

@@ -39,7 +39,7 @@
*
* \sa MatrixBase::noalias()
*/
template<typename ExpressionType>
template<typename ExpressionType, template <typename> class StorageBase>
class NoAlias
{
public:
@@ -48,17 +48,17 @@ class NoAlias
/** Behaves like MatrixBase::lazyAssign(other)
* \sa MatrixBase::lazyAssign() */
template<typename OtherDerived>
EIGEN_STRONG_INLINE ExpressionType& operator=(const MatrixBase<OtherDerived>& other)
EIGEN_STRONG_INLINE ExpressionType& operator=(const StorageBase<OtherDerived>& other)
{ return m_expression.lazyAssign(other.derived()); }
/** \sa MatrixBase::operator+= */
template<typename OtherDerived>
EIGEN_STRONG_INLINE ExpressionType& operator+=(const MatrixBase<OtherDerived>& other)
EIGEN_STRONG_INLINE ExpressionType& operator+=(const StorageBase<OtherDerived>& other)
{ return m_expression.lazyAssign(m_expression + other.derived()); }
/** \sa MatrixBase::operator-= */
template<typename OtherDerived>
EIGEN_STRONG_INLINE ExpressionType& operator-=(const MatrixBase<OtherDerived>& other)
EIGEN_STRONG_INLINE ExpressionType& operator-=(const StorageBase<OtherDerived>& other)
{ return m_expression.lazyAssign(m_expression - other.derived()); }
#ifndef EIGEN_PARSED_BY_DOXYGEN
@@ -80,12 +80,12 @@ class NoAlias
/** \returns a pseudo expression of \c *this with an operator= assuming
* no aliasing between \c *this and the source expression.
*
*
* More precisely, noalias() allows to bypass the EvalBeforeAssignBit flag.
* Currently, even though several expressions may alias, only product
* expressions have this flag. Therefore, noalias() is only usefull when
* the source expression contains a matrix product.
*
*
* Here are some examples where noalias is usefull:
* \code
* D.noalias() = A * B;
@@ -107,7 +107,7 @@ class NoAlias
* \sa class NoAlias
*/
template<typename Derived>
NoAlias<Derived> MatrixBase<Derived>::noalias()
NoAlias<Derived,MatrixBase> MatrixBase<Derived>::noalias()
{
return derived();
}

View File

@@ -32,18 +32,7 @@
* \brief Internal helper class for swapping two expressions
*/
template<typename ExpressionType>
struct ei_traits<SwapWrapper<ExpressionType> >
{
typedef typename ExpressionType::Scalar Scalar;
enum {
RowsAtCompileTime = ExpressionType::RowsAtCompileTime,
ColsAtCompileTime = ExpressionType::ColsAtCompileTime,
MaxRowsAtCompileTime = ExpressionType::MaxRowsAtCompileTime,
MaxColsAtCompileTime = ExpressionType::MaxColsAtCompileTime,
Flags = ExpressionType::Flags,
CoeffReadCost = ExpressionType::CoeffReadCost
};
};
struct ei_traits<SwapWrapper<ExpressionType> > : ei_traits<ExpressionType> {};
template<typename ExpressionType> class SwapWrapper
: public MatrixBase<SwapWrapper<ExpressionType> >

View File

@@ -174,16 +174,10 @@ const unsigned int UpperTriangularBit = 0x400;
* means the strictly upper triangular part is 0 */
const unsigned int LowerTriangularBit = 0x800;
/** \ingroup flags
*
* means the expression includes sparse matrices and the sparse path has to be taken. */
const unsigned int SparseBit = 0x1000;
// list of flags that are inherited by default
const unsigned int HereditaryBits = RowMajorBit
| EvalBeforeNestingBit
| EvalBeforeAssigningBit
| SparseBit;
| EvalBeforeAssigningBit;
// Possible values for the Mode parameter of part()
const unsigned int UpperTriangular = UpperTriangularBit;
@@ -262,7 +256,7 @@ namespace {
enum {
IsDense = 0,
IsSparse = SparseBit,
IsSparse,
NoDirectAccess = 0,
HasDirectAccess = DirectAccessBit
};

View File

@@ -35,13 +35,12 @@ template<typename _Scalar, int _Rows, int _Cols,
int _MaxRows = _Rows, int _MaxCols = _Cols> class Matrix;
template<typename ExpressionType, unsigned int Added, unsigned int Removed> class Flagged;
template<typename ExpressionType> class NoAlias;
template<typename ExpressionType, template <typename> class StorageBase > class NoAlias;
template<typename ExpressionType> class NestByValue;
template<typename ExpressionType> class SwapWrapper;
template<typename MatrixType> class Minor;
template<typename MatrixType, int BlockRows=Dynamic, int BlockCols=Dynamic, int PacketAccess=AsRequested,
int _DirectAccessStatus = ei_traits<MatrixType>::Flags&DirectAccessBit ? DirectAccessBit
: ei_traits<MatrixType>::Flags&SparseBit> class Block;
int _DirectAccessStatus = (ei_traits<MatrixType>::Flags&DirectAccessBit) ? HasDirectAccess : NoDirectAccess> class Block;
template<typename MatrixType, int Size=Dynamic, int PacketAccess=AsRequested> class VectorBlock;
template<typename MatrixType> class Transpose;
template<typename MatrixType> class Conjugate;
@@ -61,7 +60,7 @@ template<typename MatrixType, int PacketAccess = AsRequested> class Map;
template<typename Derived> class TriangularBase;
template<typename MatrixType, unsigned int Mode> class TriangularView;
template<typename MatrixType, unsigned int Mode> class SelfAdjointView;
template<typename ExpressionType> class Cwise;
template<typename ExpressionType, template <typename> class StorageBase> class Cwise;
template<typename ExpressionType> class WithFormat;
template<typename MatrixType> struct CommaInitializer;
template<typename Derived> class ReturnByValue;

View File

@@ -108,9 +108,9 @@ template<int _Rows, int _Cols> struct ei_size_at_compile_time
* in order to avoid a useless copy
*/
template<typename T, int Sparseness = ei_traits<T>::Flags&SparseBit> class ei_eval;
template<typename T, typename StorageType = typename ei_traits<T>::StorageType> class ei_eval;
template<typename T> struct ei_eval<T,IsDense>
template<typename T> struct ei_eval<T,Dense>
{
typedef Matrix<typename ei_traits<T>::Scalar,
ei_traits<T>::RowsAtCompileTime,
@@ -123,7 +123,7 @@ template<typename T> struct ei_eval<T,IsDense>
// for matrices, no need to evaluate, just use a const reference to avoid a useless copy
template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols>
struct ei_eval<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>, IsDense>
struct ei_eval<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>, Dense>
{
typedef const Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>& type;
};