mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
bug #449: add SparseMatrix::conservativeResize feature
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user