aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/sparse.h
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2009-01-19 15:20:45 +0000
committerGravatar Gael Guennebaud <g.gael@free.fr>2009-01-19 15:20:45 +0000
commit178858f1bd4f0661f355d17058d87f8c56a4c0c1 (patch)
tree2889df07300034e8567911e7cf4cad7786e2e762 /test/sparse.h
parent385fd3d918024f0e954b40b1b729887b16f43788 (diff)
add a flexible sparse matrix class designed for fast matrix assembly
Diffstat (limited to 'test/sparse.h')
-rw-r--r--test/sparse.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/sparse.h b/test/sparse.h
index 919afb760..d18217e0a 100644
--- a/test/sparse.h
+++ b/test/sparse.h
@@ -96,6 +96,49 @@ initSparse(double density,
template<typename Scalar> void
initSparse(double density,
+ Matrix<Scalar,Dynamic,Dynamic>& refMat,
+ DynamicSparseMatrix<Scalar>& sparseMat,
+ int flags = 0,
+ std::vector<Vector2i>* zeroCoords = 0,
+ std::vector<Vector2i>* nonzeroCoords = 0)
+{
+ sparseMat.startFill(int(refMat.rows()*refMat.cols()*density));
+ for(int j=0; j<refMat.cols(); j++)
+ {
+ for(int i=0; i<refMat.rows(); i++)
+ {
+ Scalar v = (ei_random<double>(0,1) < density) ? ei_random<Scalar>() : Scalar(0);
+ if ((flags&ForceNonZeroDiag) && (i==j))
+ {
+ v = ei_random<Scalar>()*Scalar(3.);
+ v = v*v + Scalar(5.);
+ }
+ if ((flags & MakeLowerTriangular) && j>i)
+ v = Scalar(0);
+ else if ((flags & MakeUpperTriangular) && j<i)
+ v = Scalar(0);
+
+ if ((flags&ForceRealDiag) && (i==j))
+ v = ei_real(v);
+
+ if (v!=Scalar(0))
+ {
+ sparseMat.fill(i,j) = v;
+ if (nonzeroCoords)
+ nonzeroCoords->push_back(Vector2i(i,j));
+ }
+ else if (zeroCoords)
+ {
+ zeroCoords->push_back(Vector2i(i,j));
+ }
+ refMat(i,j) = v;
+ }
+ }
+ sparseMat.endFill();
+}
+
+template<typename Scalar> void
+initSparse(double density,
Matrix<Scalar,Dynamic,1>& refVec,
SparseVector<Scalar>& sparseVec,
std::vector<int>* zeroCoords = 0,