Skip to content

Commit 47106d6

Browse files
benwtrentkderusso
authored andcommitted
Address when scores can be very large in osq score test (elastic#129592)
Using a static `diff` or epsilon just doesn't work for this test as the scores can be very large, but relatively close. Maybe there is a simpler way, but my mind wasn't wanting to "math" very much. For example, the seed that this previously failed on had scores like `1.726524E9` and `1.7265239E9`, which, given their size, are really close together (within 128). But a static epsilon wouldn't capture that. closes: elastic#128485
1 parent 0729937 commit 47106d6

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

libs/simdvec/src/test/java/org/elasticsearch/simdvec/internal/vectorization/ES91OSQVectorScorerTests.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,21 @@ public void testScore() throws Exception {
125125
scores2
126126
);
127127
for (int j = 0; j < ES91OSQVectorsScorer.BULK_SIZE; j++) {
128-
if (scores1[j] > (maxDims * Short.MAX_VALUE)) {
129-
int diff = (int) (scores1[j] - scores2[j]);
130-
assertThat("defaultScores: " + scores1[j] + " bulkScores: " + scores2[j], Math.abs(diff), lessThan(65));
131-
} else if (scores1[j] > (maxDims * Byte.MAX_VALUE)) {
132-
int diff = (int) (scores1[j] - scores2[j]);
133-
assertThat("defaultScores: " + scores1[j] + " bulkScores: " + scores2[j], Math.abs(diff), lessThan(9));
128+
if (scores1[j] == scores2[j]) {
129+
continue;
130+
}
131+
if (scores1[j] > (maxDims * Byte.MAX_VALUE)) {
132+
float diff = Math.abs(scores1[j] - scores2[j]);
133+
assertThat(
134+
"defaultScores: " + scores1[j] + " bulkScores: " + scores2[j],
135+
diff / scores1[j],
136+
lessThan(1e-5f)
137+
);
138+
assertThat(
139+
"defaultScores: " + scores1[j] + " bulkScores: " + scores2[j],
140+
diff / scores2[j],
141+
lessThan(1e-5f)
142+
);
134143
} else {
135144
assertEquals(scores1[j], scores2[j], 1e-2f);
136145
}

0 commit comments

Comments
 (0)