add tests for vectorutils integer boundaries (#12634)

This commit is contained in:
Robert Muir 2023-10-08 11:26:33 -04:00 committed by GitHub
parent 2474940bff
commit ce3a904465
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 30 additions and 0 deletions

View File

@ -17,6 +17,7 @@
package org.apache.lucene.internal.vectorization;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import java.util.Arrays;
import java.util.function.ToDoubleFunction;
import java.util.function.ToIntFunction;
import java.util.stream.IntStream;
@ -62,6 +63,35 @@ public class TestVectorUtilSupport extends BaseVectorizationTestCase {
assertFloatReturningProviders(p -> p.cosine(a, b));
}
public void testBinaryVectorsBoundaries() {
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.dotProduct(a, b));
assertIntReturningProviders(p -> p.squareDistance(a, b));
assertFloatReturningProviders(p -> p.cosine(a, b));
Arrays.fill(a, Byte.MAX_VALUE);
Arrays.fill(b, Byte.MAX_VALUE);
assertIntReturningProviders(p -> p.dotProduct(a, b));
assertIntReturningProviders(p -> p.squareDistance(a, b));
assertFloatReturningProviders(p -> p.cosine(a, b));
Arrays.fill(a, Byte.MIN_VALUE);
Arrays.fill(b, Byte.MAX_VALUE);
assertIntReturningProviders(p -> p.dotProduct(a, b));
assertIntReturningProviders(p -> p.squareDistance(a, b));
assertFloatReturningProviders(p -> p.cosine(a, b));
Arrays.fill(a, Byte.MAX_VALUE);
Arrays.fill(b, Byte.MIN_VALUE);
assertIntReturningProviders(p -> p.dotProduct(a, b));
assertIntReturningProviders(p -> p.squareDistance(a, b));
assertFloatReturningProviders(p -> p.cosine(a, b));
}
private void assertFloatReturningProviders(ToDoubleFunction<VectorUtilSupport> func) {
assertEquals(
func.applyAsDouble(LUCENE_PROVIDER.getVectorUtilSupport()),