You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ja...@apache.org on 2023/02/01 09:52:50 UTC

[lucene] 02/03: Remove VectorUtil#toBytesRef (#12121)

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

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

commit ae268472af8823f4205243f658ae990a9fabd59c
Author: Luca Cavanna <ja...@apache.org>
AuthorDate: Wed Feb 1 10:47:50 2023 +0100

    Remove VectorUtil#toBytesRef (#12121)
    
    The method is currently only used in its corresponding test method.
---
 .../src/java/org/apache/lucene/util/VectorUtil.java   | 19 -------------------
 .../test/org/apache/lucene/util/TestVectorUtil.java   | 12 ------------
 2 files changed, 31 deletions(-)

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 9b18414c004..8800d434ba6 100644
--- a/lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
+++ b/lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
@@ -270,23 +270,4 @@ public final class VectorUtil {
     float denom = (float) (a.length * (1 << 15));
     return 0.5f + dotProduct(a, b) / denom;
   }
-
-  /**
-   * Convert a floating point vector to an array of bytes using casting; the vector values should be
-   * in [-128,127]
-   *
-   * @param vector a vector
-   * @return a new BytesRef containing the vector's values cast to byte.
-   */
-  public static BytesRef toBytesRef(float[] vector) {
-    BytesRef b = new BytesRef(new byte[vector.length]);
-    for (int i = 0; i < vector.length; i++) {
-      if (vector[i] < -128 || vector[i] > 127) {
-        throw new IllegalArgumentException(
-            "Vector value at " + i + " is out of range [-128.127]: " + vector[i]);
-      }
-      b.bytes[i] = (byte) vector[i];
-    }
-    return b;
-  }
 }
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestVectorUtil.java b/lucene/core/src/test/org/apache/lucene/util/TestVectorUtil.java
index 57ed2a6c1f4..21ad580de6c 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestVectorUtil.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestVectorUtil.java
@@ -262,16 +262,4 @@ public class TestVectorUtil extends LuceneTestCase {
     u[1] = -v[0];
     assertEquals(0, VectorUtil.cosine(u, v), DELTA);
   }
-
-  public void testToBytesRef() {
-    assertEquals(
-        new BytesRef(new byte[] {-128, 0, 127}),
-        VectorUtil.toBytesRef(new float[] {-128f, 0, 127f}));
-    assertEquals(
-        new BytesRef(new byte[] {-19, 0, 33}),
-        VectorUtil.toBytesRef(new float[] {-19.9f, 0.5f, 33.7f}));
-    expectThrows(
-        IllegalArgumentException.class, () -> VectorUtil.toBytesRef(new float[] {-128.1f}));
-    expectThrows(IllegalArgumentException.class, () -> VectorUtil.toBytesRef(new float[] {127.1f}));
-  }
 }