aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/sparse_basic.cpp
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2009-01-21 18:46:04 +0000
committerGravatar Gael Guennebaud <g.gael@free.fr>2009-01-21 18:46:04 +0000
commit52cf07d2660099c5c05a5d183991e920eac63895 (patch)
tree55d5cd6f655a9c9ba77bd62c4e9ca37510a0b081 /test/sparse_basic.cpp
parent25f1658fcece61d74778281b39de8358fc024957 (diff)
sparse module:
* add row(i), col(i) functions * add prune() function to remove small coefficients
Diffstat (limited to 'test/sparse_basic.cpp')
-rw-r--r--test/sparse_basic.cpp41
1 files changed, 38 insertions, 3 deletions
diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp
index addd40f9e..5ae038ef8 100644
--- a/test/sparse_basic.cpp
+++ b/test/sparse_basic.cpp
@@ -323,14 +323,49 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
VERIFY_IS_APPROX(x=mLo.template marked<LowerTriangular|SelfAdjoint>()*b, refX=refS*b);
VERIFY_IS_APPROX(x=mS.template marked<SelfAdjoint>()*b, refX=refS*b);
}
+
+ // test prune
+ {
+ SparseMatrixType m2(rows, rows);
+ DenseMatrix refM2(rows, rows);
+ refM2.setZero();
+ int countFalseNonZero = 0;
+ int countTrueNonZero = 0;
+ m2.startFill();
+ for (int j=0; j<m2.outerSize(); ++j)
+ for (int i=0; i<m2.innerSize(); ++i)
+ {
+ float x = ei_random<float>(0,1);
+ if (x<0.1)
+ {
+ // do nothing
+ }
+ else if (x<0.5)
+ {
+ countFalseNonZero++;
+ m2.fill(i,j) = Scalar(0);
+ }
+ else
+ {
+ countTrueNonZero++;
+ m2.fill(i,j) = refM2(i,j) = Scalar(1);
+ }
+ }
+ m2.endFill();
+ VERIFY(countFalseNonZero+countTrueNonZero == m2.nonZeros());
+ VERIFY_IS_APPROX(m2, refM2);
+ m2.prune(1);
+ VERIFY(countTrueNonZero==m2.nonZeros());
+ VERIFY_IS_APPROX(m2, refM2);
+ }
}
void test_sparse_basic()
{
for(int i = 0; i < g_repeat; i++) {
-// CALL_SUBTEST( sparse_basic(SparseMatrix<double>(8, 8)) );
-// CALL_SUBTEST( sparse_basic(SparseMatrix<std::complex<double> >(16, 16)) );
-// CALL_SUBTEST( sparse_basic(SparseMatrix<double>(33, 33)) );
+ CALL_SUBTEST( sparse_basic(SparseMatrix<double>(8, 8)) );
+ CALL_SUBTEST( sparse_basic(SparseMatrix<std::complex<double> >(16, 16)) );
+ CALL_SUBTEST( sparse_basic(SparseMatrix<double>(33, 33)) );
CALL_SUBTEST( sparse_basic(DynamicSparseMatrix<double>(8, 8)) );
}