From 204d1f1456c0a58c1b8f5ebe54a794766b757f62 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sat, 8 Dec 2018 00:13:37 +0100 Subject: [PATCH] Fix noise in sparse_basic_3 (numerical cancellation) (grafted from cd25b538abff7370100ef5613b8138919f89c7b0 ) --- test/sparse_basic.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp index f84b6e3f5..d0ef722b6 100644 --- a/test/sparse_basic.cpp +++ b/test/sparse_basic.cpp @@ -630,7 +630,8 @@ void big_sparse_triplet(Index rows, Index cols, double density) { { Index r = internal::random(0,rows-1); Index c = internal::random(0,cols-1); - Scalar v = internal::random(); + // use positive values to prevent numerical cancellation errors in sum + Scalar v = numext::abs(internal::random()); triplets.push_back(TripletType(r,c,v)); sum += v; }