various work on the Sparse module:

* added some glue to Eigen/Core (SparseBit, ei_eval, Matrix)
* add two new sparse matrix types:
   HashMatrix: based on std::map (for random writes)
   LinkedVectorMatrix: array of linked vectors
   (for outer coherent writes, e.g. to transpose a matrix)
* add a SparseSetter class to easily set/update any kind of matrices, e.g.:
   { SparseSetter<MatrixType,RandomAccessPattern> wrapper(mymatrix);
     for (...) wrapper->coeffRef(rand(),rand()) = rand(); }
* automatic shallow copy for RValue
* and a lot of mess !
plus:
* remove the remaining ArrayBit related stuff
* don't use alloca in product for very large memory allocation
This commit is contained in:
Gael Guennebaud
2008-06-26 23:22:26 +00:00
parent c5bd1703cb
commit e5d301dc96
17 changed files with 1226 additions and 169 deletions

View File

@@ -86,7 +86,12 @@ static void ei_cache_friendly_product(
const int l2BlockRows = MaxL2BlockSize > rows ? rows : MaxL2BlockSize;
const int l2BlockCols = MaxL2BlockSize > cols ? cols : MaxL2BlockSize;
const int l2BlockSize = MaxL2BlockSize > size ? size : MaxL2BlockSize;
Scalar* __restrict__ block = (Scalar*)alloca(sizeof(Scalar)*l2BlockRows*size);
Scalar* __restrict__ block = 0;
const int allocBlockSize = sizeof(Scalar)*l2BlockRows*size;
if (allocBlockSize>16000000)
block = (Scalar*)malloc(allocBlockSize);
else
block = (Scalar*)alloca(allocBlockSize);
Scalar* __restrict__ rhsCopy = (Scalar*)alloca(sizeof(Scalar)*l2BlockSize);
// loops on each L2 cache friendly blocks of the result
@@ -347,6 +352,9 @@ static void ei_cache_friendly_product(
}
}
}
if (allocBlockSize>16000000)
free(block);
}
#endif // EIGEN_CACHE_FRIENDLY_PRODUCT_H

View File

@@ -92,7 +92,8 @@ struct ei_traits<Matrix<_Scalar, _Rows, _Cols, _MaxRows, _MaxCols, _Flags> >
_Rows, _Cols, _MaxRows, _MaxCols,
_Flags
>::ret,
CoeffReadCost = NumTraits<Scalar>::ReadCost
CoeffReadCost = NumTraits<Scalar>::ReadCost,
SupportedAccessPatterns = RandomAccessPattern
};
};

View File

@@ -258,7 +258,6 @@ template<typename OtherDerived>
inline const typename ProductReturnType<Derived,OtherDerived>::Type
MatrixBase<Derived>::operator*(const MatrixBase<OtherDerived> &other) const
{
assert( (Derived::Flags&ArrayBit) == (OtherDerived::Flags&ArrayBit) );
return typename ProductReturnType<Derived,OtherDerived>::Type(derived(), other.derived());
}

View File

@@ -63,6 +63,8 @@ template<typename MatrixType> class Transpose
EIGEN_GENERIC_PUBLIC_INTERFACE(Transpose)
class InnerIterator;
inline Transpose(const MatrixType& matrix) : m_matrix(matrix) {}
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Transpose)

View File

@@ -138,10 +138,8 @@ const unsigned int LowerTriangularBit = 0x400;
/** \ingroup flags
*
* means the object is just an array of scalars, and operations on it are regarded as operations
* on every of these scalars taken separately.
*/
const unsigned int ArrayBit = 0x800;
* means the expression includes sparse matrices and the sparse path has to be taken. */
const unsigned int SparseBit = 0x800;
/** \ingroup flags
*
@@ -155,7 +153,7 @@ const unsigned int HereditaryBits = RowMajorBit
| EvalBeforeNestingBit
| EvalBeforeAssigningBit
| LargeBit
| ArrayBit;
| SparseBit;
// Possible values for the Mode parameter of part() and of extract()
const unsigned int Upper = UpperTriangularBit;
@@ -173,7 +171,7 @@ enum { Aligned=0, UnAligned=1 };
enum { ConditionalJumpCost = 5 };
enum CornerType { TopLeft, TopRight, BottomLeft, BottomRight };
enum DirectionType { Vertical, Horizontal };
enum ProductEvaluationMode { NormalProduct, CacheFriendlyProduct, DiagonalProduct };
enum ProductEvaluationMode { NormalProduct, CacheFriendlyProduct, DiagonalProduct, SparseProduct };
enum {
InnerVectorization,
@@ -188,5 +186,14 @@ enum {
NoUnrolling
};
enum {
Dense = 0,
Sparse = SparseBit
};
const int FullyCoherentAccessPattern = 0x1;
const int InnerCoherentAccessPattern = 0x2 | FullyCoherentAccessPattern;
const int OuterCoherentAccessPattern = 0x4 | InnerCoherentAccessPattern;
const int RandomAccessPattern = 0x8 | OuterCoherentAccessPattern;
#endif // EIGEN_CONSTANTS_H

View File

@@ -175,7 +175,9 @@ template<int _Rows, int _Cols> struct ei_size_at_compile_time
enum { ret = (_Rows==Dynamic || _Cols==Dynamic) ? Dynamic : _Rows * _Cols };
};
template<typename T> class ei_eval
template<typename T, int Sparseness = ei_traits<T>::Flags&SparseBit> class ei_eval;
template<typename T> class ei_eval<T,Dense>
{
typedef typename ei_traits<T>::Scalar _Scalar;
enum {_Rows = ei_traits<T>::RowsAtCompileTime,