aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Daniel Gomez Ferro <dgomezferro@gmail.com>2008-09-02 15:28:49 +0000
committerGravatar Daniel Gomez Ferro <dgomezferro@gmail.com>2008-09-02 15:28:49 +0000
commit8fb1678f0f174e85f6550e14f349841e406c8f53 (patch)
tree8eef447ce588be1dd450cca201f56fe32e36e4b5 /test
parent46fe7a3d9ec14ea56a879c48ba7f15e78342c8cb (diff)
Extended sparse unit-test: nested blocks and InnerIterators.
Block specialization for sparse matrices. InnerIterators for Blocks and fixes in CoreIterators.
Diffstat (limited to 'test')
-rw-r--r--test/sparse.cpp50
1 files changed, 47 insertions, 3 deletions
diff --git a/test/sparse.cpp b/test/sparse.cpp
index bac1091ce..7decb4111 100644
--- a/test/sparse.cpp
+++ b/test/sparse.cpp
@@ -25,9 +25,8 @@
#include "main.h"
#include <Eigen/Sparse>
-template<typename Scalar> void sparse()
+template<typename Scalar> void sparse(int rows, int cols)
{
- int rows = 8, cols = 8;
double density = std::max(8./(rows*cols), 0.01);
typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix;
Scalar eps = 1e-6;
@@ -73,6 +72,49 @@ template<typename Scalar> void sparse()
VERIFY_IS_APPROX(m, refMat);
+ // test InnerIterators and Block expressions
+ for(int j=0; j<cols; j++)
+ {
+ for(int i=0; i<rows; i++)
+ {
+ for(int w=1; w<cols-j; w++)
+ {
+ for(int h=1; h<rows-i; h++)
+ {
+ VERIFY_IS_APPROX(m.block(i,j,h,w), refMat.block(i,j,h,w));
+ for(int c=0; c<w; c++)
+ {
+ VERIFY_IS_APPROX(m.block(i,j,h,w).col(c), refMat.block(i,j,h,w).col(c));
+ for(int r=0; r<h; r++)
+ {
+ VERIFY_IS_APPROX(m.block(i,j,h,w).col(c).coeff(r), refMat.block(i,j,h,w).col(c).coeff(r));
+ }
+ }
+ for(int r=0; r<h; r++)
+ {
+ VERIFY_IS_APPROX(m.block(i,j,h,w).row(r), refMat.block(i,j,h,w).row(r));
+ for(int c=0; c<w; c++)
+ {
+ VERIFY_IS_APPROX(m.block(i,j,h,w).row(r).coeff(c), refMat.block(i,j,h,w).row(r).coeff(c));
+ }
+ }
+ }
+ }
+ }
+ }
+
+ for(int c=0; c<cols; c++)
+ {
+ VERIFY_IS_APPROX(m.col(c) + m.col(c), (m + m).col(c));
+ VERIFY_IS_APPROX(m.col(c) + m.col(c), refMat.col(c) + refMat.col(c));
+ }
+
+ for(int r=0; r<rows; r++)
+ {
+ VERIFY_IS_APPROX(m.row(r) + m.row(r), (m + m).row(r));
+ VERIFY_IS_APPROX(m.row(r) + m.row(r), refMat.row(r) + refMat.row(r));
+ }
+
// test SparseSetters
// coherent setter
// TODO extend the MatrixSetter
@@ -102,9 +144,11 @@ template<typename Scalar> void sparse()
}
}
VERIFY_IS_APPROX(m, refMat);
+
}
void test_sparse()
{
- sparse<double>();
+ sparse<double>(8, 8);
+ sparse<double>(16, 16);
}