diff options
author | Gael Guennebaud <g.gael@free.fr> | 2012-11-16 09:02:50 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2012-11-16 09:02:50 +0100 |
commit | 4e60283289c75f34ea12df14e781399ce733d7d5 (patch) | |
tree | 329279e0baddd8f2f1ef056fed9b8c112ca0c4fd /test/sparse_basic.cpp | |
parent | 3dc8f8536a080afb427f137b8598d31605fb3f05 (diff) |
Remove Sparse/InnerVectorSet expression in favor of a more general Block<> specialization for Sparse expression.
The specializations for "InnerPanels" are still preserved for efficiency reasons and because they offer additional usefull features.
Diffstat (limited to 'test/sparse_basic.cpp')
-rw-r--r-- | test/sparse_basic.cpp | 119 |
1 files changed, 71 insertions, 48 deletions
diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp index 4566de9f2..cebb5e6a0 100644 --- a/test/sparse_basic.cpp +++ b/test/sparse_basic.cpp @@ -155,6 +155,69 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re VERIFY_IS_APPROX(m2,m1); } + // test innerVector() + { + DenseMatrix refMat2 = DenseMatrix::Zero(rows, rows); + SparseMatrixType m2(rows, rows); + initSparse<Scalar>(density, refMat2, m2); + int j0 = internal::random<int>(0,rows-1); + int j1 = internal::random<int>(0,rows-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,rows); + m3.reserve(VectorXi::Constant(rows,rows/2)); + for(int j=0; j<rows; ++j) + for(int k=0; k<j; ++k) + m3.insertByOuterInner(j,k) = k+1; + for(int j=0; j<rows; ++j) + { + VERIFY(j==internal::real(m3.innerVector(j).nonZeros())); + if(j>0) + VERIFY(j==internal::real(m3.innerVector(j).lastCoeff())); + } + m3.makeCompressed(); + for(int j=0; j<rows; ++j) + { + VERIFY(j==internal::real(m3.innerVector(j).nonZeros())); + if(j>0) + VERIFY(j==internal::real(m3.innerVector(j).lastCoeff())); + } + + //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, rows); + SparseMatrixType m2(rows, rows); + initSparse<Scalar>(density, refMat2, m2); + int j0 = internal::random<int>(0,rows-2); + int j1 = internal::random<int>(0,rows-2); + int n0 = internal::random<int>(1,rows-(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.block(j0,0,n0,cols)+refMat2.block(j1,0,n0,cols)); + else + VERIFY_IS_APPROX(m2.innerVectors(j0,n0)+m2.innerVectors(j1,n0), + refMat2.block(0,j0,rows,n0)+refMat2.block(0,j1,rows,n0)); + //m2.innerVectors(j0,n0) = m2.innerVectors(j0,n0) + m2.innerVectors(j1,n0); + //refMat2.block(0,j0,rows,n0) = refMat2.block(0,j0,rows,n0) + refMat2.block(0,j1,rows,n0); + } + // test basic computations { DenseMatrix refM1 = DenseMatrix::Zero(rows, rows); @@ -212,48 +275,9 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re VERIFY_IS_APPROX(SparseMatrixType(m2.adjoint()), refMat2.adjoint()); } - // test innerVector() - { - DenseMatrix refMat2 = DenseMatrix::Zero(rows, rows); - SparseMatrixType m2(rows, rows); - initSparse<Scalar>(density, refMat2, m2); - int j0 = internal::random<int>(0,rows-1); - int j1 = internal::random<int>(0,rows-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,rows); - m3.reserve(VectorXi::Constant(rows,rows/2)); - for(int j=0; j<rows; ++j) - for(int k=0; k<j; ++k) - m3.insertByOuterInner(j,k) = k+1; - for(int j=0; j<rows; ++j) - { - VERIFY(j==internal::real(m3.innerVector(j).nonZeros())); - if(j>0) - VERIFY(j==internal::real(m3.innerVector(j).lastCoeff())); - } - m3.makeCompressed(); - for(int j=0; j<rows; ++j) - { - VERIFY(j==internal::real(m3.innerVector(j).nonZeros())); - if(j>0) - VERIFY(j==internal::real(m3.innerVector(j).lastCoeff())); - } - - //m2.innerVector(j0) = 2*m2.innerVector(j1); - //refMat2.col(j0) = 2*refMat2.col(j1); - //VERIFY_IS_APPROX(m2, refMat2); - } - - // test innerVectors() + + + // test generic blocks { DenseMatrix refMat2 = DenseMatrix::Zero(rows, rows); SparseMatrixType m2(rows, rows); @@ -262,17 +286,16 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re int j1 = internal::random<int>(0,rows-2); int n0 = internal::random<int>(1,rows-(std::max)(j0,j1)); if(SparseMatrixType::IsRowMajor) - VERIFY_IS_APPROX(m2.innerVectors(j0,n0), refMat2.block(j0,0,n0,cols)); + VERIFY_IS_APPROX(m2.block(j0,0,n0,cols), refMat2.block(j0,0,n0,cols)); else - VERIFY_IS_APPROX(m2.innerVectors(j0,n0), refMat2.block(0,j0,rows,n0)); + VERIFY_IS_APPROX(m2.block(0,j0,rows,n0), refMat2.block(0,j0,rows,n0)); + if(SparseMatrixType::IsRowMajor) - VERIFY_IS_APPROX(m2.innerVectors(j0,n0)+m2.innerVectors(j1,n0), + 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.innerVectors(j0,n0)+m2.innerVectors(j1,n0), + 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)); - //m2.innerVectors(j0,n0) = m2.innerVectors(j0,n0) + m2.innerVectors(j1,n0); - //refMat2.block(0,j0,rows,n0) = refMat2.block(0,j0,rows,n0) + refMat2.block(0,j1,rows,n0); } // test prune |