mirror of https://github.com/apache/lucene.git
add tests for vectorutils integer boundaries (#12634)
This commit is contained in:
parent
2474940bff
commit
ce3a904465
|
@ -17,6 +17,7 @@
|
||||||
package org.apache.lucene.internal.vectorization;
|
package org.apache.lucene.internal.vectorization;
|
||||||
|
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
|
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.function.ToDoubleFunction;
|
import java.util.function.ToDoubleFunction;
|
||||||
import java.util.function.ToIntFunction;
|
import java.util.function.ToIntFunction;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
@ -62,6 +63,35 @@ public class TestVectorUtilSupport extends BaseVectorizationTestCase {
|
||||||
assertFloatReturningProviders(p -> p.cosine(a, b));
|
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) {
|
private void assertFloatReturningProviders(ToDoubleFunction<VectorUtilSupport> func) {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
func.applyAsDouble(LUCENE_PROVIDER.getVectorUtilSupport()),
|
func.applyAsDouble(LUCENE_PROVIDER.getVectorUtilSupport()),
|
||||||
|
|
Loading…
Reference in New Issue