You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by be...@apache.org on 2023/08/29 12:34:49 UTC

[lucene] branch branch_9x updated: Use panama vector for l2normalize (#12518)

This is an automated email from the ASF dual-hosted git repository.

benwtrent pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new bb7e43be5a2 Use panama vector for l2normalize (#12518)
bb7e43be5a2 is described below

commit bb7e43be5a23829251f2a8d72dafdc756c8dfcc7
Author: Benjamin Trent <be...@gmail.com>
AuthorDate: Tue Aug 29 08:33:49 2023 -0400

    Use panama vector for l2normalize (#12518)
    
    Use panama vector for l2normalize
---
 lucene/CHANGES.txt                                          | 2 ++
 lucene/core/src/java/org/apache/lucene/util/VectorUtil.java | 5 +----
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 93a72338f3a..ef86c545002 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -60,6 +60,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.java
index 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");