From 28293142842c525eec1adde377999b065dea8cbf Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 4 May 2009 14:25:12 +0000 Subject: 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. --- test/sparse.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'test/sparse.h') 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* zeroCoords = 0, std::vector* 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(0,1) < density) ? ei_random() : 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 void @@ -107,9 +109,11 @@ initSparse(double density, std::vector* zeroCoords = 0, std::vector* 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(0,1) < density) ? ei_random() : 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 void @@ -156,7 +160,7 @@ initSparse(double density, Scalar v = (ei_random(0,1) < density) ? ei_random() : Scalar(0); if (v!=Scalar(0)) { - sparseVec.fill(i) = v; + sparseVec.insertBack(i) = v; if (nonzeroCoords) nonzeroCoords->push_back(i); } -- cgit v1.2.3