Apache Lucene open-source search software
Use panama vector for l2normalize (#12518)
Benjamin Trentd1c353116157
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 3a88efece17..f8f3b5ac8fb 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -182,6 +182,8 @@ Optimizations* GITHUB#12415: Optimized counts on disjunctive queries. (Adrien Grand)+* GITHUB#12518: Use panama vector API to speed up l2norm calculations (Ben Trent)+Bug Fixes---------------------diff --git a/lucene/core/src/java/org/apache/lucene/util/VectorUtil.java b/lucene/core/src/java/org/apache/lucene/util/VectorUtil.javaindex 1af99245806..a978e2d1f1f 100644--- a/lucene/core/src/java/org/apache/lucene/util/VectorUtil.java+++ b/lucene/core/src/java/org/apache/lucene/util/VectorUtil.java@@ -106,11 +106,8 @@ public final class VectorUtil {* @throws IllegalArgumentException when the vector is all zero and throwOnZero is true*/public static float[] l2normalize(float[] v, boolean throwOnZero) {- double squareSum = 0.0f;+ double squareSum = IMPL.dotProduct(v, v);int dim = v.length;- for (float x : v) {- squareSum += x * x;- }if (squareSum == 0) {if (throwOnZero) {throw new IllegalArgumentException("Cannot normalize a zero-length vector");