aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/sparse.h
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2009-05-04 14:25:12 +0000
committerGravatar Gael Guennebaud <g.gael@free.fr>2009-05-04 14:25:12 +0000
commit28293142842c525eec1adde377999b065dea8cbf (patch)
tree22a6b32d00f507afaaa6a20c712ecd70c8b6ffb7 /test/sparse.h
parentddb6e96d48e353099911cf4179ea6285dce40d4c (diff)
new simplified API to fill sparse matrices (the old functions are
deprecated). Basically there are now only 2 functions to set a coefficient: 1) mat.coeffRef(row,col) = value; 2) mat.insert(row,col) = value; coeffRef has no limitation, insert assumes the coeff has not already been set, and raises an assert otherwise. In addition I added a much lower level, but more efficient filling mechanism for internal use only.
Diffstat (limited to 'test/sparse.h')
-rw-r--r--test/sparse.h18
1 files changed, 11 insertions, 7 deletions
diff --git a/test/sparse.h b/test/sparse.h
index 80d99dc5b..eb2f98f5f 100644
--- a/test/sparse.h
+++ b/test/sparse.h
@@ -64,9 +64,11 @@ initSparse(double density,
std::vector<Vector2i>* zeroCoords = 0,
std::vector<Vector2i>* nonzeroCoords = 0)
{
- sparseMat.startFill(int(refMat.rows()*refMat.cols()*density));
+ sparseMat.setZero();
+ sparseMat.reserve(int(refMat.rows()*refMat.cols()*density));
for(int j=0; j<refMat.cols(); j++)
{
+ sparseMat.startVec(j);
for(int i=0; i<refMat.rows(); i++)
{
Scalar v = (ei_random<double>(0,1) < density) ? ei_random<Scalar>() : Scalar(0);
@@ -85,7 +87,7 @@ initSparse(double density,
if (v!=Scalar(0))
{
- sparseMat.fill(i,j) = v;
+ sparseMat.insertBack(j,i) = v;
if (nonzeroCoords)
nonzeroCoords->push_back(Vector2i(i,j));
}
@@ -96,7 +98,7 @@ initSparse(double density,
refMat(i,j) = v;
}
}
- sparseMat.endFill();
+ sparseMat.finalize();
}
template<typename Scalar> void
@@ -107,9 +109,11 @@ initSparse(double density,
std::vector<Vector2i>* zeroCoords = 0,
std::vector<Vector2i>* nonzeroCoords = 0)
{
- sparseMat.startFill(int(refMat.rows()*refMat.cols()*density));
+ sparseMat.setZero();
+ sparseMat.reserve(int(refMat.rows()*refMat.cols()*density));
for(int j=0; j<refMat.cols(); j++)
{
+ sparseMat.startVec(j); // not needed for DynamicSparseMatrix
for(int i=0; i<refMat.rows(); i++)
{
Scalar v = (ei_random<double>(0,1) < density) ? ei_random<Scalar>() : Scalar(0);
@@ -128,7 +132,7 @@ initSparse(double density,
if (v!=Scalar(0))
{
- sparseMat.fill(i,j) = v;
+ sparseMat.insertBack(j,i) = v;
if (nonzeroCoords)
nonzeroCoords->push_back(Vector2i(i,j));
}
@@ -139,7 +143,7 @@ initSparse(double density,
refMat(i,j) = v;
}
}
- sparseMat.endFill();
+ sparseMat.finalize();
}
template<typename Scalar> void
@@ -156,7 +160,7 @@ initSparse(double density,
Scalar v = (ei_random<double>(0,1) < density) ? ei_random<Scalar>() : Scalar(0);
if (v!=Scalar(0))
{
- sparseVec.fill(i) = v;
+ sparseVec.insertBack(i) = v;
if (nonzeroCoords)
nonzeroCoords->push_back(i);
}