Sparse module:

* extend unit tests
* add support for generic sum reduction and dot product
* optimize the cwise()* : this is a special case of CwiseBinaryOp where
  we only have to process the coeffs which are not null for *both* matrices.
  Perhaps there exist some other binary operations like that ?
This commit is contained in:
Gael Guennebaud
2009-01-07 17:01:57 +00:00
parent 7078cfaeaa
commit 709e903335
9 changed files with 382 additions and 39 deletions

View File

@@ -89,4 +89,28 @@ initSparse(double density,
sparseMat.endFill();
}
template<typename Scalar> void
initSparse(double density,
Matrix<Scalar,Dynamic,1>& refVec,
SparseVector<Scalar>& sparseVec,
std::vector<int>* zeroCoords = 0,
std::vector<int>* nonzeroCoords = 0)
{
sparseVec.reserve(refVec.size()*density);
sparseVec.setZero();
for(int i=0; i<refVec.size(); i++)
{
Scalar v = (ei_random<double>(0,1) < density) ? ei_random<Scalar>() : Scalar(0);
if (v!=Scalar(0))
{
sparseVec.fill(i) = v;
if (nonzeroCoords)
nonzeroCoords->push_back(i);
}
else if (zeroCoords)
zeroCoords->push_back(i);
refVec[i] = v;
}
}
#endif // EIGEN_TESTSPARSE_H