[jdk17u-dev] RFR: 8315024: Vector API FP reduction tests should not test for exact equality

Amos Shi ashi at openjdk.org
Fri Aug 16 05:07:17 UTC 2024


On Fri, 9 Aug 2024 08:27:05 GMT, Matthias Baesken <mbaesken at openjdk.org> wrote:

>> Backport of [JDK-8315024](https://bugs.openjdk.org/browse/JDK-8315024)
>> - This PR has two commits
>>   - `commit 1`: the git apply result, which is `clean`
>>   - `commit 2`: manually merge the following two `.rej` files
>>     - `test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java.rej`
>>     - `test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java.rej`
>> 
>> Content of `test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java.rej`
>> 
>> 
>> @@ -668,15 +670,21 @@
>>  
>>      static void assertReductionArraysEquals(double[] r, double rc, double[] a,
>>                                              FReductionOp f, FReductionAllOp fa) {
>> +        assertReductionArraysEquals(r, rc, a, f, fa, (double)0.0);
>> +    }
>> +
>> +    static void assertReductionArraysEquals(double[] r, double rc, double[] a,
>> +                                            FReductionOp f, FReductionAllOp fa,
>> +                                            double relativeError) {
>>          int i = 0;
>>          try {
>> -            Assert.assertEquals(rc, fa.apply(a));
>> +            Assert.assertEquals(rc, fa.apply(a), Math.abs(rc * relativeError));
>>              for (; i < a.length; i += SPECIES.length()) {
>> -                Assert.assertEquals(r[i], f.apply(a, i));
>> +                Assert.assertEquals(r[i], f.apply(a, i), Math.abs(r[i] * relativeError));
>>              }
>>          } catch (AssertionError e) {
>> -            Assert.assertEquals(rc, fa.apply(a), "Final result is incorrect!");
>> -            Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
>> +            Assert.assertEquals(rc, fa.apply(a), Math.abs(rc * relativeError), "Final result is incorrect!");
>> +            Assert.assertEquals(r[i], f.apply(a, i), Math.abs(r[i] * relativeError), "at index #" + i);
>>          }
>>      }
>>  
>> @@ -690,15 +698,22 @@
>>  
>>      static void assertReductionArraysEqualsMasked(double[] r, double rc, double[] a, boolean[] mask,
>>                                              FReductionMaskedOp f, FReductionAllMaskedOp fa) {
>> +        assertReductionArraysEqualsMasked(r, rc, a, mask, f, fa, (double)0.0);
>> +    }
>> +
>> +    static void assertReductionArraysEqualsMasked(double[] r, double rc, double[] a, boolean[] mask,
>> +                                            FReductionMaskedOp f, FReductionAllMaskedOp fa,
>> +                                            double relativeError) {
>>          int i = 0;
>>          try {
>> -            Assert.assertEquals(rc, fa.apply(a, mask))...
>
> In the original commit I see  in [test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java](https://github.com/openjdk/jdk/commit/e6f23a90d4a53339a3c9c2b76fc5d317940e4472#diff-a1baf5cd2c3bc9046a703b75c78cdb1948a2ca10d84ac1428dee4b471f87546f)
> 
> https://github.com/openjdk/jdk/commit/e6f23a90d4a53339a3c9c2b76fc5d317940e4472
> private static final double RELATIVE_ROUNDING_ERROR = (double)0.000001;
> 
> Is it intentional that it is not in the backport ?

Hi @MBaesken,

Somehow the git `patch` command has put these two lines to the `test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java` file at line `625-626`


+ 625    // for floating point reduction ops that may introduce rounding errors
+ 626    private static final double RELATIVE_ROUNDING_ERROR = (double)0.000001;
``` 

I will move them to earlier lines in respect to the original commit.


Regards
Amos
A Happy Developer

-------------

PR Comment: https://git.openjdk.org/jdk17u-dev/pull/2768#issuecomment-2292812891


More information about the jdk-updates-dev mailing list