Skip to content

Fix Int7uScorerBenchmarkTests for running on Java 21 #130731

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,13 @@ public void setup() throws IOException {
for (int i = 0; i < dims; i++) {
queryVec[i] = ThreadLocalRandom.current().nextFloat();
}
luceneDotScorerQuery = luceneScorer(values, VectorSimilarityFunction.DOT_PRODUCT, queryVec);
nativeDotScorerQuery = factory.getInt7SQVectorScorer(VectorSimilarityFunction.DOT_PRODUCT, values, queryVec).get();
luceneSqrScorerQuery = luceneScorer(values, VectorSimilarityFunction.EUCLIDEAN, queryVec);
nativeSqrScorerQuery = factory.getInt7SQVectorScorer(VectorSimilarityFunction.EUCLIDEAN, values, queryVec).get();

if (Runtime.version().feature() >= 22) {
luceneDotScorerQuery = luceneScorer(values, VectorSimilarityFunction.DOT_PRODUCT, queryVec);
nativeDotScorerQuery = factory.getInt7SQVectorScorer(VectorSimilarityFunction.DOT_PRODUCT, values, queryVec).get();
luceneSqrScorerQuery = luceneScorer(values, VectorSimilarityFunction.EUCLIDEAN, queryVec);
nativeSqrScorerQuery = factory.getInt7SQVectorScorer(VectorSimilarityFunction.EUCLIDEAN, values, queryVec).get();
}
Comment on lines -137 to +143
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to do NPE checks in the benchmark methods now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this could happen. In reality we'd be running with >= Java 22 as you cannot run that part of the bench without it. I mostly just want to make the test happy. Lemme see if there is a cleaner way to restructure things.

}

@TearDown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public static void skipWindows() {
assumeFalse("doesn't work on windows yet", Constants.WINDOWS);
}

static boolean supportsHeapSegments() {
return Runtime.version().feature() >= 22;
}

public void testDotProduct() throws Exception {
for (int i = 0; i < 100; i++) {
var bench = new Int7uScorerBenchmark();
Expand All @@ -42,8 +46,10 @@ public void testDotProduct() throws Exception {
assertEquals(expected, bench.dotProductLucene(), delta);
assertEquals(expected, bench.dotProductNative(), delta);

expected = bench.dotProductLuceneQuery();
assertEquals(expected, bench.dotProductNativeQuery(), delta);
if (supportsHeapSegments()) {
expected = bench.dotProductLuceneQuery();
assertEquals(expected, bench.dotProductNativeQuery(), delta);
}
} finally {
bench.teardown();
}
Expand All @@ -60,8 +66,10 @@ public void testSquareDistance() throws Exception {
assertEquals(expected, bench.squareDistanceLucene(), delta);
assertEquals(expected, bench.squareDistanceNative(), delta);

expected = bench.squareDistanceLuceneQuery();
assertEquals(expected, bench.squareDistanceNativeQuery(), delta);
if (supportsHeapSegments()) {
expected = bench.squareDistanceLuceneQuery();
assertEquals(expected, bench.squareDistanceNativeQuery(), delta);
}
} finally {
bench.teardown();
}
Expand Down