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

@@ -52,7 +52,7 @@ struct ei_traits<DynamicSparseMatrix<_Scalar, _Flags> >
ColsAtCompileTime = Dynamic,
MaxRowsAtCompileTime = Dynamic,
MaxColsAtCompileTime = Dynamic,
Flags = SparseBit | _Flags,
Flags = _Flags,
CoeffReadCost = NumTraits<Scalar>::ReadCost,
SupportedAccessPatterns = OuterRandomAccessPattern
};

View File

@@ -1,179 +0,0 @@
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
// 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/>.
#if 0
#ifndef EIGEN_SPARSE_CWISE_H
#define EIGEN_SPARSE_CWISE_H
/** \internal
* convenient macro to defined the return type of a cwise binary operation */
#define EIGEN_SPARSE_CWISE_BINOP_RETURN_TYPE(OP) \
CwiseBinaryOp<OP<typename ei_traits<ExpressionType>::Scalar>, ExpressionType, OtherDerived>
#define EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE \
SparseCwiseBinaryOp< \
ei_scalar_product_op< \
typename ei_scalar_product_traits< \
typename ei_traits<ExpressionType>::Scalar, \
typename ei_traits<OtherDerived>::Scalar \
>::ReturnType \
>, \
ExpressionType, \
OtherDerived \
>
/** \internal
* convenient macro to defined the return type of a cwise unary operation */
#define EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(OP) \
SparseCwiseUnaryOp<OP<typename ei_traits<ExpressionType>::Scalar>, ExpressionType>
/** \internal
* convenient macro to defined the return type of a cwise comparison to a scalar */
/*#define EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(OP) \
CwiseBinaryOp<OP<typename ei_traits<ExpressionType>::Scalar>, ExpressionType, \
NestByValue<typename ExpressionType::ConstantReturnType> >*/
template<typename ExpressionType> class SparseCwise
{
public:
typedef typename ei_traits<ExpressionType>::Scalar Scalar;
typedef typename ei_meta_if<ei_must_nest_by_value<ExpressionType>::ret,
ExpressionType, const ExpressionType&>::ret ExpressionTypeNested;
typedef CwiseUnaryOp<ei_scalar_add_op<Scalar>, ExpressionType> ScalarAddReturnType;
inline SparseCwise(const ExpressionType& matrix) : m_matrix(matrix) {}
/** \internal */
inline const ExpressionType& _expression() const { return m_matrix; }
template<typename OtherDerived>
const EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE
operator*(const SparseMatrixBase<OtherDerived> &other) const;
template<typename OtherDerived>
const EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE
operator*(const MatrixBase<OtherDerived> &other) const;
// template<typename OtherDerived>
// const EIGEN_SPARSE_CWISE_BINOP_RETURN_TYPE(ei_scalar_quotient_op)
// operator/(const SparseMatrixBase<OtherDerived> &other) const;
//
// template<typename OtherDerived>
// const EIGEN_SPARSE_CWISE_BINOP_RETURN_TYPE(ei_scalar_quotient_op)
// operator/(const MatrixBase<OtherDerived> &other) const;
template<typename OtherDerived>
const EIGEN_SPARSE_CWISE_BINOP_RETURN_TYPE(ei_scalar_min_op)
min(const SparseMatrixBase<OtherDerived> &other) const;
template<typename OtherDerived>
const EIGEN_SPARSE_CWISE_BINOP_RETURN_TYPE(ei_scalar_max_op)
max(const SparseMatrixBase<OtherDerived> &other) const;
const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_abs_op) abs() const;
const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_abs2_op) abs2() const;
// const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_square_op) square() const;
// const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_cube_op) cube() const;
// const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_inverse_op) inverse() const;
// const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_sqrt_op) sqrt() const;
// const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_exp_op) exp() const;
// const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_log_op) log() const;
// const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_cos_op) cos() const;
// const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_sin_op) sin() const;
// const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_pow_op) pow(const Scalar& exponent) const;
template<typename OtherDerived>
inline ExpressionType& operator*=(const SparseMatrixBase<OtherDerived> &other);
// template<typename OtherDerived>
// inline ExpressionType& operator/=(const SparseMatrixBase<OtherDerived> &other);
/*
template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less)
operator<(const MatrixBase<OtherDerived>& other) const;
template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal)
operator<=(const MatrixBase<OtherDerived>& other) const;
template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)
operator>(const MatrixBase<OtherDerived>& other) const;
template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)
operator>=(const MatrixBase<OtherDerived>& other) const;
template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to)
operator==(const MatrixBase<OtherDerived>& other) const;
template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to)
operator!=(const MatrixBase<OtherDerived>& other) const;
// comparisons to a scalar value
const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less)
operator<(Scalar s) const;
const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less_equal)
operator<=(Scalar s) const;
const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater)
operator>(Scalar s) const;
const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal)
operator>=(Scalar s) const;
const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to)
operator==(Scalar s) const;
const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::not_equal_to)
operator!=(Scalar s) const;
*/
// allow to extend SparseCwise outside Eigen
#ifdef EIGEN_SPARSE_CWISE_PLUGIN
#include EIGEN_SPARSE_CWISE_PLUGIN
#endif
protected:
ExpressionTypeNested m_matrix;
};
// template<typename Derived>
// inline const SparseCwise<Derived>
// SparseMatrixBase<Derived>::cwise() const
// {
// return derived();
// }
//
// template<typename Derived>
// inline SparseCwise<Derived>
// SparseMatrixBase<Derived>::cwise()
// {
// return derived();
// }
#endif // EIGEN_SPARSE_CWISE_H
#endif

View File

@@ -95,8 +95,8 @@ class CwiseBinaryOpImpl<BinaryOp, Lhs, Rhs, Sparse>
};
template<typename BinaryOp, typename Lhs, typename Rhs, typename Derived,
int _LhsStorageMode = int(Lhs::Flags) & SparseBit,
int _RhsStorageMode = int(Rhs::Flags) & SparseBit>
typename _LhsStorageMode = typename ei_traits<Lhs>::StorageType,
typename _RhsStorageMode = typename ei_traits<Rhs>::StorageType>
class ei_sparse_cwise_binary_op_inner_iterator_selector;
template<typename BinaryOp, typename Lhs, typename Rhs>
@@ -123,7 +123,7 @@ class CwiseBinaryOpImpl<BinaryOp,Lhs,Rhs,Sparse>::InnerIterator
// sparse - sparse (generic)
template<typename BinaryOp, typename Lhs, typename Rhs, typename Derived>
class ei_sparse_cwise_binary_op_inner_iterator_selector<BinaryOp, Lhs, Rhs, Derived, IsSparse, IsSparse>
class ei_sparse_cwise_binary_op_inner_iterator_selector<BinaryOp, Lhs, Rhs, Derived, Sparse, Sparse>
{
typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> CwiseBinaryXpr;
typedef typename ei_traits<CwiseBinaryXpr>::Scalar Scalar;
@@ -185,7 +185,7 @@ class ei_sparse_cwise_binary_op_inner_iterator_selector<BinaryOp, Lhs, Rhs, Deri
// sparse - sparse (product)
template<typename T, typename Lhs, typename Rhs, typename Derived>
class ei_sparse_cwise_binary_op_inner_iterator_selector<ei_scalar_product_op<T>, Lhs, Rhs, Derived, IsSparse, IsSparse>
class ei_sparse_cwise_binary_op_inner_iterator_selector<ei_scalar_product_op<T>, Lhs, Rhs, Derived, Sparse, Sparse>
{
typedef ei_scalar_product_op<T> BinaryFunc;
typedef CwiseBinaryOp<BinaryFunc, Lhs, Rhs> CwiseBinaryXpr;
@@ -238,7 +238,7 @@ class ei_sparse_cwise_binary_op_inner_iterator_selector<ei_scalar_product_op<T>,
// sparse - dense (product)
template<typename T, typename Lhs, typename Rhs, typename Derived>
class ei_sparse_cwise_binary_op_inner_iterator_selector<ei_scalar_product_op<T>, Lhs, Rhs, Derived, IsSparse, IsDense>
class ei_sparse_cwise_binary_op_inner_iterator_selector<ei_scalar_product_op<T>, Lhs, Rhs, Derived, Sparse, Dense>
{
typedef ei_scalar_product_op<T> BinaryFunc;
typedef CwiseBinaryOp<BinaryFunc, Lhs, Rhs> CwiseBinaryXpr;
@@ -278,7 +278,7 @@ class ei_sparse_cwise_binary_op_inner_iterator_selector<ei_scalar_product_op<T>,
// sparse - dense (product)
template<typename T, typename Lhs, typename Rhs, typename Derived>
class ei_sparse_cwise_binary_op_inner_iterator_selector<ei_scalar_product_op<T>, Lhs, Rhs, Derived, IsDense, IsSparse>
class ei_sparse_cwise_binary_op_inner_iterator_selector<ei_scalar_product_op<T>, Lhs, Rhs, Derived, Dense, Sparse>
{
typedef ei_scalar_product_op<T> BinaryFunc;
typedef CwiseBinaryOp<BinaryFunc, Lhs, Rhs> CwiseBinaryXpr;

View File

@@ -43,21 +43,22 @@ struct ei_traits<SparseDiagonalProduct<Lhs, Rhs> >
typedef typename ei_cleantype<Lhs>::type _Lhs;
typedef typename ei_cleantype<Rhs>::type _Rhs;
typedef typename _Lhs::Scalar Scalar;
typedef Sparse StorageType;
enum {
RowsAtCompileTime = _Lhs::RowsAtCompileTime,
ColsAtCompileTime = _Rhs::ColsAtCompileTime,
MaxRowsAtCompileTime = _Lhs::MaxRowsAtCompileTime,
MaxColsAtCompileTime = _Rhs::MaxColsAtCompileTime,
SparseFlags = ei_is_diagonal<_Lhs>::ret ? int(_Rhs::Flags) : int(_Lhs::Flags),
Flags = SparseBit | (SparseFlags&RowMajorBit),
Flags = (SparseFlags&RowMajorBit),
CoeffReadCost = Dynamic
};
};
enum {SDP_IsDiagonal, SDP_IsSparseRowMajor, SDP_IsSparseColMajor};
template<typename Lhs, typename Rhs, typename SparseDiagonalProductType, int RhsMode, int LhsMode>
template<typename Lhs, typename Rhs, typename SparseDiagonalProductType, int RhsMode, int LhsMode>
class ei_sparse_diagonal_product_inner_iterator_selector;
template<typename Lhs, typename Rhs>
@@ -70,7 +71,7 @@ class SparseDiagonalProduct
typedef typename ei_cleantype<LhsNested>::type _LhsNested;
typedef typename ei_cleantype<RhsNested>::type _RhsNested;
enum {
LhsMode = ei_is_diagonal<_LhsNested>::ret ? SDP_IsDiagonal
: (_LhsNested::Flags&RowMajorBit) ? SDP_IsSparseRowMajor : SDP_IsSparseColMajor,
@@ -81,7 +82,7 @@ class SparseDiagonalProduct
public:
EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(SparseDiagonalProduct)
typedef ei_sparse_diagonal_product_inner_iterator_selector
<_LhsNested,_RhsNested,SparseDiagonalProduct,LhsMode,RhsMode> InnerIterator;

View File

@@ -1,49 +0,0 @@
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2009 Gael Guennebaud <g.gael@free.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/>.
#if 0
#ifndef EIGEN_SPARSE_EXPRESSIONMAKER_H
#define EIGEN_SPARSE_EXPRESSIONMAKER_H
template<typename XprType>
struct MakeNestByValue<XprType,IsSparse>
{
typedef SparseNestByValue<XprType> Type;
};
template<typename Func, typename XprType>
struct MakeCwiseUnaryOp<Func,XprType,IsSparse>
{
typedef SparseCwiseUnaryOp<Func,XprType> Type;
};
template<typename Func, typename A, typename B>
struct MakeCwiseBinaryOp<Func,A,B,IsSparse>
{
typedef SparseCwiseBinaryOp<Func,A,B> Type;
};
// TODO complete the list
#endif // EIGEN_SPARSE_EXPRESSIONMAKER_H
#endif

View File

@@ -1,97 +0,0 @@
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
// Copyright (C) 2008 Gael Guennebaud <g.gael@free.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_SPARSE_FLAGGED_H
#define EIGEN_SPARSE_FLAGGED_H
template<typename ExpressionType, unsigned int Added, unsigned int Removed>
struct ei_traits<SparseFlagged<ExpressionType, Added, Removed> > : ei_traits<ExpressionType>
{
enum { Flags = (ExpressionType::Flags | Added) & ~Removed };
};
template<typename ExpressionType, unsigned int Added, unsigned int Removed> class SparseFlagged
: public SparseMatrixBase<SparseFlagged<ExpressionType, Added, Removed> >
{
public:
EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(SparseFlagged)
class InnerIterator;
class ReverseInnerIterator;
typedef typename ei_meta_if<ei_must_nest_by_value<ExpressionType>::ret,
ExpressionType, const ExpressionType&>::ret ExpressionTypeNested;
inline SparseFlagged(const ExpressionType& matrix) : m_matrix(matrix) {}
inline int rows() const { return m_matrix.rows(); }
inline int cols() const { return m_matrix.cols(); }
// FIXME should be keep them ?
inline Scalar& coeffRef(int row, int col)
{ return m_matrix.const_cast_derived().coeffRef(col, row); }
inline const Scalar coeff(int row, int col) const
{ return m_matrix.coeff(col, row); }
inline const Scalar coeff(int index) const
{ return m_matrix.coeff(index); }
inline Scalar& coeffRef(int index)
{ return m_matrix.const_cast_derived().coeffRef(index); }
protected:
ExpressionTypeNested m_matrix;
};
template<typename ExpressionType, unsigned int Added, unsigned int Removed>
class SparseFlagged<ExpressionType,Added,Removed>::InnerIterator : public ExpressionType::InnerIterator
{
public:
EIGEN_STRONG_INLINE InnerIterator(const SparseFlagged& xpr, int outer)
: ExpressionType::InnerIterator(xpr.m_matrix, outer)
{}
};
template<typename ExpressionType, unsigned int Added, unsigned int Removed>
class SparseFlagged<ExpressionType,Added,Removed>::ReverseInnerIterator : public ExpressionType::ReverseInnerIterator
{
public:
EIGEN_STRONG_INLINE ReverseInnerIterator(const SparseFlagged& xpr, int outer)
: ExpressionType::ReverseInnerIterator(xpr.m_matrix, outer)
{}
};
template<typename Derived>
template<unsigned int Added>
inline const SparseFlagged<Derived, Added, 0>
SparseMatrixBase<Derived>::marked() const
{
return derived();
}
#endif // EIGEN_SPARSE_FLAGGED_H

View File

@@ -51,7 +51,7 @@ struct ei_traits<SparseMatrix<_Scalar, _Options> >
ColsAtCompileTime = Dynamic,
MaxRowsAtCompileTime = Dynamic,
MaxColsAtCompileTime = Dynamic,
Flags = SparseBit | _Options,
Flags = _Options,
CoeffReadCost = NumTraits<Scalar>::ReadCost,
SupportedAccessPatterns = InnerRandomAccessPattern
};

View File

@@ -36,16 +36,13 @@
*
*
*/
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 SparseMatrixBase Self;
typedef SparseMatrixBase StorageBaseType;
enum {
@@ -112,7 +109,9 @@ template<typename Derived> class SparseMatrixBase : public AnyMatrixBase<Derived
Transpose<Derived>
>::ret AdjointReturnType;
#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::SparseMatrixBase
#include "../Core/CwiseUnaryOps.h"
#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
#ifndef EIGEN_PARSED_BY_DOXYGEN
/** This is the "real scalar" type; if the \a Scalar type is already real numbers
@@ -534,8 +533,8 @@ template<typename Derived> class SparseMatrixBase : public AnyMatrixBase<Derived
// template<typename OtherDerived>
// void swap(MatrixBase<OtherDerived> EIGEN_REF_TO_TEMPORARY other);
template<unsigned int Added>
const SparseFlagged<Derived, Added, 0> marked() const;
// template<unsigned int Added>
// const SparseFlagged<Derived, Added, 0> marked() const;
// const Flagged<Derived, 0, EvalBeforeNestingBit | EvalBeforeAssigningBit> lazy() const;
/** \returns number of elements to skip to pass from one row (resp. column) to another

View File

@@ -25,16 +25,9 @@
#ifndef EIGEN_SPARSEPRODUCT_H
#define EIGEN_SPARSEPRODUCT_H
template<typename Lhs, typename Rhs> struct ei_sparse_product_mode
{
enum {
value = (Rhs::Flags&Lhs::Flags&SparseBit)==SparseBit
? SparseTimeSparseProduct
: (Lhs::Flags&SparseBit)==SparseBit
? SparseTimeDenseProduct
: DenseTimeSparseProduct };
};
template<typename Lhs, typename Rhs> struct ei_sparse_product_mode<Lhs,Rhs,Sparse,Sparse> { enum { value = SparseTimeSparseProduct }; };
template<typename Lhs, typename Rhs> struct ei_sparse_product_mode<Lhs,Rhs,Dense, Sparse> { enum { value = DenseTimeSparseProduct }; };
template<typename Lhs, typename Rhs> struct ei_sparse_product_mode<Lhs,Rhs,Sparse,Dense> { enum { value = SparseTimeDenseProduct }; };
template<typename Lhs, typename Rhs, int ProductMode>
struct SparseProductReturnType
@@ -91,13 +84,10 @@ struct ei_traits<SparseProduct<LhsNested, RhsNested, ProductMode> >
MaxRowsAtCompileTime = _LhsNested::MaxRowsAtCompileTime,
MaxColsAtCompileTime = _RhsNested::MaxColsAtCompileTime,
// LhsIsRowMajor = (LhsFlags & RowMajorBit)==RowMajorBit,
// RhsIsRowMajor = (RhsFlags & RowMajorBit)==RowMajorBit,
EvalToRowMajor = (RhsFlags & LhsFlags & RowMajorBit),
ResultIsSparse = ProductMode==SparseTimeSparseProduct,
RemovedBits = ~( (EvalToRowMajor ? 0 : RowMajorBit) | (ResultIsSparse ? 0 : SparseBit) ),
RemovedBits = ~(EvalToRowMajor ? 0 : RowMajorBit),
Flags = (int(LhsFlags | RhsFlags) & HereditaryBits & RemovedBits)
| EvalBeforeAssigningBit
@@ -106,6 +96,8 @@ struct ei_traits<SparseProduct<LhsNested, RhsNested, ProductMode> >
CoeffReadCost = Dynamic
};
typedef typename ei_meta_if<ResultIsSparse, Sparse, Dense>::ret StorageType;
typedef typename ei_meta_if<ResultIsSparse,
SparseMatrixBase<SparseProduct<LhsNested, RhsNested, ProductMode> >,
MatrixBase<SparseProduct<LhsNested, RhsNested, ProductMode> > >::ret Base;

View File

@@ -1,7 +1,7 @@
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
// Copyright (C) 2008-2009 Gael Guennebaud <g.gael@free.fr>
//
// Eigen is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@@ -25,51 +25,30 @@
#ifndef EIGEN_SPARSETRANSPOSE_H
#define EIGEN_SPARSETRANSPOSE_H
// template<typename MatrixType>
// struct ei_traits<SparseTranspose<MatrixType> > : ei_traits<Transpose<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_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) {}
//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 matrix().nonZeros(); }
inline int nonZeros() const { return derived().nestedExpression().nonZeros(); }
// FIXME should be keep them ?
inline Scalar& coeffRef(int row, int col)
{ return matrix().const_cast_derived().coeffRef(col, row); }
{ return const_cast_derived().nestedExpression().coeffRef(col, row); }
inline const Scalar coeff(int row, int col) const
{ return matrix().coeff(col, row); }
{ return derived().nestedExpression().coeff(col, row); }
inline const Scalar coeff(int index) const
{ return matrix().coeff(index); }
{ return derived().nestedExpression().coeff(index); }
inline Scalar& coeffRef(int index)
{ return matrix().const_cast_derived().coeffRef(index); }
// protected:
// const typename MatrixType::Nested m_matrix;
{ return const_cast_derived().nestedExpression().coeffRef(index); }
};
template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>::InnerIterator : public MatrixType::InnerIterator
@@ -78,7 +57,7 @@ template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>::InnerItera
public:
EIGEN_STRONG_INLINE InnerIterator(const TransposeImpl& trans, int outer)
: Base(trans.matrix(), outer)
: Base(trans.derived().nestedExpression(), outer)
{}
inline int row() const { return Base::col(); }
inline int col() const { return Base::row(); }
@@ -90,7 +69,7 @@ template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>::ReverseInn
public:
EIGEN_STRONG_INLINE ReverseInnerIterator(const TransposeImpl& xpr, int outer)
: Base(xpr.matrix(), outer)
: Base(xpr.derived().nestedExpression(), outer)
{}
inline int row() const { return Base::col(); }
inline int col() const { return Base::row(); }

View File

@@ -82,7 +82,8 @@ enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \
CoeffReadCost = Eigen::ei_traits<Derived>::CoeffReadCost, \
SizeAtCompileTime = Base::SizeAtCompileTime, \
IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; \
using Base::derived;
using Base::derived; \
using Base::const_cast_derived;
#define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived) \
_EIGEN_SPARSE_PUBLIC_INTERFACE(Derived, Eigen::SparseMatrixBase<Derived>)
@@ -129,7 +130,10 @@ template<typename ExpressionType,
template<typename ExpressionType, int Mode> class SparseTriangular;
template<typename Lhs, typename Rhs> class SparseDiagonalProduct;
template<typename Lhs, typename Rhs> struct ei_sparse_product_mode;
template<typename Lhs, typename Rhs,
typename LhsStorage = typename ei_traits<Lhs>::StorageType,
typename RhsStorage = typename ei_traits<Rhs>::StorageType> struct ei_sparse_product_mode;
template<typename Lhs, typename Rhs, int ProductMode = ei_sparse_product_mode<Lhs,Rhs>::value> struct SparseProductReturnType;
const int CoherentAccessPattern = 0x1;
@@ -137,18 +141,7 @@ const int InnerRandomAccessPattern = 0x2 | CoherentAccessPattern;
const int OuterRandomAccessPattern = 0x4 | CoherentAccessPattern;
const int RandomAccessPattern = 0x8 | OuterRandomAccessPattern | InnerRandomAccessPattern;
// 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
// ? AccessPatternSupported
// : AccessPatternNotSupported
// };
// };
template<typename T> class ei_eval<T,IsSparse>
template<typename T> class ei_eval<T,Sparse>
{
typedef typename ei_traits<T>::Scalar _Scalar;
enum {

View File

@@ -46,7 +46,7 @@ struct ei_traits<SparseVector<_Scalar, _Options> >
ColsAtCompileTime = IsColVector ? 1 : Dynamic,
MaxRowsAtCompileTime = RowsAtCompileTime,
MaxColsAtCompileTime = ColsAtCompileTime,
Flags = SparseBit | _Options,
Flags = _Options,
CoeffReadCost = NumTraits<Scalar>::ReadCost,
SupportedAccessPatterns = InnerRandomAccessPattern
};