Skip to content

Apache Lucene open-source search software

Add cross-provider parity tests for uint8DotProduct and uint8SquareDistance (#16167)

vignesh_A48d4a9b470e1
diff --git a/lucene/core/src/test/org/apache/lucene/internal/vectorization/TestVectorUtilSupport.java b/lucene/core/src/test/org/apache/lucene/internal/vectorization/TestVectorUtilSupport.java
index ccfed7c8c1a..e5e630a388d 100644
--- a/lucene/core/src/test/org/apache/lucene/internal/vectorization/TestVectorUtilSupport.java
+++ b/lucene/core/src/test/org/apache/lucene/internal/vectorization/TestVectorUtilSupport.java
@@ -98,6 +98,40 @@ public class TestVectorUtilSupport extends BaseVectorizationTestCase {
assertFloatReturningProviders(p -> p.cosine(a, b));
}
+ public void testUint8Vectors() {
+ var a = new byte[size];
+ var b = new byte[size];
+ random().nextBytes(a);
+ random().nextBytes(b);
+ assertIntReturningProviders(p -> p.uint8DotProduct(a, b));
+ assertIntReturningProviders(p -> p.uint8SquareDistance(a, b));
+ }
+
+ public void testUint8VectorsBoundaries() {
+ var a = new byte[size];
+ var b = new byte[size];
+
+ Arrays.fill(a, Byte.MIN_VALUE);
+ Arrays.fill(b, Byte.MIN_VALUE);
+ assertIntReturningProviders(p -> p.uint8DotProduct(a, b));
+ assertIntReturningProviders(p -> p.uint8SquareDistance(a, b));
+
+ Arrays.fill(a, Byte.MAX_VALUE);
+ Arrays.fill(b, Byte.MAX_VALUE);
+ assertIntReturningProviders(p -> p.uint8DotProduct(a, b));
+ assertIntReturningProviders(p -> p.uint8SquareDistance(a, b));
+
+ Arrays.fill(a, Byte.MIN_VALUE);
+ Arrays.fill(b, Byte.MAX_VALUE);
+ assertIntReturningProviders(p -> p.uint8DotProduct(a, b));
+ assertIntReturningProviders(p -> p.uint8SquareDistance(a, b));
+
+ Arrays.fill(a, Byte.MAX_VALUE);
+ Arrays.fill(b, Byte.MIN_VALUE);
+ assertIntReturningProviders(p -> p.uint8DotProduct(a, b));
+ assertIntReturningProviders(p -> p.uint8SquareDistance(a, b));
+ }
+
public void testInt4DotProduct() {
assumeTrue("even sizes only", size % 2 == 0);
var a = new byte[size];