diff options
author | Benjamin Piwowarski <benjamin@bpiwowar.net> | 2012-07-19 00:07:06 +0200 |
---|---|---|
committer | Benjamin Piwowarski <benjamin@bpiwowar.net> | 2012-07-19 00:07:06 +0200 |
commit | 6bf49ceac212cc575f70d1d32cf3849a4177624a (patch) | |
tree | 85fe4dd6d2bc23df52835a81d606b2e7a0b76a37 /test | |
parent | 3f08a6a126a334bb89c187bcf4ee3598972e616b (diff) |
bug #449: add SparseMatrix::conservativeResize feature
Diffstat (limited to 'test')
-rw-r--r-- | test/sparse_basic.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp index 8897a9dca..767451450 100644 --- a/test/sparse_basic.cpp +++ b/test/sparse_basic.cpp @@ -379,6 +379,41 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re initSparse<Scalar>(density, refMat2, m2); VERIFY_IS_APPROX(m2.diagonal(), refMat2.diagonal().eval()); } + + // test conservative resize + { + std::vector< std::pair<int,int> > inc; + inc.push_back(std::pair<int,int>(-3,-2)); + inc.push_back(std::pair<int,int>(0,0)); + inc.push_back(std::pair<int,int>(3,2)); + inc.push_back(std::pair<int,int>(3,0)); + inc.push_back(std::pair<int,int>(0,3)); + + for(size_t i = 0; i< inc.size(); i++) { + int incRows = inc[i].first; + int incCols = inc[i].second; + SparseMatrixType m1(rows, cols); + DenseMatrix refMat1 = DenseMatrix::Zero(rows, cols); + initSparse<Scalar>(density, refMat1, m1); + + m1.conservativeResize(rows+incRows, cols+incCols); + refMat1.conservativeResize(rows+incRows, cols+incCols); + if (incRows > 0) refMat1.bottomRows(incRows).setZero(); + if (incCols > 0) refMat1.rightCols(incCols).setZero(); + + VERIFY_IS_APPROX(m1, refMat1); + + // Insert new values + if (incRows > 0) + m1.insert(refMat1.rows()-1, 0) = refMat1(refMat1.rows()-1, 0) = 1; + if (incCols > 0) + m1.insert(0, refMat1.cols()-1) = refMat1(0, refMat1.cols()-1) = 1; + + VERIFY_IS_APPROX(m1, refMat1); + + + } + } } void test_sparse_basic() |