8315024: Vector API FP reduction tests should not test for exact equality

Reviewed-by: epeter, thartmann
This commit is contained in:
Gergö Barany 2023-10-24 08:58:15 +00:00 committed by Tobias Hartmann
parent fd332da1c8
commit e6f23a90d4
13 changed files with 415 additions and 120 deletions

View File

@ -60,6 +60,8 @@ public class Double128VectorTests extends AbstractVectorTest {
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
// for floating point reduction ops that may introduce rounding errors
private static final double RELATIVE_ROUNDING_ERROR = (double)0.000001;
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128);
@ -119,15 +121,21 @@ public class Double128VectorTests extends AbstractVectorTest {
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);
}
}
@ -141,15 +149,22 @@ public class Double128VectorTests extends AbstractVectorTest {
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));
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError));
for (; i < a.length; i += SPECIES.length()) {
Assert.assertEquals(r[i], f.apply(a, i, mask));
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] *
relativeError));
}
} catch (AssertionError e) {
Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] * relativeError), "at index #" + i);
}
}
@ -1078,6 +1093,14 @@ public class Double128VectorTests extends AbstractVectorTest {
return fill(s * BUFFER_REPS,
i -> (((double)(i + 1) == 0) ? 1 : (double)(i + 1)));
}),
withToString("double[0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> (double)0.01 + ((double)i / (i + 1)));
}),
withToString("double[i -> i % 17 == 0 ? cornerCaseValue(i) : 0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> i % 17 == 0 ? cornerCaseValue(i) : (double)0.01 + ((double)i / (i + 1)));
}),
withToString("double[cornerCaseValue(i)]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> cornerCaseValue(i));
@ -2168,7 +2191,7 @@ public class Double128VectorTests extends AbstractVectorTest {
}
assertReductionArraysEquals(r, ra, a,
Double128VectorTests::ADDReduce, Double128VectorTests::ADDReduceAll);
Double128VectorTests::ADDReduce, Double128VectorTests::ADDReduceAll, RELATIVE_ROUNDING_ERROR);
}
static double ADDReduceMasked(double[] a, int idx, boolean[] mask) {
@ -2214,7 +2237,7 @@ public class Double128VectorTests extends AbstractVectorTest {
}
assertReductionArraysEqualsMasked(r, ra, a, mask,
Double128VectorTests::ADDReduceMasked, Double128VectorTests::ADDReduceAllMasked);
Double128VectorTests::ADDReduceMasked, Double128VectorTests::ADDReduceAllMasked, RELATIVE_ROUNDING_ERROR);
}
static double MULReduce(double[] a, int idx) {
@ -2257,7 +2280,7 @@ public class Double128VectorTests extends AbstractVectorTest {
}
assertReductionArraysEquals(r, ra, a,
Double128VectorTests::MULReduce, Double128VectorTests::MULReduceAll);
Double128VectorTests::MULReduce, Double128VectorTests::MULReduceAll, RELATIVE_ROUNDING_ERROR);
}
static double MULReduceMasked(double[] a, int idx, boolean[] mask) {
@ -2303,7 +2326,7 @@ public class Double128VectorTests extends AbstractVectorTest {
}
assertReductionArraysEqualsMasked(r, ra, a, mask,
Double128VectorTests::MULReduceMasked, Double128VectorTests::MULReduceAllMasked);
Double128VectorTests::MULReduceMasked, Double128VectorTests::MULReduceAllMasked, RELATIVE_ROUNDING_ERROR);
}
static double MINReduce(double[] a, int idx) {

View File

@ -60,6 +60,8 @@ public class Double256VectorTests extends AbstractVectorTest {
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
// for floating point reduction ops that may introduce rounding errors
private static final double RELATIVE_ROUNDING_ERROR = (double)0.000001;
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256);
@ -119,15 +121,21 @@ public class Double256VectorTests extends AbstractVectorTest {
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);
}
}
@ -141,15 +149,22 @@ public class Double256VectorTests extends AbstractVectorTest {
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));
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError));
for (; i < a.length; i += SPECIES.length()) {
Assert.assertEquals(r[i], f.apply(a, i, mask));
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] *
relativeError));
}
} catch (AssertionError e) {
Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] * relativeError), "at index #" + i);
}
}
@ -1078,6 +1093,14 @@ public class Double256VectorTests extends AbstractVectorTest {
return fill(s * BUFFER_REPS,
i -> (((double)(i + 1) == 0) ? 1 : (double)(i + 1)));
}),
withToString("double[0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> (double)0.01 + ((double)i / (i + 1)));
}),
withToString("double[i -> i % 17 == 0 ? cornerCaseValue(i) : 0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> i % 17 == 0 ? cornerCaseValue(i) : (double)0.01 + ((double)i / (i + 1)));
}),
withToString("double[cornerCaseValue(i)]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> cornerCaseValue(i));
@ -2168,7 +2191,7 @@ public class Double256VectorTests extends AbstractVectorTest {
}
assertReductionArraysEquals(r, ra, a,
Double256VectorTests::ADDReduce, Double256VectorTests::ADDReduceAll);
Double256VectorTests::ADDReduce, Double256VectorTests::ADDReduceAll, RELATIVE_ROUNDING_ERROR);
}
static double ADDReduceMasked(double[] a, int idx, boolean[] mask) {
@ -2214,7 +2237,7 @@ public class Double256VectorTests extends AbstractVectorTest {
}
assertReductionArraysEqualsMasked(r, ra, a, mask,
Double256VectorTests::ADDReduceMasked, Double256VectorTests::ADDReduceAllMasked);
Double256VectorTests::ADDReduceMasked, Double256VectorTests::ADDReduceAllMasked, RELATIVE_ROUNDING_ERROR);
}
static double MULReduce(double[] a, int idx) {
@ -2257,7 +2280,7 @@ public class Double256VectorTests extends AbstractVectorTest {
}
assertReductionArraysEquals(r, ra, a,
Double256VectorTests::MULReduce, Double256VectorTests::MULReduceAll);
Double256VectorTests::MULReduce, Double256VectorTests::MULReduceAll, RELATIVE_ROUNDING_ERROR);
}
static double MULReduceMasked(double[] a, int idx, boolean[] mask) {
@ -2303,7 +2326,7 @@ public class Double256VectorTests extends AbstractVectorTest {
}
assertReductionArraysEqualsMasked(r, ra, a, mask,
Double256VectorTests::MULReduceMasked, Double256VectorTests::MULReduceAllMasked);
Double256VectorTests::MULReduceMasked, Double256VectorTests::MULReduceAllMasked, RELATIVE_ROUNDING_ERROR);
}
static double MINReduce(double[] a, int idx) {

View File

@ -60,6 +60,8 @@ public class Double512VectorTests extends AbstractVectorTest {
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
// for floating point reduction ops that may introduce rounding errors
private static final double RELATIVE_ROUNDING_ERROR = (double)0.000001;
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512);
@ -119,15 +121,21 @@ public class Double512VectorTests extends AbstractVectorTest {
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);
}
}
@ -141,15 +149,22 @@ public class Double512VectorTests extends AbstractVectorTest {
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));
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError));
for (; i < a.length; i += SPECIES.length()) {
Assert.assertEquals(r[i], f.apply(a, i, mask));
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] *
relativeError));
}
} catch (AssertionError e) {
Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] * relativeError), "at index #" + i);
}
}
@ -1078,6 +1093,14 @@ public class Double512VectorTests extends AbstractVectorTest {
return fill(s * BUFFER_REPS,
i -> (((double)(i + 1) == 0) ? 1 : (double)(i + 1)));
}),
withToString("double[0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> (double)0.01 + ((double)i / (i + 1)));
}),
withToString("double[i -> i % 17 == 0 ? cornerCaseValue(i) : 0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> i % 17 == 0 ? cornerCaseValue(i) : (double)0.01 + ((double)i / (i + 1)));
}),
withToString("double[cornerCaseValue(i)]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> cornerCaseValue(i));
@ -2168,7 +2191,7 @@ public class Double512VectorTests extends AbstractVectorTest {
}
assertReductionArraysEquals(r, ra, a,
Double512VectorTests::ADDReduce, Double512VectorTests::ADDReduceAll);
Double512VectorTests::ADDReduce, Double512VectorTests::ADDReduceAll, RELATIVE_ROUNDING_ERROR);
}
static double ADDReduceMasked(double[] a, int idx, boolean[] mask) {
@ -2214,7 +2237,7 @@ public class Double512VectorTests extends AbstractVectorTest {
}
assertReductionArraysEqualsMasked(r, ra, a, mask,
Double512VectorTests::ADDReduceMasked, Double512VectorTests::ADDReduceAllMasked);
Double512VectorTests::ADDReduceMasked, Double512VectorTests::ADDReduceAllMasked, RELATIVE_ROUNDING_ERROR);
}
static double MULReduce(double[] a, int idx) {
@ -2257,7 +2280,7 @@ public class Double512VectorTests extends AbstractVectorTest {
}
assertReductionArraysEquals(r, ra, a,
Double512VectorTests::MULReduce, Double512VectorTests::MULReduceAll);
Double512VectorTests::MULReduce, Double512VectorTests::MULReduceAll, RELATIVE_ROUNDING_ERROR);
}
static double MULReduceMasked(double[] a, int idx, boolean[] mask) {
@ -2303,7 +2326,7 @@ public class Double512VectorTests extends AbstractVectorTest {
}
assertReductionArraysEqualsMasked(r, ra, a, mask,
Double512VectorTests::MULReduceMasked, Double512VectorTests::MULReduceAllMasked);
Double512VectorTests::MULReduceMasked, Double512VectorTests::MULReduceAllMasked, RELATIVE_ROUNDING_ERROR);
}
static double MINReduce(double[] a, int idx) {

View File

@ -60,6 +60,8 @@ public class Double64VectorTests extends AbstractVectorTest {
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
// for floating point reduction ops that may introduce rounding errors
private static final double RELATIVE_ROUNDING_ERROR = (double)0.000001;
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64);
@ -119,15 +121,21 @@ public class Double64VectorTests extends AbstractVectorTest {
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);
}
}
@ -141,15 +149,22 @@ public class Double64VectorTests extends AbstractVectorTest {
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));
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError));
for (; i < a.length; i += SPECIES.length()) {
Assert.assertEquals(r[i], f.apply(a, i, mask));
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] *
relativeError));
}
} catch (AssertionError e) {
Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] * relativeError), "at index #" + i);
}
}
@ -1078,6 +1093,14 @@ public class Double64VectorTests extends AbstractVectorTest {
return fill(s * BUFFER_REPS,
i -> (((double)(i + 1) == 0) ? 1 : (double)(i + 1)));
}),
withToString("double[0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> (double)0.01 + ((double)i / (i + 1)));
}),
withToString("double[i -> i % 17 == 0 ? cornerCaseValue(i) : 0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> i % 17 == 0 ? cornerCaseValue(i) : (double)0.01 + ((double)i / (i + 1)));
}),
withToString("double[cornerCaseValue(i)]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> cornerCaseValue(i));
@ -2168,7 +2191,7 @@ public class Double64VectorTests extends AbstractVectorTest {
}
assertReductionArraysEquals(r, ra, a,
Double64VectorTests::ADDReduce, Double64VectorTests::ADDReduceAll);
Double64VectorTests::ADDReduce, Double64VectorTests::ADDReduceAll, RELATIVE_ROUNDING_ERROR);
}
static double ADDReduceMasked(double[] a, int idx, boolean[] mask) {
@ -2214,7 +2237,7 @@ public class Double64VectorTests extends AbstractVectorTest {
}
assertReductionArraysEqualsMasked(r, ra, a, mask,
Double64VectorTests::ADDReduceMasked, Double64VectorTests::ADDReduceAllMasked);
Double64VectorTests::ADDReduceMasked, Double64VectorTests::ADDReduceAllMasked, RELATIVE_ROUNDING_ERROR);
}
static double MULReduce(double[] a, int idx) {
@ -2257,7 +2280,7 @@ public class Double64VectorTests extends AbstractVectorTest {
}
assertReductionArraysEquals(r, ra, a,
Double64VectorTests::MULReduce, Double64VectorTests::MULReduceAll);
Double64VectorTests::MULReduce, Double64VectorTests::MULReduceAll, RELATIVE_ROUNDING_ERROR);
}
static double MULReduceMasked(double[] a, int idx, boolean[] mask) {
@ -2303,7 +2326,7 @@ public class Double64VectorTests extends AbstractVectorTest {
}
assertReductionArraysEqualsMasked(r, ra, a, mask,
Double64VectorTests::MULReduceMasked, Double64VectorTests::MULReduceAllMasked);
Double64VectorTests::MULReduceMasked, Double64VectorTests::MULReduceAllMasked, RELATIVE_ROUNDING_ERROR);
}
static double MINReduce(double[] a, int idx) {

View File

@ -65,6 +65,8 @@ public class DoubleMaxVectorTests extends AbstractVectorTest {
private static final int Max = 256; // juts so we can do N/Max
// for floating point reduction ops that may introduce rounding errors
private static final double RELATIVE_ROUNDING_ERROR = (double)0.000001;
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max);
@ -124,15 +126,21 @@ public class DoubleMaxVectorTests extends AbstractVectorTest {
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);
}
}
@ -146,15 +154,22 @@ public class DoubleMaxVectorTests extends AbstractVectorTest {
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));
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError));
for (; i < a.length; i += SPECIES.length()) {
Assert.assertEquals(r[i], f.apply(a, i, mask));
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] *
relativeError));
}
} catch (AssertionError e) {
Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] * relativeError), "at index #" + i);
}
}
@ -1083,6 +1098,14 @@ public class DoubleMaxVectorTests extends AbstractVectorTest {
return fill(s * BUFFER_REPS,
i -> (((double)(i + 1) == 0) ? 1 : (double)(i + 1)));
}),
withToString("double[0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> (double)0.01 + ((double)i / (i + 1)));
}),
withToString("double[i -> i % 17 == 0 ? cornerCaseValue(i) : 0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> i % 17 == 0 ? cornerCaseValue(i) : (double)0.01 + ((double)i / (i + 1)));
}),
withToString("double[cornerCaseValue(i)]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> cornerCaseValue(i));
@ -2173,7 +2196,7 @@ public class DoubleMaxVectorTests extends AbstractVectorTest {
}
assertReductionArraysEquals(r, ra, a,
DoubleMaxVectorTests::ADDReduce, DoubleMaxVectorTests::ADDReduceAll);
DoubleMaxVectorTests::ADDReduce, DoubleMaxVectorTests::ADDReduceAll, RELATIVE_ROUNDING_ERROR);
}
static double ADDReduceMasked(double[] a, int idx, boolean[] mask) {
@ -2219,7 +2242,7 @@ public class DoubleMaxVectorTests extends AbstractVectorTest {
}
assertReductionArraysEqualsMasked(r, ra, a, mask,
DoubleMaxVectorTests::ADDReduceMasked, DoubleMaxVectorTests::ADDReduceAllMasked);
DoubleMaxVectorTests::ADDReduceMasked, DoubleMaxVectorTests::ADDReduceAllMasked, RELATIVE_ROUNDING_ERROR);
}
static double MULReduce(double[] a, int idx) {
@ -2262,7 +2285,7 @@ public class DoubleMaxVectorTests extends AbstractVectorTest {
}
assertReductionArraysEquals(r, ra, a,
DoubleMaxVectorTests::MULReduce, DoubleMaxVectorTests::MULReduceAll);
DoubleMaxVectorTests::MULReduce, DoubleMaxVectorTests::MULReduceAll, RELATIVE_ROUNDING_ERROR);
}
static double MULReduceMasked(double[] a, int idx, boolean[] mask) {
@ -2308,7 +2331,7 @@ public class DoubleMaxVectorTests extends AbstractVectorTest {
}
assertReductionArraysEqualsMasked(r, ra, a, mask,
DoubleMaxVectorTests::MULReduceMasked, DoubleMaxVectorTests::MULReduceAllMasked);
DoubleMaxVectorTests::MULReduceMasked, DoubleMaxVectorTests::MULReduceAllMasked, RELATIVE_ROUNDING_ERROR);
}
static double MINReduce(double[] a, int idx) {

View File

@ -60,6 +60,8 @@ public class Float128VectorTests extends AbstractVectorTest {
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
// for floating point reduction ops that may introduce rounding errors
private static final float RELATIVE_ROUNDING_ERROR = (float)0.000001;
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128);
@ -119,15 +121,21 @@ public class Float128VectorTests extends AbstractVectorTest {
static void assertReductionArraysEquals(float[] r, float rc, float[] a,
FReductionOp f, FReductionAllOp fa) {
assertReductionArraysEquals(r, rc, a, f, fa, (float)0.0);
}
static void assertReductionArraysEquals(float[] r, float rc, float[] a,
FReductionOp f, FReductionAllOp fa,
float 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);
}
}
@ -141,15 +149,22 @@ public class Float128VectorTests extends AbstractVectorTest {
static void assertReductionArraysEqualsMasked(float[] r, float rc, float[] a, boolean[] mask,
FReductionMaskedOp f, FReductionAllMaskedOp fa) {
assertReductionArraysEqualsMasked(r, rc, a, mask, f, fa, (float)0.0);
}
static void assertReductionArraysEqualsMasked(float[] r, float rc, float[] a, boolean[] mask,
FReductionMaskedOp f, FReductionAllMaskedOp fa,
float relativeError) {
int i = 0;
try {
Assert.assertEquals(rc, fa.apply(a, mask));
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError));
for (; i < a.length; i += SPECIES.length()) {
Assert.assertEquals(r[i], f.apply(a, i, mask));
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] *
relativeError));
}
} catch (AssertionError e) {
Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] * relativeError), "at index #" + i);
}
}
@ -1089,6 +1104,14 @@ public class Float128VectorTests extends AbstractVectorTest {
return fill(s * BUFFER_REPS,
i -> (((float)(i + 1) == 0) ? 1 : (float)(i + 1)));
}),
withToString("float[0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> (float)0.01 + ((float)i / (i + 1)));
}),
withToString("float[i -> i % 17 == 0 ? cornerCaseValue(i) : 0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> i % 17 == 0 ? cornerCaseValue(i) : (float)0.01 + ((float)i / (i + 1)));
}),
withToString("float[cornerCaseValue(i)]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> cornerCaseValue(i));
@ -2179,7 +2202,7 @@ public class Float128VectorTests extends AbstractVectorTest {
}
assertReductionArraysEquals(r, ra, a,
Float128VectorTests::ADDReduce, Float128VectorTests::ADDReduceAll);
Float128VectorTests::ADDReduce, Float128VectorTests::ADDReduceAll, RELATIVE_ROUNDING_ERROR);
}
static float ADDReduceMasked(float[] a, int idx, boolean[] mask) {
@ -2225,7 +2248,7 @@ public class Float128VectorTests extends AbstractVectorTest {
}
assertReductionArraysEqualsMasked(r, ra, a, mask,
Float128VectorTests::ADDReduceMasked, Float128VectorTests::ADDReduceAllMasked);
Float128VectorTests::ADDReduceMasked, Float128VectorTests::ADDReduceAllMasked, RELATIVE_ROUNDING_ERROR);
}
static float MULReduce(float[] a, int idx) {
@ -2268,7 +2291,7 @@ public class Float128VectorTests extends AbstractVectorTest {
}
assertReductionArraysEquals(r, ra, a,
Float128VectorTests::MULReduce, Float128VectorTests::MULReduceAll);
Float128VectorTests::MULReduce, Float128VectorTests::MULReduceAll, RELATIVE_ROUNDING_ERROR);
}
static float MULReduceMasked(float[] a, int idx, boolean[] mask) {
@ -2314,7 +2337,7 @@ public class Float128VectorTests extends AbstractVectorTest {
}
assertReductionArraysEqualsMasked(r, ra, a, mask,
Float128VectorTests::MULReduceMasked, Float128VectorTests::MULReduceAllMasked);
Float128VectorTests::MULReduceMasked, Float128VectorTests::MULReduceAllMasked, RELATIVE_ROUNDING_ERROR);
}
static float MINReduce(float[] a, int idx) {

View File

@ -60,6 +60,8 @@ public class Float256VectorTests extends AbstractVectorTest {
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
// for floating point reduction ops that may introduce rounding errors
private static final float RELATIVE_ROUNDING_ERROR = (float)0.000001;
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256);
@ -119,15 +121,21 @@ public class Float256VectorTests extends AbstractVectorTest {
static void assertReductionArraysEquals(float[] r, float rc, float[] a,
FReductionOp f, FReductionAllOp fa) {
assertReductionArraysEquals(r, rc, a, f, fa, (float)0.0);
}
static void assertReductionArraysEquals(float[] r, float rc, float[] a,
FReductionOp f, FReductionAllOp fa,
float 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);
}
}
@ -141,15 +149,22 @@ public class Float256VectorTests extends AbstractVectorTest {
static void assertReductionArraysEqualsMasked(float[] r, float rc, float[] a, boolean[] mask,
FReductionMaskedOp f, FReductionAllMaskedOp fa) {
assertReductionArraysEqualsMasked(r, rc, a, mask, f, fa, (float)0.0);
}
static void assertReductionArraysEqualsMasked(float[] r, float rc, float[] a, boolean[] mask,
FReductionMaskedOp f, FReductionAllMaskedOp fa,
float relativeError) {
int i = 0;
try {
Assert.assertEquals(rc, fa.apply(a, mask));
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError));
for (; i < a.length; i += SPECIES.length()) {
Assert.assertEquals(r[i], f.apply(a, i, mask));
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] *
relativeError));
}
} catch (AssertionError e) {
Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] * relativeError), "at index #" + i);
}
}
@ -1089,6 +1104,14 @@ public class Float256VectorTests extends AbstractVectorTest {
return fill(s * BUFFER_REPS,
i -> (((float)(i + 1) == 0) ? 1 : (float)(i + 1)));
}),
withToString("float[0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> (float)0.01 + ((float)i / (i + 1)));
}),
withToString("float[i -> i % 17 == 0 ? cornerCaseValue(i) : 0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> i % 17 == 0 ? cornerCaseValue(i) : (float)0.01 + ((float)i / (i + 1)));
}),
withToString("float[cornerCaseValue(i)]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> cornerCaseValue(i));
@ -2179,7 +2202,7 @@ public class Float256VectorTests extends AbstractVectorTest {
}
assertReductionArraysEquals(r, ra, a,
Float256VectorTests::ADDReduce, Float256VectorTests::ADDReduceAll);
Float256VectorTests::ADDReduce, Float256VectorTests::ADDReduceAll, RELATIVE_ROUNDING_ERROR);
}
static float ADDReduceMasked(float[] a, int idx, boolean[] mask) {
@ -2225,7 +2248,7 @@ public class Float256VectorTests extends AbstractVectorTest {
}
assertReductionArraysEqualsMasked(r, ra, a, mask,
Float256VectorTests::ADDReduceMasked, Float256VectorTests::ADDReduceAllMasked);
Float256VectorTests::ADDReduceMasked, Float256VectorTests::ADDReduceAllMasked, RELATIVE_ROUNDING_ERROR);
}
static float MULReduce(float[] a, int idx) {
@ -2268,7 +2291,7 @@ public class Float256VectorTests extends AbstractVectorTest {
}
assertReductionArraysEquals(r, ra, a,
Float256VectorTests::MULReduce, Float256VectorTests::MULReduceAll);
Float256VectorTests::MULReduce, Float256VectorTests::MULReduceAll, RELATIVE_ROUNDING_ERROR);
}
static float MULReduceMasked(float[] a, int idx, boolean[] mask) {
@ -2314,7 +2337,7 @@ public class Float256VectorTests extends AbstractVectorTest {
}
assertReductionArraysEqualsMasked(r, ra, a, mask,
Float256VectorTests::MULReduceMasked, Float256VectorTests::MULReduceAllMasked);
Float256VectorTests::MULReduceMasked, Float256VectorTests::MULReduceAllMasked, RELATIVE_ROUNDING_ERROR);
}
static float MINReduce(float[] a, int idx) {

View File

@ -60,6 +60,8 @@ public class Float512VectorTests extends AbstractVectorTest {
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
// for floating point reduction ops that may introduce rounding errors
private static final float RELATIVE_ROUNDING_ERROR = (float)0.000001;
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512);
@ -119,15 +121,21 @@ public class Float512VectorTests extends AbstractVectorTest {
static void assertReductionArraysEquals(float[] r, float rc, float[] a,
FReductionOp f, FReductionAllOp fa) {
assertReductionArraysEquals(r, rc, a, f, fa, (float)0.0);
}
static void assertReductionArraysEquals(float[] r, float rc, float[] a,
FReductionOp f, FReductionAllOp fa,
float 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);
}
}
@ -141,15 +149,22 @@ public class Float512VectorTests extends AbstractVectorTest {
static void assertReductionArraysEqualsMasked(float[] r, float rc, float[] a, boolean[] mask,
FReductionMaskedOp f, FReductionAllMaskedOp fa) {
assertReductionArraysEqualsMasked(r, rc, a, mask, f, fa, (float)0.0);
}
static void assertReductionArraysEqualsMasked(float[] r, float rc, float[] a, boolean[] mask,
FReductionMaskedOp f, FReductionAllMaskedOp fa,
float relativeError) {
int i = 0;
try {
Assert.assertEquals(rc, fa.apply(a, mask));
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError));
for (; i < a.length; i += SPECIES.length()) {
Assert.assertEquals(r[i], f.apply(a, i, mask));
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] *
relativeError));
}
} catch (AssertionError e) {
Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] * relativeError), "at index #" + i);
}
}
@ -1089,6 +1104,14 @@ public class Float512VectorTests extends AbstractVectorTest {
return fill(s * BUFFER_REPS,
i -> (((float)(i + 1) == 0) ? 1 : (float)(i + 1)));
}),
withToString("float[0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> (float)0.01 + ((float)i / (i + 1)));
}),
withToString("float[i -> i % 17 == 0 ? cornerCaseValue(i) : 0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> i % 17 == 0 ? cornerCaseValue(i) : (float)0.01 + ((float)i / (i + 1)));
}),
withToString("float[cornerCaseValue(i)]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> cornerCaseValue(i));
@ -2179,7 +2202,7 @@ public class Float512VectorTests extends AbstractVectorTest {
}
assertReductionArraysEquals(r, ra, a,
Float512VectorTests::ADDReduce, Float512VectorTests::ADDReduceAll);
Float512VectorTests::ADDReduce, Float512VectorTests::ADDReduceAll, RELATIVE_ROUNDING_ERROR);
}
static float ADDReduceMasked(float[] a, int idx, boolean[] mask) {
@ -2225,7 +2248,7 @@ public class Float512VectorTests extends AbstractVectorTest {
}
assertReductionArraysEqualsMasked(r, ra, a, mask,
Float512VectorTests::ADDReduceMasked, Float512VectorTests::ADDReduceAllMasked);
Float512VectorTests::ADDReduceMasked, Float512VectorTests::ADDReduceAllMasked, RELATIVE_ROUNDING_ERROR);
}
static float MULReduce(float[] a, int idx) {
@ -2268,7 +2291,7 @@ public class Float512VectorTests extends AbstractVectorTest {
}
assertReductionArraysEquals(r, ra, a,
Float512VectorTests::MULReduce, Float512VectorTests::MULReduceAll);
Float512VectorTests::MULReduce, Float512VectorTests::MULReduceAll, RELATIVE_ROUNDING_ERROR);
}
static float MULReduceMasked(float[] a, int idx, boolean[] mask) {
@ -2314,7 +2337,7 @@ public class Float512VectorTests extends AbstractVectorTest {
}
assertReductionArraysEqualsMasked(r, ra, a, mask,
Float512VectorTests::MULReduceMasked, Float512VectorTests::MULReduceAllMasked);
Float512VectorTests::MULReduceMasked, Float512VectorTests::MULReduceAllMasked, RELATIVE_ROUNDING_ERROR);
}
static float MINReduce(float[] a, int idx) {

View File

@ -60,6 +60,8 @@ public class Float64VectorTests extends AbstractVectorTest {
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
// for floating point reduction ops that may introduce rounding errors
private static final float RELATIVE_ROUNDING_ERROR = (float)0.000001;
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 64);
@ -119,15 +121,21 @@ public class Float64VectorTests extends AbstractVectorTest {
static void assertReductionArraysEquals(float[] r, float rc, float[] a,
FReductionOp f, FReductionAllOp fa) {
assertReductionArraysEquals(r, rc, a, f, fa, (float)0.0);
}
static void assertReductionArraysEquals(float[] r, float rc, float[] a,
FReductionOp f, FReductionAllOp fa,
float 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);
}
}
@ -141,15 +149,22 @@ public class Float64VectorTests extends AbstractVectorTest {
static void assertReductionArraysEqualsMasked(float[] r, float rc, float[] a, boolean[] mask,
FReductionMaskedOp f, FReductionAllMaskedOp fa) {
assertReductionArraysEqualsMasked(r, rc, a, mask, f, fa, (float)0.0);
}
static void assertReductionArraysEqualsMasked(float[] r, float rc, float[] a, boolean[] mask,
FReductionMaskedOp f, FReductionAllMaskedOp fa,
float relativeError) {
int i = 0;
try {
Assert.assertEquals(rc, fa.apply(a, mask));
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError));
for (; i < a.length; i += SPECIES.length()) {
Assert.assertEquals(r[i], f.apply(a, i, mask));
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] *
relativeError));
}
} catch (AssertionError e) {
Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] * relativeError), "at index #" + i);
}
}
@ -1089,6 +1104,14 @@ public class Float64VectorTests extends AbstractVectorTest {
return fill(s * BUFFER_REPS,
i -> (((float)(i + 1) == 0) ? 1 : (float)(i + 1)));
}),
withToString("float[0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> (float)0.01 + ((float)i / (i + 1)));
}),
withToString("float[i -> i % 17 == 0 ? cornerCaseValue(i) : 0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> i % 17 == 0 ? cornerCaseValue(i) : (float)0.01 + ((float)i / (i + 1)));
}),
withToString("float[cornerCaseValue(i)]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> cornerCaseValue(i));
@ -2179,7 +2202,7 @@ public class Float64VectorTests extends AbstractVectorTest {
}
assertReductionArraysEquals(r, ra, a,
Float64VectorTests::ADDReduce, Float64VectorTests::ADDReduceAll);
Float64VectorTests::ADDReduce, Float64VectorTests::ADDReduceAll, RELATIVE_ROUNDING_ERROR);
}
static float ADDReduceMasked(float[] a, int idx, boolean[] mask) {
@ -2225,7 +2248,7 @@ public class Float64VectorTests extends AbstractVectorTest {
}
assertReductionArraysEqualsMasked(r, ra, a, mask,
Float64VectorTests::ADDReduceMasked, Float64VectorTests::ADDReduceAllMasked);
Float64VectorTests::ADDReduceMasked, Float64VectorTests::ADDReduceAllMasked, RELATIVE_ROUNDING_ERROR);
}
static float MULReduce(float[] a, int idx) {
@ -2268,7 +2291,7 @@ public class Float64VectorTests extends AbstractVectorTest {
}
assertReductionArraysEquals(r, ra, a,
Float64VectorTests::MULReduce, Float64VectorTests::MULReduceAll);
Float64VectorTests::MULReduce, Float64VectorTests::MULReduceAll, RELATIVE_ROUNDING_ERROR);
}
static float MULReduceMasked(float[] a, int idx, boolean[] mask) {
@ -2314,7 +2337,7 @@ public class Float64VectorTests extends AbstractVectorTest {
}
assertReductionArraysEqualsMasked(r, ra, a, mask,
Float64VectorTests::MULReduceMasked, Float64VectorTests::MULReduceAllMasked);
Float64VectorTests::MULReduceMasked, Float64VectorTests::MULReduceAllMasked, RELATIVE_ROUNDING_ERROR);
}
static float MINReduce(float[] a, int idx) {

View File

@ -65,6 +65,8 @@ public class FloatMaxVectorTests extends AbstractVectorTest {
private static final int Max = 256; // juts so we can do N/Max
// for floating point reduction ops that may introduce rounding errors
private static final float RELATIVE_ROUNDING_ERROR = (float)0.000001;
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max);
@ -124,15 +126,21 @@ public class FloatMaxVectorTests extends AbstractVectorTest {
static void assertReductionArraysEquals(float[] r, float rc, float[] a,
FReductionOp f, FReductionAllOp fa) {
assertReductionArraysEquals(r, rc, a, f, fa, (float)0.0);
}
static void assertReductionArraysEquals(float[] r, float rc, float[] a,
FReductionOp f, FReductionAllOp fa,
float 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);
}
}
@ -146,15 +154,22 @@ public class FloatMaxVectorTests extends AbstractVectorTest {
static void assertReductionArraysEqualsMasked(float[] r, float rc, float[] a, boolean[] mask,
FReductionMaskedOp f, FReductionAllMaskedOp fa) {
assertReductionArraysEqualsMasked(r, rc, a, mask, f, fa, (float)0.0);
}
static void assertReductionArraysEqualsMasked(float[] r, float rc, float[] a, boolean[] mask,
FReductionMaskedOp f, FReductionAllMaskedOp fa,
float relativeError) {
int i = 0;
try {
Assert.assertEquals(rc, fa.apply(a, mask));
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError));
for (; i < a.length; i += SPECIES.length()) {
Assert.assertEquals(r[i], f.apply(a, i, mask));
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] *
relativeError));
}
} catch (AssertionError e) {
Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] * relativeError), "at index #" + i);
}
}
@ -1094,6 +1109,14 @@ public class FloatMaxVectorTests extends AbstractVectorTest {
return fill(s * BUFFER_REPS,
i -> (((float)(i + 1) == 0) ? 1 : (float)(i + 1)));
}),
withToString("float[0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> (float)0.01 + ((float)i / (i + 1)));
}),
withToString("float[i -> i % 17 == 0 ? cornerCaseValue(i) : 0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> i % 17 == 0 ? cornerCaseValue(i) : (float)0.01 + ((float)i / (i + 1)));
}),
withToString("float[cornerCaseValue(i)]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> cornerCaseValue(i));
@ -2184,7 +2207,7 @@ public class FloatMaxVectorTests extends AbstractVectorTest {
}
assertReductionArraysEquals(r, ra, a,
FloatMaxVectorTests::ADDReduce, FloatMaxVectorTests::ADDReduceAll);
FloatMaxVectorTests::ADDReduce, FloatMaxVectorTests::ADDReduceAll, RELATIVE_ROUNDING_ERROR);
}
static float ADDReduceMasked(float[] a, int idx, boolean[] mask) {
@ -2230,7 +2253,7 @@ public class FloatMaxVectorTests extends AbstractVectorTest {
}
assertReductionArraysEqualsMasked(r, ra, a, mask,
FloatMaxVectorTests::ADDReduceMasked, FloatMaxVectorTests::ADDReduceAllMasked);
FloatMaxVectorTests::ADDReduceMasked, FloatMaxVectorTests::ADDReduceAllMasked, RELATIVE_ROUNDING_ERROR);
}
static float MULReduce(float[] a, int idx) {
@ -2273,7 +2296,7 @@ public class FloatMaxVectorTests extends AbstractVectorTest {
}
assertReductionArraysEquals(r, ra, a,
FloatMaxVectorTests::MULReduce, FloatMaxVectorTests::MULReduceAll);
FloatMaxVectorTests::MULReduce, FloatMaxVectorTests::MULReduceAll, RELATIVE_ROUNDING_ERROR);
}
static float MULReduceMasked(float[] a, int idx, boolean[] mask) {
@ -2319,7 +2342,7 @@ public class FloatMaxVectorTests extends AbstractVectorTest {
}
assertReductionArraysEqualsMasked(r, ra, a, mask,
FloatMaxVectorTests::MULReduceMasked, FloatMaxVectorTests::MULReduceAllMasked);
FloatMaxVectorTests::MULReduceMasked, FloatMaxVectorTests::MULReduceAllMasked, RELATIVE_ROUNDING_ERROR);
}
static float MINReduce(float[] a, int idx) {

View File

@ -3,5 +3,9 @@
static void [[TEST]]Reduce$vectorteststype$Masked(IntFunction<$type$[]> fa, IntFunction<boolean[]> fm) {
[[KERNEL]]
assertReductionArraysEqualsMasked(r, ra, a, mask,
#if[FP]
$vectorteststype$::[[TEST]]ReduceMasked, $vectorteststype$::[[TEST]]ReduceAllMasked, RELATIVE_ROUNDING_ERROR);
#else[FP]
$vectorteststype$::[[TEST]]ReduceMasked, $vectorteststype$::[[TEST]]ReduceAllMasked);
#end[FP]
}

View File

@ -3,5 +3,9 @@
static void [[TEST]]Reduce$vectorteststype$(IntFunction<$type$[]> fa) {
[[KERNEL]]
assertReductionArraysEquals(r, ra, a,
#if[FP]
$vectorteststype$::[[TEST]]Reduce, $vectorteststype$::[[TEST]]ReduceAll, RELATIVE_ROUNDING_ERROR);
#else[FP]
$vectorteststype$::[[TEST]]Reduce, $vectorteststype$::[[TEST]]ReduceAll);
#end[FP]
}

View File

@ -92,6 +92,10 @@ public class $vectorteststype$ extends AbstractVectorTest {
#if[BITWISE]
private static final $type$ CONST_SHIFT = $Boxtype$.SIZE / 2;
#end[BITWISE]
#if[FP]
// for floating point reduction ops that may introduce rounding errors
private static final $type$ RELATIVE_ROUNDING_ERROR = ($type$)0.000001;
#end[FP]
static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / $bits$);
@ -151,6 +155,9 @@ public class $vectorteststype$ extends AbstractVectorTest {
static void assertReductionArraysEquals($type$[] r, $type$ rc, $type$[] a,
FReductionOp f, FReductionAllOp fa) {
#if[FP]
assertReductionArraysEquals(r, rc, a, f, fa, ($type$)0.0);
#else[FP]
int i = 0;
try {
Assert.assertEquals(rc, fa.apply(a));
@ -161,7 +168,25 @@ public class $vectorteststype$ extends AbstractVectorTest {
Assert.assertEquals(rc, fa.apply(a), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
}
#end[FP]
}
#if[FP]
static void assertReductionArraysEquals($type$[] r, $type$ rc, $type$[] a,
FReductionOp f, FReductionAllOp fa,
$type$ relativeError) {
int i = 0;
try {
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), Math.abs(r[i] * relativeError));
}
} catch (AssertionError e) {
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);
}
}
#end[FP]
interface FReductionMaskedOp {
$type$ apply($type$[] a, int idx, boolean[] mask);
@ -173,6 +198,9 @@ public class $vectorteststype$ extends AbstractVectorTest {
static void assertReductionArraysEqualsMasked($type$[] r, $type$ rc, $type$[] a, boolean[] mask,
FReductionMaskedOp f, FReductionAllMaskedOp fa) {
#if[FP]
assertReductionArraysEqualsMasked(r, rc, a, mask, f, fa, ($type$)0.0);
#else[FP]
int i = 0;
try {
Assert.assertEquals(rc, fa.apply(a, mask));
@ -183,7 +211,26 @@ public class $vectorteststype$ extends AbstractVectorTest {
Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
}
#end[FP]
}
#if[FP]
static void assertReductionArraysEqualsMasked($type$[] r, $type$ rc, $type$[] a, boolean[] mask,
FReductionMaskedOp f, FReductionAllMaskedOp fa,
$type$ relativeError) {
int i = 0;
try {
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError));
for (; i < a.length; i += SPECIES.length()) {
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] *
relativeError));
}
} catch (AssertionError e) {
Assert.assertEquals(rc, fa.apply(a, mask), Math.abs(rc * relativeError), "Final result is incorrect!");
Assert.assertEquals(r[i], f.apply(a, i, mask), Math.abs(r[i] * relativeError), "at index #" + i);
}
}
#end[FP]
#if[!Long]
interface FReductionOpLong {
@ -1147,6 +1194,16 @@ public class $vectorteststype$ extends AbstractVectorTest {
return fill(s * BUFFER_REPS,
i -> ((($type$)(i + 1) == 0) ? 1 : ($type$)(i + 1)));
}),
#if[FP]
withToString("$type$[0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> ($type$)0.01 + (($type$)i / (i + 1)));
}),
withToString("$type$[i -> i % 17 == 0 ? cornerCaseValue(i) : 0.01 + (i / (i + 1))]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> i % 17 == 0 ? cornerCaseValue(i) : ($type$)0.01 + (($type$)i / (i + 1)));
}),
#end[FP]
withToString("$type$[cornerCaseValue(i)]", (int s) -> {
return fill(s * BUFFER_REPS,
i -> cornerCaseValue(i));