Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8273514: java/util/DoubleStreamSums/CompensatedSums.java failure #5430

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -32,11 +32,8 @@
import java.util.function.BiConsumer;
import java.util.function.ObjDoubleConsumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.DoubleStream;

import static org.testng.Assert.assertTrue;

import org.testng.Assert;
import org.testng.annotations.Test;

@@ -68,36 +65,38 @@ public void testCompensatedSums() {
// Older less accurate implementations included here as the baseline.

// squared error of naive sum by reduction - should be large
naive += Math.pow(DoubleStream.of(rand).reduce((x, y) -> x+y).getAsDouble() - sum[0], 2);
naive += square(DoubleStream.of(rand).reduce((x, y) -> x+y).getAsDouble() - sum[0]);

// squared error of sequential sum - should be 0
jdkSequentialStreamError += Math.pow(DoubleStream.of(rand).sum() - sum[0], 2);
jdkSequentialStreamError += square(DoubleStream.of(rand).sum() - sum[0]);

goodSequentialStreamError += Math.pow(computeFinalSum(DoubleStream.of(rand).collect(doubleSupplier,objDoubleConsumer,goodCollectorConsumer)) - sum[0], 2);
goodSequentialStreamError += square(computeFinalSum(DoubleStream.of(rand).collect(doubleSupplier,objDoubleConsumer,goodCollectorConsumer)) - sum[0]);

// squared error of parallel sum from the JDK
jdkParallelStreamError += Math.pow(DoubleStream.of(rand).parallel().sum() - sum[0], 2);
jdkParallelStreamError += square(DoubleStream.of(rand).parallel().sum() - sum[0]);

// squared error of parallel sum
goodParallelStreamError += Math.pow(computeFinalSum(DoubleStream.of(rand).parallel().collect(doubleSupplier,objDoubleConsumer,goodCollectorConsumer)) - sum[0], 2);
goodParallelStreamError += square(computeFinalSum(DoubleStream.of(rand).parallel().collect(doubleSupplier,objDoubleConsumer,goodCollectorConsumer)) - sum[0]);

// the bad parallel stream
badParallelStreamError += Math.pow(computeFinalSum(DoubleStream.of(rand).parallel().collect(doubleSupplier,objDoubleConsumer,badCollectorConsumer)) - sum[0], 2);
badParallelStreamError += square(computeFinalSum(DoubleStream.of(rand).parallel().collect(doubleSupplier,objDoubleConsumer,badCollectorConsumer)) - sum[0]);


igraves marked this conversation as resolved.
Show resolved Hide resolved
}

Assert.assertEquals(goodSequentialStreamError, 0.0);
Assert.assertEquals(goodSequentialStreamError, jdkSequentialStreamError);

Assert.assertTrue(jdkParallelStreamError <= goodParallelStreamError);
Assert.assertTrue(badParallelStreamError > goodParallelStreamError);
Assert.assertTrue(badParallelStreamError > jdkParallelStreamError);

Assert.assertTrue(goodSequentialStreamError >= jdkSequentialStreamError);
Assert.assertTrue(naive > jdkSequentialStreamError);
Assert.assertTrue(naive > jdkParallelStreamError);

}

private static double square(double arg) {
return arg * arg;
}

// from OpenJDK8 Collectors, unmodified
static double[] sumWithCompensation(double[] intermediateSum, double value) {
double tmp = value - intermediateSum[1];