diff options
author | Gael Guennebaud <g.gael@free.fr> | 2009-01-14 14:24:10 +0000 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2009-01-14 14:24:10 +0000 |
commit | c4c70669d165afefe0c68e7bb194ee81b9fba0b5 (patch) | |
tree | 37793f68813b629ecc0a3067dc0609d6ea873738 /test | |
parent | ee87f5ee49f23179a07c8486cc9c0ebcf6e947d6 (diff) |
Big rewrite in the Sparse module: SparseMatrixBase no longer inherits MatrixBase.
That means a lot of features which were available for sparse matrices
via the dense (and super slow) implemention are no longer available.
All features which make sense for sparse matrices (aka can be implemented efficiently) will be
implemented soon, but don't expect to see an API as rich as for the dense path.
Other changes:
* no block(), row(), col() anymore.
* instead use .innerVector() to get a col or row vector of a matrix.
* .segment(), start(), end() will be back soon, not sure for block()
* faster cwise product
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 2 | ||||
-rw-r--r-- | test/sparse_basic.cpp | 35 | ||||
-rw-r--r-- | test/sparse_vector.cpp | 7 |
3 files changed, 28 insertions, 16 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bc9a5ca73..021799f5e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -195,8 +195,8 @@ ei_add_test(parametrizedline) ei_add_test(alignedbox) ei_add_test(regression) ei_add_test(stdvector) -ei_add_test(sparse_basic) ei_add_test(sparse_vector) +ei_add_test(sparse_basic) ei_add_test(sparse_solvers " " "${SPARSE_LIBS}") # print a summary of the different options diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp index c50682810..54272d871 100644 --- a/test/sparse_basic.cpp +++ b/test/sparse_basic.cpp @@ -72,7 +72,7 @@ template<typename Scalar> void sparse_basic(int rows, int cols) refMat.coeffRef(nonzeroCoords[0].x(), nonzeroCoords[0].y()) = Scalar(5); VERIFY_IS_APPROX(m, refMat); -/* + /* // test InnerIterators and Block expressions for (int t=0; t<10; ++t) { @@ -81,23 +81,23 @@ template<typename Scalar> void sparse_basic(int rows, int cols) int w = ei_random<int>(1,cols-j-1); int h = ei_random<int>(1,rows-i-1); - VERIFY_IS_APPROX(m.block(i,j,h,w), refMat.block(i,j,h,w)); +// 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)); +// 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++) @@ -171,7 +171,7 @@ template<typename Scalar> void sparse_basic(int rows, int cols) } m2.endFill(); std::cerr << m1 << "\n\n" << m2 << "\n"; - VERIFY_IS_APPROX(m1,m2); + VERIFY_IS_APPROX(m2,m1); } // { // m.setZero(); @@ -191,6 +191,17 @@ template<typename Scalar> void sparse_basic(int rows, int cols) // std::cerr << m.transpose() << "\n\n" << refMat.transpose() << "\n\n"; // VERIFY_IS_APPROX(m, refMat); + // test innerVector() + { + DenseMatrix refMat2 = DenseMatrix::Zero(rows, rows); + SparseMatrix<Scalar> m2(rows, rows); + initSparse<Scalar>(density, refMat2, m2); + int j0 = ei_random(0,rows-1); + int j1 = ei_random(0,rows-1); +// VERIFY_IS_APPROX(m2.innerVector(j0), refMat2.col(j0)); +// VERIFY_IS_APPROX(m2.innerVector(j0)+m2.innerVector(j1), refMat2.col(j0)+refMat2.col(j1)); + } + // test transpose { DenseMatrix refMat2 = DenseMatrix::Zero(rows, rows); diff --git a/test/sparse_vector.cpp b/test/sparse_vector.cpp index 0a25884ca..18ef74833 100644 --- a/test/sparse_vector.cpp +++ b/test/sparse_vector.cpp @@ -62,7 +62,8 @@ template<typename Scalar> void sparse_vector(int rows, int cols) for (typename SparseVectorType::InnerIterator it(v1); it; ++it,++j) { VERIFY(nonzerocoords[j]==it.index()); - VERIFY(it.value()==v1[it.index()]); + VERIFY(it.value()==v1.coeff(it.index())); + VERIFY(it.value()==refV1.coeff(it.index())); } } VERIFY_IS_APPROX(v1, refV1); @@ -76,7 +77,7 @@ template<typename Scalar> void sparse_vector(int rows, int cols) VERIFY_IS_APPROX(v1*s1-v2, refV1*s1-refV2); - std::cerr << v1.dot(v2) << " == " << refV1.dot(refV2) << "\n"; +// std::cerr << v1.dot(v2) << " == " << refV1.dot(refV2) << "\n"; VERIFY_IS_APPROX(v1.dot(v2), refV1.dot(refV2)); } @@ -85,7 +86,7 @@ void test_sparse_vector() { for(int i = 0; i < g_repeat; i++) { CALL_SUBTEST( sparse_vector<double>(8, 8) ); -// CALL_SUBTEST( sparse_vector<std::complex<double> >(16, 16) ); + CALL_SUBTEST( sparse_vector<std::complex<double> >(16, 16) ); CALL_SUBTEST( sparse_vector<double>(299, 535) ); } } |