From 5a3c48e3c6c6a3966b68f715610e0eaafa906b2a Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sat, 18 Apr 2015 22:43:27 +0200 Subject: bug #942: fix dangling references in evaluator of diagonal * sparse products. --- test/sparse_product.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test/sparse_product.cpp') diff --git a/test/sparse_product.cpp b/test/sparse_product.cpp index 3bad3def7..201d5bc49 100644 --- a/test/sparse_product.cpp +++ b/test/sparse_product.cpp @@ -278,11 +278,35 @@ template void sparse_produc VERIFY_IS_APPROX( m4(0,0), 0.0 ); } +template +void bug_942() +{ + typedef Matrix Vector; + typedef SparseMatrix ColSpMat; + typedef SparseMatrix RowSpMat; + ColSpMat cmA(1,1); + cmA.insert(0,0) = 1; + + RowSpMat rmA(1,1); + rmA.insert(0,0) = 1; + + Vector d(1); + d[0] = 2; + + double res = 2; + + VERIFY_IS_APPROX( ( cmA*d.asDiagonal() ).eval().coeff(0,0), res ); + VERIFY_IS_APPROX( ( d.asDiagonal()*rmA ).eval().coeff(0,0), res ); + VERIFY_IS_APPROX( ( rmA*d.asDiagonal() ).eval().coeff(0,0), res ); + VERIFY_IS_APPROX( ( d.asDiagonal()*cmA ).eval().coeff(0,0), res ); +} + void test_sparse_product() { for(int i = 0; i < g_repeat; i++) { CALL_SUBTEST_1( (sparse_product >()) ); CALL_SUBTEST_1( (sparse_product >()) ); + CALL_SUBTEST_1( (bug_942()) ); CALL_SUBTEST_2( (sparse_product, ColMajor > >()) ); CALL_SUBTEST_2( (sparse_product, RowMajor > >()) ); CALL_SUBTEST_3( (sparse_product >()) ); -- cgit v1.2.3