diff options
author | Gael Guennebaud <g.gael@free.fr> | 2011-09-08 13:42:54 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2011-09-08 13:42:54 +0200 |
commit | 7706bafcfd26471801c3ac43a120a7e66ee36160 (patch) | |
tree | bb15c07c3cbe8e9cd2c85dad5d9faeaa8d94b6f0 /test/sparse_basic.cpp | |
parent | 7898281b2b29fcb74fe9b78d9382e6ca91c25f5d (diff) |
add the possibility to reserve room for inner vector in SparseMatrix
Diffstat (limited to 'test/sparse_basic.cpp')
-rw-r--r-- | test/sparse_basic.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp index a6c148591..d4579e4c9 100644 --- a/test/sparse_basic.cpp +++ b/test/sparse_basic.cpp @@ -140,6 +140,28 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re m2.finalize(); VERIFY_IS_APPROX(m2,m1); } + + // test insert (un-compressed) + for(int mode=0;mode<4;++mode) + { + DenseMatrix m1(rows,cols); + m1.setZero(); + SparseMatrixType m2(rows,cols); + VectorXi r(VectorXi::Constant(m2.outerSize(), ((mode%2)==0) ? m2.innerSize() : std::max<int>(1,m2.innerSize()/8))); + m2.reserve(r); + for (int k=0; k<rows*cols; ++k) + { + int i = internal::random<int>(0,rows-1); + int j = internal::random<int>(0,cols-1); + if (m1.coeff(i,j)==Scalar(0)) + m2.insert(i,j) = m1(i,j) = internal::random<Scalar>(); + if(mode==3) + m2.reserve(r); + } + m2.finalize(); + m2.makeCompressed(); + VERIFY_IS_APPROX(m2,m1); + } // test basic computations { |