From 349c2c9235ce93b50bd8e38be3e876ee73442ccc Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Thu, 9 Oct 2014 23:35:49 +0200 Subject: bug #367: fix double copies in atWithInsertion, and add respective unit-test --- test/sparse_vector.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'test/sparse_vector.cpp') diff --git a/test/sparse_vector.cpp b/test/sparse_vector.cpp index 5eea9edfd..5dc421976 100644 --- a/test/sparse_vector.cpp +++ b/test/sparse_vector.cpp @@ -23,8 +23,8 @@ template void sparse_vector(int rows, int cols) SparseVectorType v1(rows), v2(rows), v3(rows); DenseMatrix refM1 = DenseMatrix::Zero(rows, rows); DenseVector refV1 = DenseVector::Random(rows), - refV2 = DenseVector::Random(rows), - refV3 = DenseVector::Random(rows); + refV2 = DenseVector::Random(rows), + refV3 = DenseVector::Random(rows); std::vector zerocoords, nonzerocoords; initSparse(densityVec, refV1, v1, &zerocoords, &nonzerocoords); @@ -52,6 +52,20 @@ template void sparse_vector(int rows, int cols) } } VERIFY_IS_APPROX(v1, refV1); + + // test coeffRef with reallocation + { + SparseVectorType v1(rows); + DenseVector v2 = DenseVector::Zero(rows); + for(int k=0; k(0,rows-1); + Scalar v = internal::random(); + v1.coeffRef(i) += v; + v2.coeffRef(i) += v; + } + VERIFY_IS_APPROX(v1,v2); + } v1.coeffRef(nonzerocoords[0]) = Scalar(5); refV1.coeffRef(nonzerocoords[0]) = Scalar(5); -- cgit v1.2.3