Experiment the ET refactoring on Transpose for Dense and Sparse storages.

All tests work fine.
This commit is contained in:
Gael Guennebaud
2009-11-16 18:19:08 +01:00
parent a89b22f352
commit 2a3a6fe45e
22 changed files with 244 additions and 116 deletions

View File

@@ -46,6 +46,7 @@ template<typename _Scalar, int _Flags>
struct ei_traits<DynamicSparseMatrix<_Scalar, _Flags> >
{
typedef _Scalar Scalar;
typedef Sparse StorageType;
enum {
RowsAtCompileTime = Dynamic,
ColsAtCompileTime = Dynamic,

View File

@@ -45,6 +45,7 @@ template<typename _Scalar, int _Options>
struct ei_traits<SparseMatrix<_Scalar, _Options> >
{
typedef _Scalar Scalar;
typedef Sparse StorageType;
enum {
RowsAtCompileTime = Dynamic,
ColsAtCompileTime = Dynamic,

View File

@@ -36,11 +36,15 @@
*
*
*/
struct Sparse {};
template<typename Derived> class SparseMatrixBase : public AnyMatrixBase<Derived>
{
public:
typedef typename ei_traits<Derived>::Scalar Scalar;
typedef typename ei_packet_traits<Scalar>::type PacketScalar;
// typedef typename Derived::InnerIterator InnerIterator;
enum {
@@ -86,7 +90,11 @@ template<typename Derived> class SparseMatrixBase : public AnyMatrixBase<Derived
* this expression.
*/
IsRowMajor = Flags&RowMajorBit ? 1 : 0
IsRowMajor = Flags&RowMajorBit ? 1 : 0,
#ifndef EIGEN_PARSED_BY_DOXYGEN
_HasDirectAccess = (int(Flags)&DirectAccessBit) ? 1 : 0 // workaround sunCC
#endif
};
/** \internal the return type of MatrixBase::conjugate() */
@@ -100,8 +108,8 @@ template<typename Derived> class SparseMatrixBase : public AnyMatrixBase<Derived
typedef SparseCwiseUnaryOp<ei_scalar_imag_op<Scalar>, Derived> ImagReturnType;
/** \internal the return type of MatrixBase::adjoint() */
typedef typename ei_meta_if<NumTraits<Scalar>::IsComplex,
SparseCwiseUnaryOp<ei_scalar_conjugate_op<Scalar>, SparseNestByValue<Eigen::SparseTranspose<Derived> > >,
SparseTranspose<Derived>
SparseCwiseUnaryOp<ei_scalar_conjugate_op<Scalar>, SparseNestByValue<Eigen::Transpose<Derived> > >,
Transpose<Derived>
>::ret AdjointReturnType;
#ifndef EIGEN_PARSED_BY_DOXYGEN
@@ -113,6 +121,10 @@ template<typename Derived> class SparseMatrixBase : public AnyMatrixBase<Derived
*/
typedef typename NumTraits<Scalar>::Real RealScalar;
/** \internal the return type of coeff()
*/
typedef typename ei_meta_if<_HasDirectAccess, const Scalar&, Scalar>::ret CoeffReturnType;
/** type of the equivalent square matrix */
typedef Matrix<Scalar,EIGEN_ENUM_MAX(RowsAtCompileTime,ColsAtCompileTime),
EIGEN_ENUM_MAX(RowsAtCompileTime,ColsAtCompileTime)> SquareMatrixType;
@@ -353,8 +365,8 @@ template<typename Derived> class SparseMatrixBase : public AnyMatrixBase<Derived
// const PlainMatrixType normalized() const;
// void normalize();
SparseTranspose<Derived> transpose() { return derived(); }
const SparseTranspose<Derived> transpose() const { return derived(); }
Transpose<Derived> transpose() { return derived(); }
const Transpose<Derived> transpose() const { return derived(); }
// void transposeInPlace();
const AdjointReturnType adjoint() const { return transpose().nestByValue(); }

View File

@@ -25,64 +25,72 @@
#ifndef EIGEN_SPARSETRANSPOSE_H
#define EIGEN_SPARSETRANSPOSE_H
template<typename MatrixType>
struct ei_traits<SparseTranspose<MatrixType> > : ei_traits<Transpose<MatrixType> >
{};
// template<typename MatrixType>
// struct ei_traits<SparseTranspose<MatrixType> > : ei_traits<Transpose<MatrixType> >
// {};
template<typename MatrixType> class SparseTranspose
: public SparseMatrixBase<SparseTranspose<MatrixType> >
template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>
: public SparseMatrixBase<Transpose<MatrixType> >
{
const typename ei_cleantype<typename MatrixType::Nested>::type& matrix() const
{ return derived().nestedExpression(); }
typename ei_cleantype<typename MatrixType::Nested>::type& matrix()
{ return derived().nestedExpression(); }
public:
EIGEN_GENERIC_PUBLIC_INTERFACE(SparseTranspose)
// _EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(TransposeImpl,SparseMatrixBase<Transpose<MatrixType> >)
// EIGEN_EXPRESSION_IMPL_COMMON(SparseMatrixBase<Transpose<MatrixType> >)
EIGEN_SPARSE_PUBLIC_INTERFACE(Transpose<MatrixType>)
class InnerIterator;
class ReverseInnerIterator;
inline SparseTranspose(const MatrixType& matrix) : m_matrix(matrix) {}
// inline SparseTranspose(const MatrixType& matrix) : m_matrix(matrix) {}
//EIGEN_INHERIT_ASSIGNMENT_OPERATORS(SparseTranspose)
inline int rows() const { return m_matrix.cols(); }
inline int cols() const { return m_matrix.rows(); }
inline int nonZeros() const { return m_matrix.nonZeros(); }
// inline int rows() const { return m_matrix.cols(); }
// inline int cols() const { return m_matrix.rows(); }
inline int nonZeros() const { return matrix().nonZeros(); }
// FIXME should be keep them ?
inline Scalar& coeffRef(int row, int col)
{ return m_matrix.const_cast_derived().coeffRef(col, row); }
{ return matrix().const_cast_derived().coeffRef(col, row); }
inline const Scalar coeff(int row, int col) const
{ return m_matrix.coeff(col, row); }
{ return matrix().coeff(col, row); }
inline const Scalar coeff(int index) const
{ return m_matrix.coeff(index); }
{ return matrix().coeff(index); }
inline Scalar& coeffRef(int index)
{ return m_matrix.const_cast_derived().coeffRef(index); }
{ return matrix().const_cast_derived().coeffRef(index); }
protected:
const typename MatrixType::Nested m_matrix;
// protected:
// const typename MatrixType::Nested m_matrix;
};
template<typename MatrixType> class SparseTranspose<MatrixType>::InnerIterator : public MatrixType::InnerIterator
template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>::InnerIterator : public MatrixType::InnerIterator
{
typedef typename MatrixType::InnerIterator Base;
public:
EIGEN_STRONG_INLINE InnerIterator(const SparseTranspose& trans, int outer)
: Base(trans.m_matrix, outer)
EIGEN_STRONG_INLINE InnerIterator(const TransposeImpl& trans, int outer)
: Base(trans.matrix(), outer)
{}
inline int row() const { return Base::col(); }
inline int col() const { return Base::row(); }
};
template<typename MatrixType> class SparseTranspose<MatrixType>::ReverseInnerIterator : public MatrixType::ReverseInnerIterator
template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>::ReverseInnerIterator : public MatrixType::ReverseInnerIterator
{
typedef typename MatrixType::ReverseInnerIterator Base;
public:
EIGEN_STRONG_INLINE ReverseInnerIterator(const SparseTranspose& xpr, int outer)
: Base(xpr.m_matrix, outer)
EIGEN_STRONG_INLINE ReverseInnerIterator(const TransposeImpl& xpr, int outer)
: Base(xpr.matrix(), outer)
{}
inline int row() const { return Base::col(); }
inline int col() const { return Base::row(); }

View File

@@ -69,7 +69,23 @@ enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \
IsVectorAtCompileTime = Base::IsVectorAtCompileTime };
#define EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(Derived) \
_EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::SparseMatrixBase<Derived>)
_EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::SparseMatrixBase<Derived>)
#define _EIGEN_SPARSE_PUBLIC_INTERFACE(Derived, BaseClass) \
typedef BaseClass Base; \
typedef typename Eigen::ei_traits<Derived>::Scalar Scalar; \
typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \
typedef typename Eigen::ei_nested<Derived>::type Nested; \
enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \
ColsAtCompileTime = Eigen::ei_traits<Derived>::ColsAtCompileTime, \
Flags = Eigen::ei_traits<Derived>::Flags, \
CoeffReadCost = Eigen::ei_traits<Derived>::CoeffReadCost, \
SizeAtCompileTime = Base::SizeAtCompileTime, \
IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; \
using Base::derived;
#define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived) \
_EIGEN_SPARSE_PUBLIC_INTERFACE(Derived, Eigen::SparseMatrixBase<Derived>)
enum SparseBackend {
DefaultBackend,
@@ -107,7 +123,7 @@ template<typename _Scalar, int _Flags = 0> class SparseVector;
template<typename _Scalar, int _Flags = 0> class MappedSparseMatrix;
template<typename MatrixType> class SparseNestByValue;
template<typename MatrixType> class SparseTranspose;
// template<typename MatrixType> class SparseTranspose;
template<typename MatrixType, int Size> class SparseInnerVectorSet;
template<typename Derived> class SparseCwise;
template<typename UnaryOp, typename MatrixType> class SparseCwiseUnaryOp;
@@ -127,7 +143,7 @@ const int RandomAccessPattern = 0x8 | OuterRandomAccessPattern | InnerRand
// const int AccessPatternNotSupported = 0x0;
// const int AccessPatternSupported = 0x1;
//
//
// template<typename MatrixType, int AccessPattern> struct ei_support_access_pattern
// {
// enum { ret = (int(ei_traits<MatrixType>::SupportedAccessPatterns) & AccessPattern) == AccessPattern

View File

@@ -38,6 +38,7 @@ template<typename _Scalar, int _Options>
struct ei_traits<SparseVector<_Scalar, _Options> >
{
typedef _Scalar Scalar;
typedef Sparse StorageType;
enum {
IsColVector = _Options & RowMajorBit ? 0 : 1,