Fix noise in sparse_basic_3 (numerical cancellation)

This commit is contained in:
Gael Guennebaud 2018-12-08 00:13:37 +01:00
parent efaf03bf96
commit cd25b538ab

View File

@ -658,7 +658,8 @@ void big_sparse_triplet(Index rows, Index cols, double density) {
{
Index r = internal::random<Index>(0,rows-1);
Index c = internal::random<Index>(0,cols-1);
Scalar v = internal::random<Scalar>();
// use positive values to prevent numerical cancellation errors in sum
Scalar v = numext::abs(internal::random<Scalar>());
triplets.push_back(TripletType(r,c,v));
sum += v;
}