Skip to content

Commit

Permalink
8274517: java/util/DoubleStreamSums/CompensatedSums.java fails with e…
Browse files Browse the repository at this point in the history
…xpected [true] but found [false]

Reviewed-by: alanb, bpb
  • Loading branch information
rgiulietti authored and Alan Bateman committed May 9, 2022
1 parent 034f20f commit 97a9835
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions test/jdk/java/util/DoubleStreamSums/CompensatedSums.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -24,6 +24,9 @@
/*
* @test
* @bug 8214761
* @key randomness
* @library /test/lib
* @build jdk.test.lib.RandomFactory
* @run testng CompensatedSums
* @summary
*/
Expand All @@ -34,13 +37,16 @@
import java.util.function.Supplier;
import java.util.stream.DoubleStream;

import jdk.test.lib.RandomFactory;
import org.testng.Assert;
import org.testng.annotations.Test;

public class CompensatedSums {

@Test
public void testCompensatedSums() {
Random r = RandomFactory.getRandom();

double naive = 0;
double jdkSequentialStreamError = 0;
double goodSequentialStreamError = 0;
Expand All @@ -50,7 +56,7 @@ public void testCompensatedSums() {

for (int loop = 0; loop < 100; loop++) {
// sequence of random numbers of varying magnitudes, both positive and negative
double[] rand = new Random().doubles(1_000_000)
double[] rand = r.doubles(1_000_000)
.map(Math::log)
.map(x -> (Double.doubleToLongBits(x) % 2 == 0) ? x : -x)
.toArray();
Expand Down Expand Up @@ -85,7 +91,7 @@ public void testCompensatedSums() {
}

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

Assert.assertTrue(goodSequentialStreamError >= jdkSequentialStreamError);
Assert.assertTrue(naive > jdkSequentialStreamError);
Expand All @@ -97,7 +103,7 @@ private static double square(double arg) {
return arg * arg;
}

// from OpenJDK8 Collectors, unmodified
// from OpenJDK 18 Collectors, unmodified
static double[] sumWithCompensation(double[] intermediateSum, double value) {
double tmp = value - intermediateSum[1];
double sum = intermediateSum[0];
Expand All @@ -107,9 +113,10 @@ static double[] sumWithCompensation(double[] intermediateSum, double value) {
return intermediateSum;
}

// from OpenJDK8 Collectors, unmodified
// from OpenJDK 18 Collectors, unmodified
static double computeFinalSum(double[] summands) {
double tmp = summands[0] + summands[1];
// Final sum with better error bounds subtract second summand as it is negated
double tmp = summands[0] - summands[1];
double simpleSum = summands[summands.length - 1];
if (Double.isNaN(tmp) && Double.isInfinite(simpleSum))
return simpleSum;
Expand Down

5 comments on commit 97a9835

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 97a9835 Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 97a9835 Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch GoeLin-backport-97a98352 in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 97a98352 from the openjdk/jdk repository.

The commit being backported was authored by Raffaello Giulietti on 9 May 2022 and was reviewed by Alan Bateman and Brian Burkhalter.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-97a98352:GoeLin-backport-97a98352
$ git checkout GoeLin-backport-97a98352
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-97a98352

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 97a9835 Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 97a9835 Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch GoeLin-backport-97a98352 in my personal fork of openjdk/jdk11u-dev. To create a pull request with this backport targeting openjdk/jdk11u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 97a98352 from the openjdk/jdk repository.

The commit being backported was authored by Raffaello Giulietti on 9 May 2022 and was reviewed by Alan Bateman and Brian Burkhalter.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk11u-dev:

$ git fetch https://github.com/openjdk-bots/jdk11u-dev GoeLin-backport-97a98352:GoeLin-backport-97a98352
$ git checkout GoeLin-backport-97a98352
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk11u-dev GoeLin-backport-97a98352

Please sign in to comment.