* remove ei_index, and let ei_traits propagate the index types

* add an Index type template parapeter to sparse objects
This commit is contained in:
Gael Guennebaud 2010-06-03 08:41:11 +02:00
parent 38d8352b7b
commit 8350ab9fb8
40 changed files with 162 additions and 156 deletions

View File

@ -61,7 +61,7 @@ template<typename Derived> class ArrayBase
typename NumTraits<typename ei_traits<Derived>::Scalar>::Real>::operator*; typename NumTraits<typename ei_traits<Derived>::Scalar>::Real>::operator*;
typedef typename ei_traits<Derived>::StorageKind StorageKind; typedef typename ei_traits<Derived>::StorageKind StorageKind;
typedef typename ei_index<StorageKind>::type Index; typedef typename ei_traits<Derived>::Index Index;
typedef typename ei_traits<Derived>::Scalar Scalar; typedef typename ei_traits<Derived>::Scalar Scalar;
typedef typename ei_packet_traits<Scalar>::type PacketScalar; typedef typename ei_packet_traits<Scalar>::type PacketScalar;
typedef typename NumTraits<Scalar>::Real RealScalar; typedef typename NumTraits<Scalar>::Real RealScalar;

View File

@ -47,6 +47,7 @@ struct ei_traits<BandMatrix<_Scalar,Rows,Cols,Supers,Subs,Options> >
{ {
typedef _Scalar Scalar; typedef _Scalar Scalar;
typedef Dense StorageKind; typedef Dense StorageKind;
typedef DenseIndex Index;
enum { enum {
CoeffReadCost = NumTraits<Scalar>::ReadCost, CoeffReadCost = NumTraits<Scalar>::ReadCost,
RowsAtCompileTime = Rows, RowsAtCompileTime = Rows,

View File

@ -57,6 +57,8 @@ struct ei_traits<CwiseBinaryOp<BinaryOp, Lhs, Rhs> > : ei_traits<Lhs>
>::type Scalar; >::type Scalar;
typedef typename ei_promote_storage_type<typename ei_traits<Lhs>::StorageKind, typedef typename ei_promote_storage_type<typename ei_traits<Lhs>::StorageKind,
typename ei_traits<Rhs>::StorageKind>::ret StorageKind; typename ei_traits<Rhs>::StorageKind>::ret StorageKind;
typedef typename ei_promote_index_type<typename ei_traits<Lhs>::Index,
typename ei_traits<Rhs>::Index>::type Index;
typedef typename Lhs::Nested LhsNested; typedef typename Lhs::Nested LhsNested;
typedef typename Rhs::Nested RhsNested; typedef typename Rhs::Nested RhsNested;
typedef typename ei_unref<LhsNested>::type _LhsNested; typedef typename ei_unref<LhsNested>::type _LhsNested;
@ -97,7 +99,7 @@ class CwiseBinaryOp : ei_no_assignment_operator,
BinaryOp, Lhs, Rhs, BinaryOp, Lhs, Rhs,
typename ei_promote_storage_type<typename ei_traits<Lhs>::StorageKind, typename ei_promote_storage_type<typename ei_traits<Lhs>::StorageKind,
typename ei_traits<Rhs>::StorageKind>::ret>::Base Base; typename ei_traits<Rhs>::StorageKind>::ret>::Base Base;
EIGEN_GENERIC_PUBLIC_INTERFACE_NEW(CwiseBinaryOp) EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseBinaryOp)
typedef typename ei_nested<Lhs>::type LhsNested; typedef typename ei_nested<Lhs>::type LhsNested;
typedef typename ei_nested<Rhs>::type RhsNested; typedef typename ei_nested<Rhs>::type RhsNested;
@ -125,14 +127,14 @@ class CwiseBinaryOp : ei_no_assignment_operator,
EIGEN_STRONG_INLINE Index rows() const { EIGEN_STRONG_INLINE Index rows() const {
// return the fixed size type if available to enable compile time optimizations // return the fixed size type if available to enable compile time optimizations
if (ei_traits<typename ei_cleantype<LhsNested>::type>::RowsAtCompileTime==Dynamic) if (ei_traits<typename ei_cleantype<LhsNested>::type>::RowsAtCompileTime==Dynamic)
return m_rhs.rows(); return m_rhs.rows();
else else
return m_lhs.rows(); return m_lhs.rows();
} }
EIGEN_STRONG_INLINE Index cols() const { EIGEN_STRONG_INLINE Index cols() const {
// return the fixed size type if available to enable compile time optimizations // return the fixed size type if available to enable compile time optimizations
if (ei_traits<typename ei_cleantype<LhsNested>::type>::ColsAtCompileTime==Dynamic) if (ei_traits<typename ei_cleantype<LhsNested>::type>::ColsAtCompileTime==Dynamic)
return m_rhs.cols(); return m_rhs.cols();
else else
return m_lhs.cols(); return m_lhs.cols();

View File

@ -71,7 +71,7 @@ class CwiseUnaryOp : ei_no_assignment_operator,
public: public:
typedef typename CwiseUnaryOpImpl<UnaryOp, XprType,typename ei_traits<XprType>::StorageKind>::Base Base; typedef typename CwiseUnaryOpImpl<UnaryOp, XprType,typename ei_traits<XprType>::StorageKind>::Base Base;
EIGEN_GENERIC_PUBLIC_INTERFACE_NEW(CwiseUnaryOp) EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp)
inline CwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp()) inline CwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp())
: m_xpr(xpr), m_functor(func) {} : m_xpr(xpr), m_functor(func) {}

View File

@ -67,7 +67,7 @@ class CwiseUnaryView : ei_no_assignment_operator,
public: public:
typedef typename CwiseUnaryViewImpl<ViewOp, MatrixType,typename ei_traits<MatrixType>::StorageKind>::Base Base; typedef typename CwiseUnaryViewImpl<ViewOp, MatrixType,typename ei_traits<MatrixType>::StorageKind>::Base Base;
EIGEN_GENERIC_PUBLIC_INTERFACE_NEW(CwiseUnaryView) EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView)
inline CwiseUnaryView(const MatrixType& mat, const ViewOp& func = ViewOp()) inline CwiseUnaryView(const MatrixType& mat, const ViewOp& func = ViewOp())
: m_matrix(mat), m_functor(func) {} : m_matrix(mat), m_functor(func) {}

View File

@ -51,7 +51,7 @@ template<typename Derived> class DenseBase
class InnerIterator; class InnerIterator;
typedef typename ei_traits<Derived>::StorageKind StorageKind; typedef typename ei_traits<Derived>::StorageKind StorageKind;
typedef typename ei_index<StorageKind>::type Index; typedef typename ei_traits<Derived>::Index Index;
typedef typename ei_traits<Derived>::Scalar Scalar; typedef typename ei_traits<Derived>::Scalar Scalar;
typedef typename ei_packet_traits<Scalar>::type PacketScalar; typedef typename ei_packet_traits<Scalar>::type PacketScalar;
typedef typename NumTraits<Scalar>::Real RealScalar; typedef typename NumTraits<Scalar>::Real RealScalar;

View File

@ -30,7 +30,7 @@ class DenseCoeffsBase : public EigenBase<Derived>
{ {
public: public:
typedef typename ei_traits<Derived>::StorageKind StorageKind; typedef typename ei_traits<Derived>::StorageKind StorageKind;
typedef typename ei_index<StorageKind>::type Index; typedef typename ei_traits<Derived>::Index Index;
typedef typename ei_traits<Derived>::Scalar Scalar; typedef typename ei_traits<Derived>::Scalar Scalar;
typedef typename ei_packet_traits<Scalar>::type PacketScalar; typedef typename ei_packet_traits<Scalar>::type PacketScalar;
typedef typename ei_meta_if<ei_has_direct_access<Derived>::ret, const Scalar&, Scalar>::ret CoeffReturnType; typedef typename ei_meta_if<ei_has_direct_access<Derived>::ret, const Scalar&, Scalar>::ret CoeffReturnType;
@ -40,7 +40,7 @@ class DenseCoeffsBase : public EigenBase<Derived>
using Base::cols; using Base::cols;
using Base::size; using Base::size;
using Base::derived; using Base::derived;
EIGEN_STRONG_INLINE Index rowIndexByOuterInner(Index outer, Index inner) const EIGEN_STRONG_INLINE Index rowIndexByOuterInner(Index outer, Index inner) const
{ {
return int(Derived::RowsAtCompileTime) == 1 ? 0 return int(Derived::RowsAtCompileTime) == 1 ? 0
@ -245,7 +245,7 @@ class DenseCoeffsBase<Derived, true> : public DenseCoeffsBase<Derived, false>
typedef DenseCoeffsBase<Derived, false> Base; typedef DenseCoeffsBase<Derived, false> Base;
typedef typename ei_traits<Derived>::StorageKind StorageKind; typedef typename ei_traits<Derived>::StorageKind StorageKind;
typedef typename ei_index<StorageKind>::type Index; typedef typename ei_traits<Derived>::Index Index;
typedef typename ei_traits<Derived>::Scalar Scalar; typedef typename ei_traits<Derived>::Scalar Scalar;
typedef typename ei_packet_traits<Scalar>::type PacketScalar; typedef typename ei_packet_traits<Scalar>::type PacketScalar;
typedef typename NumTraits<Scalar>::Real RealScalar; typedef typename NumTraits<Scalar>::Real RealScalar;

View File

@ -46,7 +46,7 @@ class DenseStorageBase : public ei_dense_xpr_base<Derived>::type
typedef typename ei_dense_xpr_base<Derived>::type Base; typedef typename ei_dense_xpr_base<Derived>::type Base;
typedef typename ei_traits<Derived>::StorageKind StorageKind; typedef typename ei_traits<Derived>::StorageKind StorageKind;
typedef typename ei_index<StorageKind>::type Index; typedef typename ei_traits<Derived>::Index Index;
typedef typename ei_traits<Derived>::Scalar Scalar; typedef typename ei_traits<Derived>::Scalar Scalar;
typedef typename ei_packet_traits<Scalar>::type PacketScalar; typedef typename ei_packet_traits<Scalar>::type PacketScalar;
typedef typename NumTraits<Scalar>::Real RealScalar; typedef typename NumTraits<Scalar>::Real RealScalar;

View File

@ -34,7 +34,7 @@ class DiagonalBase : public EigenBase<Derived>
typedef typename ei_traits<Derived>::DiagonalVectorType DiagonalVectorType; typedef typename ei_traits<Derived>::DiagonalVectorType DiagonalVectorType;
typedef typename DiagonalVectorType::Scalar Scalar; typedef typename DiagonalVectorType::Scalar Scalar;
typedef typename ei_traits<Derived>::StorageKind StorageKind; typedef typename ei_traits<Derived>::StorageKind StorageKind;
typedef typename ei_index<StorageKind>::type Index; typedef typename ei_traits<Derived>::Index Index;
enum { enum {
RowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime, RowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
@ -103,6 +103,7 @@ struct ei_traits<DiagonalMatrix<_Scalar,SizeAtCompileTime,MaxSizeAtCompileTime>
{ {
typedef Matrix<_Scalar,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1> DiagonalVectorType; typedef Matrix<_Scalar,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1> DiagonalVectorType;
typedef Dense StorageKind; typedef Dense StorageKind;
typedef DenseIndex Index;
}; };
template<typename _Scalar, int SizeAtCompileTime, int MaxSizeAtCompileTime> template<typename _Scalar, int SizeAtCompileTime, int MaxSizeAtCompileTime>
@ -115,7 +116,7 @@ class DiagonalMatrix
typedef const DiagonalMatrix& Nested; typedef const DiagonalMatrix& Nested;
typedef _Scalar Scalar; typedef _Scalar Scalar;
typedef typename ei_traits<DiagonalMatrix>::StorageKind StorageKind; typedef typename ei_traits<DiagonalMatrix>::StorageKind StorageKind;
typedef typename ei_index<StorageKind>::type Index; typedef typename ei_traits<DiagonalMatrix>::Index Index;
#endif #endif
protected: protected:
@ -203,6 +204,7 @@ struct ei_traits<DiagonalWrapper<_DiagonalVectorType> >
{ {
typedef _DiagonalVectorType DiagonalVectorType; typedef _DiagonalVectorType DiagonalVectorType;
typedef typename DiagonalVectorType::Scalar Scalar; typedef typename DiagonalVectorType::Scalar Scalar;
typedef typename DiagonalVectorType::Index Index;
typedef typename DiagonalVectorType::StorageKind StorageKind; typedef typename DiagonalVectorType::StorageKind StorageKind;
enum { enum {
RowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime, RowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,

View File

@ -40,7 +40,7 @@ template<typename Derived> struct EigenBase
// typedef typename ei_plain_matrix_type<Derived>::type PlainObject; // typedef typename ei_plain_matrix_type<Derived>::type PlainObject;
typedef typename ei_traits<Derived>::StorageKind StorageKind; typedef typename ei_traits<Derived>::StorageKind StorageKind;
typedef typename ei_index<StorageKind>::type Index; typedef typename ei_traits<Derived>::Index Index;
/** \returns a reference to the derived object */ /** \returns a reference to the derived object */
Derived& derived() { return *static_cast<Derived*>(this); } Derived& derived() { return *static_cast<Derived*>(this); }

View File

@ -46,7 +46,7 @@ template<typename Derived> class MapBase
typedef typename ei_traits<Derived>::StorageKind StorageKind; typedef typename ei_traits<Derived>::StorageKind StorageKind;
typedef typename ei_index<StorageKind>::type Index; typedef typename ei_traits<Derived>::Index Index;
typedef typename ei_traits<Derived>::Scalar Scalar; typedef typename ei_traits<Derived>::Scalar Scalar;
typedef typename ei_packet_traits<Scalar>::type PacketScalar; typedef typename ei_packet_traits<Scalar>::type PacketScalar;
typedef typename NumTraits<Scalar>::Real RealScalar; typedef typename NumTraits<Scalar>::Real RealScalar;

View File

@ -113,6 +113,7 @@ struct ei_traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
{ {
typedef _Scalar Scalar; typedef _Scalar Scalar;
typedef Dense StorageKind; typedef Dense StorageKind;
typedef DenseIndex Index;
typedef MatrixXpr XprKind; typedef MatrixXpr XprKind;
enum { enum {
RowsAtCompileTime = _Rows, RowsAtCompileTime = _Rows,

View File

@ -58,11 +58,11 @@ template<typename Derived> class MatrixBase
#ifndef EIGEN_PARSED_BY_DOXYGEN #ifndef EIGEN_PARSED_BY_DOXYGEN
typedef MatrixBase StorageBaseType; typedef MatrixBase StorageBaseType;
typedef typename ei_traits<Derived>::StorageKind StorageKind; typedef typename ei_traits<Derived>::StorageKind StorageKind;
typedef typename ei_index<StorageKind>::type Index; typedef typename ei_traits<Derived>::Index Index;
typedef typename ei_traits<Derived>::Scalar Scalar; typedef typename ei_traits<Derived>::Scalar Scalar;
typedef typename ei_packet_traits<Scalar>::type PacketScalar; typedef typename ei_packet_traits<Scalar>::type PacketScalar;
typedef typename NumTraits<Scalar>::Real RealScalar; typedef typename NumTraits<Scalar>::Real RealScalar;
typedef DenseBase<Derived> Base; typedef DenseBase<Derived> Base;
using Base::RowsAtCompileTime; using Base::RowsAtCompileTime;
using Base::ColsAtCompileTime; using Base::ColsAtCompileTime;

View File

@ -37,6 +37,8 @@ struct ei_traits<ProductBase<Derived,_Lhs,_Rhs> >
typedef typename ei_scalar_product_traits<typename Lhs::Scalar, typename Rhs::Scalar>::ReturnType Scalar; typedef typename ei_scalar_product_traits<typename Lhs::Scalar, typename Rhs::Scalar>::ReturnType Scalar;
typedef typename ei_promote_storage_type<typename ei_traits<Lhs>::StorageKind, typedef typename ei_promote_storage_type<typename ei_traits<Lhs>::StorageKind,
typename ei_traits<Rhs>::StorageKind>::ret StorageKind; typename ei_traits<Rhs>::StorageKind>::ret StorageKind;
typedef typename ei_promote_index_type<typename ei_traits<Lhs>::Index,
typename ei_traits<Rhs>::Index>::type Index;
enum { enum {
RowsAtCompileTime = ei_traits<Lhs>::RowsAtCompileTime, RowsAtCompileTime = ei_traits<Lhs>::RowsAtCompileTime,
ColsAtCompileTime = ei_traits<Rhs>::ColsAtCompileTime, ColsAtCompileTime = ei_traits<Rhs>::ColsAtCompileTime,

View File

@ -66,7 +66,7 @@ template<typename MatrixType> class Transpose
public: public:
typedef typename TransposeImpl<MatrixType,typename ei_traits<MatrixType>::StorageKind>::Base Base; typedef typename TransposeImpl<MatrixType,typename ei_traits<MatrixType>::StorageKind>::Base Base;
EIGEN_GENERIC_PUBLIC_INTERFACE_NEW(Transpose) EIGEN_GENERIC_PUBLIC_INTERFACE(Transpose)
inline Transpose(const MatrixType& matrix) : m_matrix(matrix) {} inline Transpose(const MatrixType& matrix) : m_matrix(matrix) {}

View File

@ -46,7 +46,7 @@ template<typename Derived> class TriangularBase : public EigenBase<Derived>
}; };
typedef typename ei_traits<Derived>::Scalar Scalar; typedef typename ei_traits<Derived>::Scalar Scalar;
typedef typename ei_traits<Derived>::StorageKind StorageKind; typedef typename ei_traits<Derived>::StorageKind StorageKind;
typedef typename ei_index<StorageKind>::type Index; typedef typename ei_traits<Derived>::Index Index;
inline TriangularBase() { ei_assert(!((Mode&UnitDiag) && (Mode&ZeroDiag))); } inline TriangularBase() { ei_assert(!((Mode&UnitDiag) && (Mode&ZeroDiag))); }
@ -159,7 +159,7 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView
using Base::evalToLazy; using Base::evalToLazy;
typedef typename ei_traits<TriangularView>::StorageKind StorageKind; typedef typename ei_traits<TriangularView>::StorageKind StorageKind;
typedef typename ei_index<StorageKind>::type Index; typedef typename ei_traits<TriangularView>::Index Index;
enum { enum {
Mode = _Mode, Mode = _Mode,

View File

@ -54,6 +54,8 @@ struct ei_traits<CoeffBasedProduct<LhsNested,RhsNested,NestingFlags> >
typedef typename ei_scalar_product_traits<typename _LhsNested::Scalar, typename _RhsNested::Scalar>::ReturnType Scalar; typedef typename ei_scalar_product_traits<typename _LhsNested::Scalar, typename _RhsNested::Scalar>::ReturnType Scalar;
typedef typename ei_promote_storage_type<typename ei_traits<_LhsNested>::StorageKind, typedef typename ei_promote_storage_type<typename ei_traits<_LhsNested>::StorageKind,
typename ei_traits<_RhsNested>::StorageKind>::ret StorageKind; typename ei_traits<_RhsNested>::StorageKind>::ret StorageKind;
typedef typename ei_promote_index_type<typename ei_traits<_LhsNested>::Index,
typename ei_traits<_RhsNested>::Index>::type Index;
enum { enum {
LhsCoeffReadCost = _LhsNested::CoeffReadCost, LhsCoeffReadCost = _LhsNested::CoeffReadCost,

View File

@ -98,10 +98,6 @@
#define EIGEN_DEFAULT_DENSE_INDEX_TYPE std::ptrdiff_t #define EIGEN_DEFAULT_DENSE_INDEX_TYPE std::ptrdiff_t
#endif #endif
#ifndef EIGEN_DEFAULT_SPARSE_INDEX_TYPE
#define EIGEN_DEFAULT_SPARSE_INDEX_TYPE int
#endif
/** Allows to disable some optimizations which might affect the accuracy of the result. /** Allows to disable some optimizations which might affect the accuracy of the result.
* Such optimization are enabled by default, and set EIGEN_FAST_MATH to 0 to disable them. * Such optimization are enabled by default, and set EIGEN_FAST_MATH to 0 to disable them.
* They currently include: * They currently include:
@ -269,13 +265,13 @@
* documentation in a single line. * documentation in a single line.
**/ **/
#define EIGEN_GENERIC_PUBLIC_INTERFACE_NEW(Derived) \ #define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \
typedef typename Eigen::ei_traits<Derived>::Scalar Scalar; /*!< \brief Numeric type, e.g. float, double, int or std::complex<float>. */ \ typedef typename Eigen::ei_traits<Derived>::Scalar Scalar; /*!< \brief Numeric type, e.g. float, double, int or std::complex<float>. */ \
typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; /*!< \brief The underlying numeric type for composed scalar types. \details In cases where Scalar is e.g. std::complex<T>, T were corresponding to RealScalar. */ \ typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; /*!< \brief The underlying numeric type for composed scalar types. \details In cases where Scalar is e.g. std::complex<T>, T were corresponding to RealScalar. */ \
typedef typename Base::CoeffReturnType CoeffReturnType; /*!< \brief The return type for coefficient access. \details Depending on whether the object allows direct coefficient access (e.g. for a MatrixXd), this type is either 'const Scalar&' or simply 'Scalar' for objects that do not allow direct coefficient access. */ \ typedef typename Base::CoeffReturnType CoeffReturnType; /*!< \brief The return type for coefficient access. \details Depending on whether the object allows direct coefficient access (e.g. for a MatrixXd), this type is either 'const Scalar&' or simply 'Scalar' for objects that do not allow direct coefficient access. */ \
typedef typename Eigen::ei_nested<Derived>::type Nested; \ typedef typename Eigen::ei_nested<Derived>::type Nested; \
typedef typename Eigen::ei_traits<Derived>::StorageKind StorageKind; \ typedef typename Eigen::ei_traits<Derived>::StorageKind StorageKind; \
typedef typename Eigen::ei_index<StorageKind>::type Index; \ typedef typename Eigen::ei_traits<Derived>::Index Index; \
enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \ enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \
ColsAtCompileTime = Eigen::ei_traits<Derived>::ColsAtCompileTime, \ ColsAtCompileTime = Eigen::ei_traits<Derived>::ColsAtCompileTime, \
Flags = Eigen::ei_traits<Derived>::Flags, \ Flags = Eigen::ei_traits<Derived>::Flags, \
@ -292,7 +288,7 @@
typedef typename Base::CoeffReturnType CoeffReturnType; /*!< \brief The return type for coefficient access. \details Depending on whether the object allows direct coefficient access (e.g. for a MatrixXd), this type is either 'const Scalar&' or simply 'Scalar' for objects that do not allow direct coefficient access. */ \ typedef typename Base::CoeffReturnType CoeffReturnType; /*!< \brief The return type for coefficient access. \details Depending on whether the object allows direct coefficient access (e.g. for a MatrixXd), this type is either 'const Scalar&' or simply 'Scalar' for objects that do not allow direct coefficient access. */ \
typedef typename Eigen::ei_nested<Derived>::type Nested; \ typedef typename Eigen::ei_nested<Derived>::type Nested; \
typedef typename Eigen::ei_traits<Derived>::StorageKind StorageKind; \ typedef typename Eigen::ei_traits<Derived>::StorageKind StorageKind; \
typedef typename Eigen::ei_index<StorageKind>::type Index; \ typedef typename Eigen::ei_traits<Derived>::Index Index; \
enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \ enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \
ColsAtCompileTime = Eigen::ei_traits<Derived>::ColsAtCompileTime, \ ColsAtCompileTime = Eigen::ei_traits<Derived>::ColsAtCompileTime, \
MaxRowsAtCompileTime = Eigen::ei_traits<Derived>::MaxRowsAtCompileTime, \ MaxRowsAtCompileTime = Eigen::ei_traits<Derived>::MaxRowsAtCompileTime, \

View File

@ -42,13 +42,14 @@ class ei_no_assignment_operator
ei_no_assignment_operator& operator=(const ei_no_assignment_operator&); ei_no_assignment_operator& operator=(const ei_no_assignment_operator&);
}; };
template<typename StorageKind> struct ei_index {}; typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex;
template<> /** \internal return the index type with the largest number of bits */
struct ei_index<Dense> template<typename I1, typename I2>
{ typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE type; }; struct ei_promote_index_type
{
typedef ei_index<Dense>::type DenseIndex; typedef typename ei_meta_if<(sizeof(I1)<sizeof(I2)), I2, I1>::ret type;
};
/** \internal If the template parameter Value is Dynamic, this class is just a wrapper around a T variable that /** \internal If the template parameter Value is Dynamic, this class is just a wrapper around a T variable that
* can be accessed using value() and setValue(). * can be accessed using value() and setValue().

View File

@ -53,6 +53,7 @@ template<typename VectorsType, typename CoeffsType, int Side>
struct ei_traits<HouseholderSequence<VectorsType,CoeffsType,Side> > struct ei_traits<HouseholderSequence<VectorsType,CoeffsType,Side> >
{ {
typedef typename VectorsType::Scalar Scalar; typedef typename VectorsType::Scalar Scalar;
typedef typename VectorsType::Index Index;
typedef typename VectorsType::StorageKind StorageKind; typedef typename VectorsType::StorageKind StorageKind;
enum { enum {
RowsAtCompileTime = Side==OnTheLeft ? ei_traits<VectorsType>::RowsAtCompileTime RowsAtCompileTime = Side==OnTheLeft ? ei_traits<VectorsType>::RowsAtCompileTime

View File

@ -69,7 +69,7 @@ template<typename _MatrixType> class FullPivLU
typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::Scalar Scalar;
typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar; typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar;
typedef typename ei_traits<MatrixType>::StorageKind StorageKind; typedef typename ei_traits<MatrixType>::StorageKind StorageKind;
typedef typename ei_index<StorageKind>::type Index; typedef typename MatrixType::Index Index;
typedef typename ei_plain_row_type<MatrixType, Index>::type IntRowVectorType; typedef typename ei_plain_row_type<MatrixType, Index>::type IntRowVectorType;
typedef typename ei_plain_col_type<MatrixType, Index>::type IntColVectorType; typedef typename ei_plain_col_type<MatrixType, Index>::type IntColVectorType;
typedef PermutationMatrix<ColsAtCompileTime, MaxColsAtCompileTime> PermutationQType; typedef PermutationMatrix<ColsAtCompileTime, MaxColsAtCompileTime> PermutationQType;

View File

@ -72,7 +72,7 @@ template<typename _MatrixType> class PartialPivLU
typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::Scalar Scalar;
typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar; typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar;
typedef typename ei_traits<MatrixType>::StorageKind StorageKind; typedef typename ei_traits<MatrixType>::StorageKind StorageKind;
typedef typename ei_index<StorageKind>::type Index; typedef typename MatrixType::Index Index;
typedef typename ei_plain_col_type<MatrixType, Index>::type PermutationVectorType; typedef typename ei_plain_col_type<MatrixType, Index>::type PermutationVectorType;
typedef PermutationMatrix<RowsAtCompileTime, MaxRowsAtCompileTime> PermutationType; typedef PermutationMatrix<RowsAtCompileTime, MaxRowsAtCompileTime> PermutationType;

View File

@ -30,12 +30,14 @@
* *
* See BasicSparseLLT and SparseProduct for usage examples. * See BasicSparseLLT and SparseProduct for usage examples.
*/ */
template<typename _Scalar> class AmbiVector template<typename _Scalar, typename _Index>
class AmbiVector
{ {
public: public:
typedef _Scalar Scalar; typedef _Scalar Scalar;
typedef _Index Index;
typedef typename NumTraits<Scalar>::Real RealScalar; typedef typename NumTraits<Scalar>::Real RealScalar;
typedef SparseIndex Index;
AmbiVector(Index size) AmbiVector(Index size)
: m_buffer(0), m_zero(0), m_size(0), m_allocatedSize(0), m_allocatedElements(0), m_mode(-1) : m_buffer(0), m_zero(0), m_size(0), m_allocatedSize(0), m_allocatedElements(0), m_mode(-1)
{ {
@ -130,8 +132,8 @@ template<typename _Scalar> class AmbiVector
}; };
/** \returns the number of non zeros in the current sub vector */ /** \returns the number of non zeros in the current sub vector */
template<typename Scalar> template<typename _Scalar,typename _Index>
SparseIndex AmbiVector<Scalar>::nonZeros() const _Index AmbiVector<_Scalar,_Index>::nonZeros() const
{ {
if (m_mode==IsSparse) if (m_mode==IsSparse)
return m_llSize; return m_llSize;
@ -139,8 +141,8 @@ SparseIndex AmbiVector<Scalar>::nonZeros() const
return m_end - m_start; return m_end - m_start;
} }
template<typename Scalar> template<typename _Scalar,typename _Index>
void AmbiVector<Scalar>::init(double estimatedDensity) void AmbiVector<_Scalar,_Index>::init(double estimatedDensity)
{ {
if (estimatedDensity>0.1) if (estimatedDensity>0.1)
init(IsDense); init(IsDense);
@ -148,8 +150,8 @@ void AmbiVector<Scalar>::init(double estimatedDensity)
init(IsSparse); init(IsSparse);
} }
template<typename Scalar> template<typename _Scalar,typename _Index>
void AmbiVector<Scalar>::init(int mode) void AmbiVector<_Scalar,_Index>::init(int mode)
{ {
m_mode = mode; m_mode = mode;
if (m_mode==IsSparse) if (m_mode==IsSparse)
@ -164,15 +166,15 @@ void AmbiVector<Scalar>::init(int mode)
* *
* Don't worry, this function is extremely cheap. * Don't worry, this function is extremely cheap.
*/ */
template<typename Scalar> template<typename _Scalar,typename _Index>
void AmbiVector<Scalar>::restart() void AmbiVector<_Scalar,_Index>::restart()
{ {
m_llCurrent = m_llStart; m_llCurrent = m_llStart;
} }
/** Set all coefficients of current subvector to zero */ /** Set all coefficients of current subvector to zero */
template<typename Scalar> template<typename _Scalar,typename _Index>
void AmbiVector<Scalar>::setZero() void AmbiVector<_Scalar,_Index>::setZero()
{ {
if (m_mode==IsDense) if (m_mode==IsDense)
{ {
@ -187,8 +189,8 @@ void AmbiVector<Scalar>::setZero()
} }
} }
template<typename Scalar> template<typename _Scalar,typename _Index>
Scalar& AmbiVector<Scalar>::coeffRef(Index i) _Scalar& AmbiVector<_Scalar,_Index>::coeffRef(_Index i)
{ {
if (m_mode==IsDense) if (m_mode==IsDense)
return m_buffer[i]; return m_buffer[i];
@ -256,8 +258,8 @@ Scalar& AmbiVector<Scalar>::coeffRef(Index i)
} }
} }
template<typename Scalar> template<typename _Scalar,typename _Index>
Scalar& AmbiVector<Scalar>::coeff(Index i) _Scalar& AmbiVector<_Scalar,_Index>::coeff(_Index i)
{ {
if (m_mode==IsDense) if (m_mode==IsDense)
return m_buffer[i]; return m_buffer[i];
@ -284,8 +286,8 @@ Scalar& AmbiVector<Scalar>::coeff(Index i)
} }
/** Iterator over the nonzero coefficients */ /** Iterator over the nonzero coefficients */
template<typename _Scalar> template<typename _Scalar,typename _Index>
class AmbiVector<_Scalar>::Iterator class AmbiVector<_Scalar,_Index>::Iterator
{ {
public: public:
typedef _Scalar Scalar; typedef _Scalar Scalar;

View File

@ -109,8 +109,8 @@ cholmod_dense ei_cholmod_map_eigen_to_dense(MatrixBase<Derived>& mat)
return res; return res;
} }
template<typename Scalar, int Flags> template<typename Scalar, int Flags, typename _Index>
MappedSparseMatrix<Scalar,Flags>::MappedSparseMatrix(cholmod_sparse& cm) MappedSparseMatrix<Scalar,Flags,_Index>::MappedSparseMatrix(cholmod_sparse& cm)
{ {
m_innerSize = cm.nrow; m_innerSize = cm.nrow;
m_outerSize = cm.ncol; m_outerSize = cm.ncol;

View File

@ -28,12 +28,20 @@
/** Stores a sparse set of values as a list of values and a list of indices. /** Stores a sparse set of values as a list of values and a list of indices.
* *
*/ */
template<typename Scalar> template<typename _Scalar,typename _Index>
class CompressedStorage class CompressedStorage
{ {
typedef typename NumTraits<Scalar>::Real RealScalar;
typedef SparseIndex Index;
public: public:
typedef _Scalar Scalar;
typedef _Index Index;
protected:
typedef typename NumTraits<Scalar>::Real RealScalar;
public:
CompressedStorage() CompressedStorage()
: m_values(0), m_indices(0), m_size(0), m_allocatedSize(0) : m_values(0), m_indices(0), m_size(0), m_allocatedSize(0)
{} {}
@ -118,13 +126,13 @@ class CompressedStorage
res.m_allocatedSize = res.m_size = size; res.m_allocatedSize = res.m_size = size;
return res; return res;
} }
/** \returns the largest \c k such that for all \c j in [0,k) index[\c j]\<\a key */ /** \returns the largest \c k such that for all \c j in [0,k) index[\c j]\<\a key */
inline Index searchLowerIndex(Index key) const inline Index searchLowerIndex(Index key) const
{ {
return searchLowerIndex(0, m_size, key); return searchLowerIndex(0, m_size, key);
} }
/** \returns the largest \c k in [start,end) such that for all \c j in [start,k) index[\c j]\<\a key */ /** \returns the largest \c k in [start,end) such that for all \c j in [start,k) index[\c j]\<\a key */
inline Index searchLowerIndex(size_t start, size_t end, Index key) const inline Index searchLowerIndex(size_t start, size_t end, Index key) const
{ {
@ -138,7 +146,7 @@ class CompressedStorage
} }
return static_cast<Index>(start); return static_cast<Index>(start);
} }
/** \returns the stored value at index \a key /** \returns the stored value at index \a key
* If the value does not exist, then the value \a defaultValue is returned without any insertion. */ * If the value does not exist, then the value \a defaultValue is returned without any insertion. */
inline Scalar at(Index key, Scalar defaultValue = Scalar(0)) const inline Scalar at(Index key, Scalar defaultValue = Scalar(0)) const
@ -152,7 +160,7 @@ class CompressedStorage
const size_t id = searchLowerIndex(0,m_size-1,key); const size_t id = searchLowerIndex(0,m_size-1,key);
return ((id<m_size) && (m_indices[id]==key)) ? m_values[id] : defaultValue; return ((id<m_size) && (m_indices[id]==key)) ? m_values[id] : defaultValue;
} }
/** Like at(), but the search is performed in the range [start,end) */ /** Like at(), but the search is performed in the range [start,end) */
inline Scalar atInRange(size_t start, size_t end, Index key, Scalar defaultValue = Scalar(0)) const inline Scalar atInRange(size_t start, size_t end, Index key, Scalar defaultValue = Scalar(0)) const
{ {
@ -165,7 +173,7 @@ class CompressedStorage
const size_t id = searchLowerIndex(start,end-1,key); const size_t id = searchLowerIndex(start,end-1,key);
return ((id<end) && (m_indices[id]==key)) ? m_values[id] : defaultValue; return ((id<end) && (m_indices[id]==key)) ? m_values[id] : defaultValue;
} }
/** \returns a reference to the value at index \a key /** \returns a reference to the value at index \a key
* If the value does not exist, then the value \a defaultValue is inserted * If the value does not exist, then the value \a defaultValue is inserted
* such that the keys are sorted. */ * such that the keys are sorted. */
@ -185,7 +193,7 @@ class CompressedStorage
} }
return m_values[id]; return m_values[id];
} }
void prune(Scalar reference, RealScalar epsilon = NumTraits<RealScalar>::dummy_precision()) void prune(Scalar reference, RealScalar epsilon = NumTraits<RealScalar>::dummy_precision())
{ {
size_t k = 0; size_t k = 0;

View File

@ -42,10 +42,11 @@
* *
* \see SparseMatrix * \see SparseMatrix
*/ */
template<typename _Scalar, int _Flags> template<typename _Scalar, int _Flags, typename _Index>
struct ei_traits<DynamicSparseMatrix<_Scalar, _Flags> > struct ei_traits<DynamicSparseMatrix<_Scalar, _Flags, _Index> >
{ {
typedef _Scalar Scalar; typedef _Scalar Scalar;
typedef _Index Index;
typedef Sparse StorageKind; typedef Sparse StorageKind;
typedef MatrixXpr XprKind; typedef MatrixXpr XprKind;
enum { enum {
@ -59,12 +60,12 @@ struct ei_traits<DynamicSparseMatrix<_Scalar, _Flags> >
}; };
}; };
template<typename _Scalar, int _Flags> template<typename _Scalar, int _Flags, typename _Index>
class DynamicSparseMatrix class DynamicSparseMatrix
: public SparseMatrixBase<DynamicSparseMatrix<_Scalar, _Flags> > : public SparseMatrixBase<DynamicSparseMatrix<_Scalar, _Flags, _Index> >
{ {
public: public:
EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(DynamicSparseMatrix) EIGEN_SPARSE_PUBLIC_INTERFACE(DynamicSparseMatrix)
// FIXME: why are these operator already alvailable ??? // FIXME: why are these operator already alvailable ???
// EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(DynamicSparseMatrix, +=) // EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(DynamicSparseMatrix, +=)
// EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(DynamicSparseMatrix, -=) // EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(DynamicSparseMatrix, -=)
@ -76,7 +77,7 @@ class DynamicSparseMatrix
typedef DynamicSparseMatrix<Scalar,(Flags&~RowMajorBit)|(IsRowMajor?RowMajorBit:0)> TransposedSparseMatrix; typedef DynamicSparseMatrix<Scalar,(Flags&~RowMajorBit)|(IsRowMajor?RowMajorBit:0)> TransposedSparseMatrix;
Index m_innerSize; Index m_innerSize;
std::vector<CompressedStorage<Scalar> > m_data; std::vector<CompressedStorage<Scalar,Index> > m_data;
public: public:
@ -86,8 +87,8 @@ class DynamicSparseMatrix
inline Index outerSize() const { return static_cast<Index>(m_data.size()); } inline Index outerSize() const { return static_cast<Index>(m_data.size()); }
inline Index innerNonZeros(Index j) const { return m_data[j].size(); } inline Index innerNonZeros(Index j) const { return m_data[j].size(); }
std::vector<CompressedStorage<Scalar> >& _data() { return m_data; } std::vector<CompressedStorage<Scalar,Index> >& _data() { return m_data; }
const std::vector<CompressedStorage<Scalar> >& _data() const { return m_data; } const std::vector<CompressedStorage<Scalar,Index> >& _data() const { return m_data; }
/** \returns the coefficient value at given position \a row, \a col /** \returns the coefficient value at given position \a row, \a col
* This operation involes a log(rho*outer_size) binary search. * This operation involes a log(rho*outer_size) binary search.
@ -321,8 +322,8 @@ class DynamicSparseMatrix
EIGEN_DEPRECATED void endFill() {} EIGEN_DEPRECATED void endFill() {}
}; };
template<typename Scalar, int _Flags> template<typename Scalar, int _Flags, typename _Index>
class DynamicSparseMatrix<Scalar,_Flags>::InnerIterator : public SparseVector<Scalar,_Flags>::InnerIterator class DynamicSparseMatrix<Scalar,_Flags,_Index>::InnerIterator : public SparseVector<Scalar,_Flags>::InnerIterator
{ {
typedef typename SparseVector<Scalar,_Flags>::InnerIterator Base; typedef typename SparseVector<Scalar,_Flags>::InnerIterator Base;
public: public:

View File

@ -34,25 +34,25 @@
* See http://www.netlib.org/linalg/html_templates/node91.html for details on the storage scheme. * See http://www.netlib.org/linalg/html_templates/node91.html for details on the storage scheme.
* *
*/ */
template<typename _Scalar, int _Flags> template<typename _Scalar, int _Flags, typename _Index>
struct ei_traits<MappedSparseMatrix<_Scalar, _Flags> > : ei_traits<SparseMatrix<_Scalar, _Flags> > struct ei_traits<MappedSparseMatrix<_Scalar, _Flags, _Index> > : ei_traits<SparseMatrix<_Scalar, _Flags, _Index> >
{}; {};
template<typename _Scalar, int _Flags> template<typename _Scalar, int _Flags, typename _Index>
class MappedSparseMatrix class MappedSparseMatrix
: public SparseMatrixBase<MappedSparseMatrix<_Scalar, _Flags> > : public SparseMatrixBase<MappedSparseMatrix<_Scalar, _Flags, _Index> >
{ {
public: public:
EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(MappedSparseMatrix) EIGEN_SPARSE_PUBLIC_INTERFACE(MappedSparseMatrix)
protected: protected:
enum { IsRowMajor = Base::IsRowMajor }; enum { IsRowMajor = Base::IsRowMajor };
Index m_outerSize; Index m_outerSize;
Index m_innerSize; Index m_innerSize;
Index m_nnz; Index m_nnz;
Index* m_outerIndex; Index* m_outerIndex;
Index* m_innerIndices; Index* m_innerIndices;
Scalar* m_values; Scalar* m_values;
public: public:
@ -135,8 +135,8 @@ class MappedSparseMatrix
inline ~MappedSparseMatrix() {} inline ~MappedSparseMatrix() {}
}; };
template<typename Scalar, int _Flags> template<typename Scalar, int _Flags, typename _Index>
class MappedSparseMatrix<Scalar,_Flags>::InnerIterator class MappedSparseMatrix<Scalar,_Flags,_Index>::InnerIterator
{ {
public: public:
InnerIterator(const MappedSparseMatrix& mat, Index outer) InnerIterator(const MappedSparseMatrix& mat, Index outer)

View File

@ -29,6 +29,7 @@ template<typename MatrixType, int Size>
struct ei_traits<SparseInnerVectorSet<MatrixType, Size> > struct ei_traits<SparseInnerVectorSet<MatrixType, Size> >
{ {
typedef typename ei_traits<MatrixType>::Scalar Scalar; typedef typename ei_traits<MatrixType>::Scalar Scalar;
typedef typename ei_traits<MatrixType>::Index Index;
typedef typename ei_traits<MatrixType>::StorageKind StorageKind; typedef typename ei_traits<MatrixType>::StorageKind StorageKind;
typedef MatrixXpr XprKind; typedef MatrixXpr XprKind;
enum { enum {
@ -50,7 +51,7 @@ class SparseInnerVectorSet : ei_no_assignment_operator,
enum { IsRowMajor = ei_traits<SparseInnerVectorSet>::IsRowMajor }; enum { IsRowMajor = ei_traits<SparseInnerVectorSet>::IsRowMajor };
EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(SparseInnerVectorSet) EIGEN_SPARSE_PUBLIC_INTERFACE(SparseInnerVectorSet)
class InnerIterator: public MatrixType::InnerIterator class InnerIterator: public MatrixType::InnerIterator
{ {
public: public:
@ -111,7 +112,7 @@ class SparseInnerVectorSet<DynamicSparseMatrix<_Scalar, _Options>, Size>
enum { IsRowMajor = ei_traits<SparseInnerVectorSet>::IsRowMajor }; enum { IsRowMajor = ei_traits<SparseInnerVectorSet>::IsRowMajor };
EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(SparseInnerVectorSet) EIGEN_SPARSE_PUBLIC_INTERFACE(SparseInnerVectorSet)
class InnerIterator: public MatrixType::InnerIterator class InnerIterator: public MatrixType::InnerIterator
{ {
public: public:
@ -209,7 +210,7 @@ class SparseInnerVectorSet<SparseMatrix<_Scalar, _Options>, Size>
enum { IsRowMajor = ei_traits<SparseInnerVectorSet>::IsRowMajor }; enum { IsRowMajor = ei_traits<SparseInnerVectorSet>::IsRowMajor };
EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(SparseInnerVectorSet) EIGEN_SPARSE_PUBLIC_INTERFACE(SparseInnerVectorSet)
class InnerIterator: public MatrixType::InnerIterator class InnerIterator: public MatrixType::InnerIterator
{ {
public: public:

View File

@ -43,6 +43,8 @@ struct ei_traits<SparseDiagonalProduct<Lhs, Rhs> >
typedef typename ei_cleantype<Lhs>::type _Lhs; typedef typename ei_cleantype<Lhs>::type _Lhs;
typedef typename ei_cleantype<Rhs>::type _Rhs; typedef typename ei_cleantype<Rhs>::type _Rhs;
typedef typename _Lhs::Scalar Scalar; typedef typename _Lhs::Scalar Scalar;
typedef typename ei_promote_index_type<typename ei_traits<Lhs>::Index,
typename ei_traits<Rhs>::Index>::type Index;
typedef Sparse StorageKind; typedef Sparse StorageKind;
typedef MatrixXpr XprKind; typedef MatrixXpr XprKind;
enum { enum {
@ -82,7 +84,7 @@ class SparseDiagonalProduct
public: public:
EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(SparseDiagonalProduct) EIGEN_SPARSE_PUBLIC_INTERFACE(SparseDiagonalProduct)
typedef ei_sparse_diagonal_product_inner_iterator_selector typedef ei_sparse_diagonal_product_inner_iterator_selector
<_LhsNested,_RhsNested,SparseDiagonalProduct,LhsMode,RhsMode> InnerIterator; <_LhsNested,_RhsNested,SparseDiagonalProduct,LhsMode,RhsMode> InnerIterator;

View File

@ -339,7 +339,7 @@ bool SparseLDLT<MatrixType, Backend>::solveInPlace(MatrixBase<Derived> &b) const
// FIXME should be .adjoint() but it fails to compile... // FIXME should be .adjoint() but it fails to compile...
if (m_matrix.nonZeros()>0) // otherwise L==I if (m_matrix.nonZeros()>0) // otherwise L==I
m_matrix.transpose().template triangularView<UnitUpper>().solveInPlace(b); m_matrix.adjoint().template triangularView<UnitUpper>().solveInPlace(b);
return true; return true;
} }

View File

@ -132,7 +132,7 @@ void SparseLLT<MatrixType,Backend>::compute(const MatrixType& a)
m_matrix.resize(size, size); m_matrix.resize(size, size);
// allocate a temporary vector for accumulations // allocate a temporary vector for accumulations
AmbiVector<Scalar> tempVector(size); AmbiVector<Scalar,Index> tempVector(size);
RealScalar density = a.nonZeros()/RealScalar(size*size); RealScalar density = a.nonZeros()/RealScalar(size*size);
// TODO estimate the number of non zeros // TODO estimate the number of non zeros
@ -177,7 +177,7 @@ void SparseLLT<MatrixType,Backend>::compute(const MatrixType& a)
RealScalar rx = ei_sqrt(ei_real(x)); RealScalar rx = ei_sqrt(ei_real(x));
m_matrix.insert(j,j) = rx; // FIXME use insertBack m_matrix.insert(j,j) = rx; // FIXME use insertBack
Scalar y = Scalar(1)/rx; Scalar y = Scalar(1)/rx;
for (typename AmbiVector<Scalar>::Iterator it(tempVector, m_precision*rx); it; ++it) for (typename AmbiVector<Scalar,Index>::Iterator it(tempVector, m_precision*rx); it; ++it)
{ {
// FIXME use insertBack // FIXME use insertBack
m_matrix.insert(it.index(), j) = it.value() * y; m_matrix.insert(it.index(), j) = it.value() * y;

View File

@ -37,14 +37,16 @@
* \param _Scalar the scalar type, i.e. the type of the coefficients * \param _Scalar the scalar type, i.e. the type of the coefficients
* \param _Options Union of bit flags controlling the storage scheme. Currently the only possibility * \param _Options Union of bit flags controlling the storage scheme. Currently the only possibility
* is RowMajor. The default is 0 which means column-major. * is RowMajor. The default is 0 which means column-major.
* \param _Index the type of the indices. Default is \c int.
* *
* See http://www.netlib.org/linalg/html_templates/node91.html for details on the storage scheme. * See http://www.netlib.org/linalg/html_templates/node91.html for details on the storage scheme.
* *
*/ */
template<typename _Scalar, int _Options> template<typename _Scalar, int _Options, typename _Index>
struct ei_traits<SparseMatrix<_Scalar, _Options> > struct ei_traits<SparseMatrix<_Scalar, _Options, _Index> >
{ {
typedef _Scalar Scalar; typedef _Scalar Scalar;
typedef _Index Index;
typedef Sparse StorageKind; typedef Sparse StorageKind;
typedef MatrixXpr XprKind; typedef MatrixXpr XprKind;
enum { enum {
@ -58,12 +60,12 @@ struct ei_traits<SparseMatrix<_Scalar, _Options> >
}; };
}; };
template<typename _Scalar, int _Options> template<typename _Scalar, int _Options, typename _Index>
class SparseMatrix class SparseMatrix
: public SparseMatrixBase<SparseMatrix<_Scalar, _Options> > : public SparseMatrixBase<SparseMatrix<_Scalar, _Options, _Index> >
{ {
public: public:
EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(SparseMatrix) EIGEN_SPARSE_PUBLIC_INTERFACE(SparseMatrix)
EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(SparseMatrix, +=) EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(SparseMatrix, +=)
EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(SparseMatrix, -=) EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(SparseMatrix, -=)
// FIXME: why are these operator already alvailable ??? // FIXME: why are these operator already alvailable ???
@ -80,7 +82,7 @@ class SparseMatrix
Index m_outerSize; Index m_outerSize;
Index m_innerSize; Index m_innerSize;
Index* m_outerIndex; Index* m_outerIndex;
CompressedStorage<Scalar> m_data; CompressedStorage<Scalar,Index> m_data;
public: public:
@ -570,8 +572,8 @@ class SparseMatrix
EIGEN_DEPRECATED void endFill() { finalize(); } EIGEN_DEPRECATED void endFill() { finalize(); }
}; };
template<typename Scalar, int _Options> template<typename Scalar, int _Options, typename _Index>
class SparseMatrix<Scalar,_Options>::InnerIterator class SparseMatrix<Scalar,_Options,_Index>::InnerIterator
{ {
public: public:
InnerIterator(const SparseMatrix& mat, Index outer) InnerIterator(const SparseMatrix& mat, Index outer)

View File

@ -43,7 +43,7 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived>
typedef typename ei_traits<Derived>::Scalar Scalar; typedef typename ei_traits<Derived>::Scalar Scalar;
typedef typename ei_packet_traits<Scalar>::type PacketScalar; typedef typename ei_packet_traits<Scalar>::type PacketScalar;
typedef typename ei_traits<Derived>::StorageKind StorageKind; typedef typename ei_traits<Derived>::StorageKind StorageKind;
typedef typename ei_index<StorageKind>::type Index; typedef typename ei_traits<Derived>::Index Index;
typedef SparseMatrixBase StorageBaseType; typedef SparseMatrixBase StorageBaseType;

View File

@ -57,6 +57,8 @@ struct ei_traits<SparseProduct<LhsNested, RhsNested> >
typedef typename ei_cleantype<LhsNested>::type _LhsNested; typedef typename ei_cleantype<LhsNested>::type _LhsNested;
typedef typename ei_cleantype<RhsNested>::type _RhsNested; typedef typename ei_cleantype<RhsNested>::type _RhsNested;
typedef typename _LhsNested::Scalar Scalar; typedef typename _LhsNested::Scalar Scalar;
typedef typename ei_promote_index_type<typename ei_traits<_LhsNested>::Index,
typename ei_traits<_RhsNested>::Index>::type Index;
enum { enum {
LhsCoeffReadCost = _LhsNested::CoeffReadCost, LhsCoeffReadCost = _LhsNested::CoeffReadCost,
@ -236,7 +238,7 @@ static void ei_sparse_product_impl(const Lhs& lhs, const Rhs& rhs, ResultType& r
ei_assert(lhs.outerSize() == rhs.innerSize()); ei_assert(lhs.outerSize() == rhs.innerSize());
// allocate a temporary buffer // allocate a temporary buffer
AmbiVector<Scalar> tempVector(rows); AmbiVector<Scalar,Index> tempVector(rows);
// estimate the number of non zero entries // estimate the number of non zero entries
float ratioLhs = float(lhs.nonZeros())/(float(lhs.rows())*float(lhs.cols())); float ratioLhs = float(lhs.nonZeros())/(float(lhs.rows())*float(lhs.cols()));
@ -264,7 +266,7 @@ static void ei_sparse_product_impl(const Lhs& lhs, const Rhs& rhs, ResultType& r
} }
} }
res.startVec(j); res.startVec(j);
for (typename AmbiVector<Scalar>::Iterator it(tempVector); it; ++it) for (typename AmbiVector<Scalar,Index>::Iterator it(tempVector); it; ++it)
res.insertBackByOuterInner(j,it.index()) = it.value(); res.insertBackByOuterInner(j,it.index()) = it.value();
} }
res.finalize(); res.finalize();

View File

@ -37,17 +37,17 @@ SparseMatrixBase<Derived>::sum() const
return res; return res;
} }
template<typename _Scalar, int _Options> template<typename _Scalar, int _Options, typename _Index>
typename ei_traits<SparseMatrix<_Scalar,_Options> >::Scalar typename ei_traits<SparseMatrix<_Scalar,_Options,_Index> >::Scalar
SparseMatrix<_Scalar,_Options>::sum() const SparseMatrix<_Scalar,_Options,_Index>::sum() const
{ {
ei_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix"); ei_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
return Matrix<Scalar,1,Dynamic>::Map(&m_data.value(0), m_data.size()).sum(); return Matrix<Scalar,1,Dynamic>::Map(&m_data.value(0), m_data.size()).sum();
} }
template<typename _Scalar, int _Options> template<typename _Scalar, int _Options, typename _Index>
typename ei_traits<SparseVector<_Scalar,_Options> >::Scalar typename ei_traits<SparseVector<_Scalar,_Options, _Index> >::Scalar
SparseVector<_Scalar,_Options>::sum() const SparseVector<_Scalar,_Options,_Index>::sum() const
{ {
ei_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix"); ei_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
return Matrix<Scalar,1,Dynamic>::Map(&m_data.value(0), m_data.size()).sum(); return Matrix<Scalar,1,Dynamic>::Map(&m_data.value(0), m_data.size()).sum();

View File

@ -56,30 +56,13 @@ EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, -=) \
EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, *=) \ EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, *=) \
EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, /=) EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, /=)
#define _EIGEN_SPARSE_GENERIC_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; \
typedef typename Eigen::ei_traits<Derived>::StorageKind StorageKind; \
typedef typename Eigen::ei_index<StorageKind>::type Index; \
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 };
#define EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(Derived) \
_EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::SparseMatrixBase<Derived>)
#define _EIGEN_SPARSE_PUBLIC_INTERFACE(Derived, BaseClass) \ #define _EIGEN_SPARSE_PUBLIC_INTERFACE(Derived, BaseClass) \
typedef BaseClass Base; \ typedef BaseClass Base; \
typedef typename Eigen::ei_traits<Derived>::Scalar Scalar; \ typedef typename Eigen::ei_traits<Derived>::Scalar Scalar; \
typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \ typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \
typedef typename Eigen::ei_nested<Derived>::type Nested; \ typedef typename Eigen::ei_nested<Derived>::type Nested; \
typedef typename Eigen::ei_traits<Derived>::StorageKind StorageKind; \ typedef typename Eigen::ei_traits<Derived>::StorageKind StorageKind; \
typedef typename Eigen::ei_index<StorageKind>::type Index; \ typedef typename Eigen::ei_traits<Derived>::Index Index; \
enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \ enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \
ColsAtCompileTime = Eigen::ei_traits<Derived>::ColsAtCompileTime, \ ColsAtCompileTime = Eigen::ei_traits<Derived>::ColsAtCompileTime, \
Flags = Eigen::ei_traits<Derived>::Flags, \ Flags = Eigen::ei_traits<Derived>::Flags, \
@ -92,12 +75,6 @@ EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, /=)
#define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived) \ #define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived) \
_EIGEN_SPARSE_PUBLIC_INTERFACE(Derived, Eigen::SparseMatrixBase<Derived>) _EIGEN_SPARSE_PUBLIC_INTERFACE(Derived, Eigen::SparseMatrixBase<Derived>)
template<>
struct ei_index<Sparse>
{ typedef EIGEN_DEFAULT_SPARSE_INDEX_TYPE type; };
typedef ei_index<Sparse>::type SparseIndex;
enum SparseBackend { enum SparseBackend {
DefaultBackend, DefaultBackend,
Taucs, Taucs,
@ -128,10 +105,10 @@ enum {
}; };
template<typename Derived> class SparseMatrixBase; template<typename Derived> class SparseMatrixBase;
template<typename _Scalar, int _Flags = 0> class SparseMatrix; template<typename _Scalar, int _Flags = 0, typename _Index = int> class SparseMatrix;
template<typename _Scalar, int _Flags = 0> class DynamicSparseMatrix; template<typename _Scalar, int _Flags = 0, typename _Index = int> class DynamicSparseMatrix;
template<typename _Scalar, int _Flags = 0> class SparseVector; template<typename _Scalar, int _Flags = 0, typename _Index = int> class SparseVector;
template<typename _Scalar, int _Flags = 0> class MappedSparseMatrix; template<typename _Scalar, int _Flags = 0, typename _Index = int> class MappedSparseMatrix;
template<typename MatrixType, int Size> class SparseInnerVectorSet; template<typename MatrixType, int Size> class SparseInnerVectorSet;
template<typename MatrixType, int Mode> class SparseTriangularView; template<typename MatrixType, int Mode> class SparseTriangularView;

View File

@ -34,10 +34,11 @@
* See http://www.netlib.org/linalg/html_templates/node91.html for details on the storage scheme. * See http://www.netlib.org/linalg/html_templates/node91.html for details on the storage scheme.
* *
*/ */
template<typename _Scalar, int _Options> template<typename _Scalar, int _Options, typename _Index>
struct ei_traits<SparseVector<_Scalar, _Options> > struct ei_traits<SparseVector<_Scalar, _Options, _Index> >
{ {
typedef _Scalar Scalar; typedef _Scalar Scalar;
typedef _Index Index;
typedef Sparse StorageKind; typedef Sparse StorageKind;
typedef MatrixXpr XprKind; typedef MatrixXpr XprKind;
enum { enum {
@ -53,12 +54,12 @@ struct ei_traits<SparseVector<_Scalar, _Options> >
}; };
}; };
template<typename _Scalar, int _Options> template<typename _Scalar, int _Options, typename _Index>
class SparseVector class SparseVector
: public SparseMatrixBase<SparseVector<_Scalar, _Options> > : public SparseMatrixBase<SparseVector<_Scalar, _Options, _Index> >
{ {
public: public:
EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(SparseVector) EIGEN_SPARSE_PUBLIC_INTERFACE(SparseVector)
EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(SparseVector, +=) EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(SparseVector, +=)
EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(SparseVector, -=) EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(SparseVector, -=)
// EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(SparseVector, =) // EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(SparseVector, =)
@ -69,11 +70,11 @@ class SparseVector
typedef SparseMatrixBase<SparseVector> SparseBase; typedef SparseMatrixBase<SparseVector> SparseBase;
enum { IsColVector = ei_traits<SparseVector>::IsColVector }; enum { IsColVector = ei_traits<SparseVector>::IsColVector };
CompressedStorage<Scalar> m_data; CompressedStorage<Scalar,Index> m_data;
Index m_size; Index m_size;
CompressedStorage<Scalar>& _data() { return m_data; } CompressedStorage<Scalar,Index>& _data() { return m_data; }
CompressedStorage<Scalar>& _data() const { return m_data; } CompressedStorage<Scalar,Index>& _data() const { return m_data; }
public: public:
@ -370,8 +371,8 @@ class SparseVector
EIGEN_DEPRECATED void endFill() {} EIGEN_DEPRECATED void endFill() {}
}; };
template<typename Scalar, int _Options> template<typename Scalar, int _Options, typename _Index>
class SparseVector<Scalar,_Options>::InnerIterator class SparseVector<Scalar,_Options,_Index>::InnerIterator
{ {
public: public:
InnerIterator(const SparseVector& vec, Index outer=0) InnerIterator(const SparseVector& vec, Index outer=0)
@ -380,7 +381,7 @@ class SparseVector<Scalar,_Options>::InnerIterator
ei_assert(outer==0); ei_assert(outer==0);
} }
InnerIterator(const CompressedStorage<Scalar>& data) InnerIterator(const CompressedStorage<Scalar,Index>& data)
: m_data(data), m_id(0), m_end(static_cast<Index>(m_data.size())) : m_data(data), m_id(0), m_end(static_cast<Index>(m_data.size()))
{} {}
@ -401,7 +402,7 @@ class SparseVector<Scalar,_Options>::InnerIterator
inline operator bool() const { return (m_id < m_end); } inline operator bool() const { return (m_id < m_end); }
protected: protected:
const CompressedStorage<Scalar>& m_data; const CompressedStorage<Scalar,Index>& m_data;
Index m_id; Index m_id;
const Index m_end; const Index m_end;
}; };

View File

@ -267,8 +267,8 @@ SluMatrix SparseMatrixBase<Derived>::asSluMatrix()
} }
/** View a Super LU matrix as an Eigen expression */ /** View a Super LU matrix as an Eigen expression */
template<typename Scalar, int Flags> template<typename Scalar, int Flags, typename _Index>
MappedSparseMatrix<Scalar,Flags>::MappedSparseMatrix(SluMatrix& sluMat) MappedSparseMatrix<Scalar,Flags,_Index>::MappedSparseMatrix(SluMatrix& sluMat)
{ {
if ((Flags&RowMajorBit)==RowMajorBit) if ((Flags&RowMajorBit)==RowMajorBit)
{ {

View File

@ -63,8 +63,8 @@ taucs_ccs_matrix SparseMatrixBase<Derived>::asTaucsMatrix()
return res; return res;
} }
template<typename Scalar, int Flags> template<typename Scalar, int Flags, typename _Index>
MappedSparseMatrix<Scalar,Flags>::MappedSparseMatrix(taucs_ccs_matrix& taucsMat) MappedSparseMatrix<Scalar,Flags,_Index>::MappedSparseMatrix(taucs_ccs_matrix& taucsMat)
{ {
m_innerSize = taucsMat.m; m_innerSize = taucsMat.m;
m_outerSize = taucsMat.n; m_outerSize = taucsMat.n;

View File

@ -207,10 +207,12 @@ template<typename Lhs, typename Rhs, int Mode, int UpLo>
struct ei_sparse_solve_triangular_sparse_selector<Lhs,Rhs,Mode,UpLo,ColMajor> struct ei_sparse_solve_triangular_sparse_selector<Lhs,Rhs,Mode,UpLo,ColMajor>
{ {
typedef typename Rhs::Scalar Scalar; typedef typename Rhs::Scalar Scalar;
typedef typename ei_promote_index_type<typename ei_traits<Lhs>::Index,
typename ei_traits<Rhs>::Index>::type Index;
static void run(const Lhs& lhs, Rhs& other) static void run(const Lhs& lhs, Rhs& other)
{ {
const bool IsLower = (UpLo==Lower); const bool IsLower = (UpLo==Lower);
AmbiVector<Scalar> tempVector(other.rows()*2); AmbiVector<Scalar,Index> tempVector(other.rows()*2);
tempVector.setBounds(0,other.rows()); tempVector.setBounds(0,other.rows());
Rhs res(other.rows(), other.cols()); Rhs res(other.rows(), other.cols());
@ -266,7 +268,7 @@ struct ei_sparse_solve_triangular_sparse_selector<Lhs,Rhs,Mode,UpLo,ColMajor>
int count = 0; int count = 0;
// FIXME compute a reference value to filter zeros // FIXME compute a reference value to filter zeros
for (typename AmbiVector<Scalar>::Iterator it(tempVector/*,1e-12*/); it; ++it) for (typename AmbiVector<Scalar,Index>::Iterator it(tempVector/*,1e-12*/); it; ++it)
{ {
++ count; ++ count;
// std::cerr << "fill " << it.index() << ", " << col << "\n"; // std::cerr << "fill " << it.index() << ", " << col << "\n";