mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
bug #1574: implement "sparse_matrix =,+=,-= diagonal_matrix" with smart insertion strategies of missing diagonal coeffs.
This commit is contained in:
@@ -546,7 +546,7 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
|
||||
{
|
||||
DenseVector d = DenseVector::Random(rows);
|
||||
DenseMatrix refMat2 = d.asDiagonal();
|
||||
SparseMatrixType m2(rows, rows);
|
||||
SparseMatrixType m2;
|
||||
m2 = d.asDiagonal();
|
||||
VERIFY_IS_APPROX(m2, refMat2);
|
||||
SparseMatrixType m3(d.asDiagonal());
|
||||
@@ -554,6 +554,28 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
|
||||
refMat2 += d.asDiagonal();
|
||||
m2 += d.asDiagonal();
|
||||
VERIFY_IS_APPROX(m2, refMat2);
|
||||
m2.setZero(); m2 += d.asDiagonal();
|
||||
refMat2.setZero(); refMat2 += d.asDiagonal();
|
||||
VERIFY_IS_APPROX(m2, refMat2);
|
||||
m2.setZero(); m2 -= d.asDiagonal();
|
||||
refMat2.setZero(); refMat2 -= d.asDiagonal();
|
||||
VERIFY_IS_APPROX(m2, refMat2);
|
||||
|
||||
initSparse<Scalar>(density, refMat2, m2);
|
||||
m2.makeCompressed();
|
||||
m2 += d.asDiagonal();
|
||||
refMat2 += d.asDiagonal();
|
||||
VERIFY_IS_APPROX(m2, refMat2);
|
||||
|
||||
initSparse<Scalar>(density, refMat2, m2);
|
||||
m2.makeCompressed();
|
||||
VectorXi res(rows);
|
||||
for(Index i=0; i<rows; ++i)
|
||||
res(i) = internal::random<int>(0,3);
|
||||
m2.reserve(res);
|
||||
m2 -= d.asDiagonal();
|
||||
refMat2 -= d.asDiagonal();
|
||||
VERIFY_IS_APPROX(m2, refMat2);
|
||||
}
|
||||
|
||||
// test conservative resize
|
||||
|
||||
Reference in New Issue
Block a user