From 709e9033355834e6d9166dd9eac975a383e55ece Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 7 Jan 2009 17:01:57 +0000 Subject: 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 ? --- test/sparse.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test/sparse.h') diff --git a/test/sparse.h b/test/sparse.h index bf4a2ac04..310e976f2 100644 --- a/test/sparse.h +++ b/test/sparse.h @@ -89,4 +89,28 @@ initSparse(double density, sparseMat.endFill(); } +template void +initSparse(double density, + Matrix& refVec, + SparseVector& sparseVec, + std::vector* zeroCoords = 0, + std::vector* nonzeroCoords = 0) +{ + sparseVec.reserve(refVec.size()*density); + sparseVec.setZero(); + for(int i=0; i(0,1) < density) ? ei_random() : 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 -- cgit v1.2.3