From d7698c18b7801f041c36adffcdfaefc99140887f Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Thu, 19 Mar 2015 15:11:05 +0100 Subject: Split sparse_basic unit test --- test/sparse_basic.cpp | 204 +------------------------------------------------- 1 file changed, 4 insertions(+), 200 deletions(-) (limited to 'test/sparse_basic.cpp') diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp index d929e1463..75f29a2b4 100644 --- a/test/sparse_basic.cpp +++ b/test/sparse_basic.cpp @@ -30,7 +30,6 @@ template void sparse_basic(const SparseMatrixType& re double density = (std::max)(8./(rows*cols), 0.01); typedef Matrix DenseMatrix; typedef Matrix DenseVector; - typedef Matrix RowDenseVector; Scalar eps = 1e-6; Scalar s1 = internal::random(); @@ -59,77 +58,6 @@ template void sparse_basic(const SparseMatrixType& re VERIFY_IS_APPROX(m, refMat); - // test InnerIterators and Block expressions - for (int t=0; t<10; ++t) - { - Index j = internal::random(0,cols-2); - Index i = internal::random(0,rows-2); - Index w = internal::random(1,cols-j); - Index h = internal::random(1,rows-i); - - VERIFY_IS_APPROX(m.block(i,j,h,w), refMat.block(i,j,h,w)); - for(Index c=0; c void sparse_basic(const SparseMatrixType& re VERIFY_IS_APPROX(m2,m1); } - // test innerVector() - { - DenseMatrix refMat2 = DenseMatrix::Zero(rows, cols); - SparseMatrixType m2(rows, cols); - initSparse(density, refMat2, m2); - Index j0 = internal::random(0,outer-1); - Index j1 = internal::random(0,outer-1); - if(SparseMatrixType::IsRowMajor) - VERIFY_IS_APPROX(m2.innerVector(j0), refMat2.row(j0)); - else - VERIFY_IS_APPROX(m2.innerVector(j0), refMat2.col(j0)); - - if(SparseMatrixType::IsRowMajor) - VERIFY_IS_APPROX(m2.innerVector(j0)+m2.innerVector(j1), refMat2.row(j0)+refMat2.row(j1)); - else - VERIFY_IS_APPROX(m2.innerVector(j0)+m2.innerVector(j1), refMat2.col(j0)+refMat2.col(j1)); - - SparseMatrixType m3(rows,cols); - m3.reserve(VectorXi::Constant(outer,int(inner/2))); - for(Index j=0; j0) - VERIFY(j==numext::real(m3.innerVector(j).lastCoeff())); - } - m3.makeCompressed(); - for(Index j=0; j<(std::min)(outer, inner); ++j) - { - VERIFY(j==numext::real(m3.innerVector(j).nonZeros())); - if(j>0) - VERIFY(j==numext::real(m3.innerVector(j).lastCoeff())); - } - - VERIFY(m3.innerVector(j0).nonZeros() == m3.transpose().innerVector(j0).nonZeros()); - -// m2.innerVector(j0) = 2*m2.innerVector(j1); -// refMat2.col(j0) = 2*refMat2.col(j1); -// VERIFY_IS_APPROX(m2, refMat2); - } - - // test innerVectors() - { - DenseMatrix refMat2 = DenseMatrix::Zero(rows, cols); - SparseMatrixType m2(rows, cols); - initSparse(density, refMat2, m2); - if(internal::random(0,1)>0.5) m2.makeCompressed(); - Index j0 = internal::random(0,outer-2); - Index j1 = internal::random(0,outer-2); - Index n0 = internal::random(1,outer-(std::max)(j0,j1)); - if(SparseMatrixType::IsRowMajor) - VERIFY_IS_APPROX(m2.innerVectors(j0,n0), refMat2.block(j0,0,n0,cols)); - else - VERIFY_IS_APPROX(m2.innerVectors(j0,n0), refMat2.block(0,j0,rows,n0)); - if(SparseMatrixType::IsRowMajor) - VERIFY_IS_APPROX(m2.innerVectors(j0,n0)+m2.innerVectors(j1,n0), - refMat2.middleRows(j0,n0)+refMat2.middleRows(j1,n0)); - else - VERIFY_IS_APPROX(m2.innerVectors(j0,n0)+m2.innerVectors(j1,n0), - refMat2.block(0,j0,rows,n0)+refMat2.block(0,j1,rows,n0)); - - VERIFY_IS_APPROX(m2, refMat2); - - VERIFY(m2.innerVectors(j0,n0).nonZeros() == m2.transpose().innerVectors(j0,n0).nonZeros()); - - m2.innerVectors(j0,n0) = m2.innerVectors(j0,n0) + m2.innerVectors(j1,n0); - if(SparseMatrixType::IsRowMajor) - refMat2.middleRows(j0,n0) = (refMat2.middleRows(j0,n0) + refMat2.middleRows(j1,n0)).eval(); - else - refMat2.middleCols(j0,n0) = (refMat2.middleCols(j0,n0) + refMat2.middleCols(j1,n0)).eval(); - - VERIFY_IS_APPROX(m2, refMat2); - } - // test basic computations { DenseMatrix refM1 = DenseMatrix::Zero(rows, cols); @@ -360,54 +212,6 @@ template void sparse_basic(const SparseMatrixType& re VERIFY(m2.isApprox(m3)); } - - - // test generic blocks - { - DenseMatrix refMat2 = DenseMatrix::Zero(rows, cols); - SparseMatrixType m2(rows, cols); - initSparse(density, refMat2, m2); - Index j0 = internal::random(0,outer-2); - Index j1 = internal::random(0,outer-2); - Index n0 = internal::random(1,outer-(std::max)(j0,j1)); - if(SparseMatrixType::IsRowMajor) - VERIFY_IS_APPROX(m2.block(j0,0,n0,cols), refMat2.block(j0,0,n0,cols)); - else - VERIFY_IS_APPROX(m2.block(0,j0,rows,n0), refMat2.block(0,j0,rows,n0)); - - if(SparseMatrixType::IsRowMajor) - VERIFY_IS_APPROX(m2.block(j0,0,n0,cols)+m2.block(j1,0,n0,cols), - refMat2.block(j0,0,n0,cols)+refMat2.block(j1,0,n0,cols)); - else - VERIFY_IS_APPROX(m2.block(0,j0,rows,n0)+m2.block(0,j1,rows,n0), - refMat2.block(0,j0,rows,n0)+refMat2.block(0,j1,rows,n0)); - - Index i = internal::random(0,m2.outerSize()-1); - if(SparseMatrixType::IsRowMajor) { - m2.innerVector(i) = m2.innerVector(i) * s1; - refMat2.row(i) = refMat2.row(i) * s1; - VERIFY_IS_APPROX(m2,refMat2); - } else { - m2.innerVector(i) = m2.innerVector(i) * s1; - refMat2.col(i) = refMat2.col(i) * s1; - VERIFY_IS_APPROX(m2,refMat2); - } - - Index r0 = internal::random(0,rows-2); - Index c0 = internal::random(0,cols-2); - Index r1 = internal::random(1,rows-r0); - Index c1 = internal::random(1,cols-c0); - - VERIFY_IS_APPROX(DenseVector(m2.col(c0)), refMat2.col(c0)); - VERIFY_IS_APPROX(m2.col(c0), refMat2.col(c0)); - - VERIFY_IS_APPROX(RowDenseVector(m2.row(r0)), refMat2.row(r0)); - VERIFY_IS_APPROX(m2.row(r0), refMat2.row(r0)); - - VERIFY_IS_APPROX(m2.block(r0,c0,r1,c1), refMat2.block(r0,c0,r1,c1)); - VERIFY_IS_APPROX((2*m2).block(r0,c0,r1,c1), (2*refMat2).block(r0,c0,r1,c1)); - } - // test prune { SparseMatrixType m2(rows, cols); @@ -646,8 +450,8 @@ void test_sparse_basic() CALL_SUBTEST_2(( sparse_basic(SparseMatrix, ColMajor>(r, c)) )); CALL_SUBTEST_2(( sparse_basic(SparseMatrix, RowMajor>(r, c)) )); CALL_SUBTEST_1(( sparse_basic(SparseMatrix(r, c)) )); - CALL_SUBTEST_1(( sparse_basic(SparseMatrix(r, c)) )); - CALL_SUBTEST_1(( sparse_basic(SparseMatrix(r, c)) )); + CALL_SUBTEST_5(( sparse_basic(SparseMatrix(r, c)) )); + CALL_SUBTEST_5(( sparse_basic(SparseMatrix(r, c)) )); r = Eigen::internal::random(1,100); c = Eigen::internal::random(1,100); @@ -655,8 +459,8 @@ void test_sparse_basic() r = c; // check square matrices in 25% of tries } - CALL_SUBTEST_1(( sparse_basic(SparseMatrix(short(r), short(c))) )); - CALL_SUBTEST_1(( sparse_basic(SparseMatrix(short(r), short(c))) )); + CALL_SUBTEST_6(( sparse_basic(SparseMatrix(short(r), short(c))) )); + CALL_SUBTEST_6(( sparse_basic(SparseMatrix(short(r), short(c))) )); } // Regression test for bug 900: (manually insert higher values here, if you have enough RAM): -- cgit v1.2.3