aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/sparse.h
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2009-01-07 17:01:57 +0000
committerGravatar Gael Guennebaud <g.gael@free.fr>2009-01-07 17:01:57 +0000
commit709e9033355834e6d9166dd9eac975a383e55ece (patch)
tree2bc70cec7128d1eb15afd49ab6199ea67036a525 /test/sparse.h
parent7078cfaeaa52db71229cb81c5da07d593b2e5174 (diff)
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 ?
Diffstat (limited to 'test/sparse.h')
-rw-r--r--test/sparse.h24
1 files changed, 24 insertions, 0 deletions
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<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