1515import org .junit .AfterClass ;
1616import org .junit .BeforeClass ;
1717
18- import java .lang .foreign .Arena ;
1918import java .lang .foreign .MemorySegment ;
20- import java .util .stream .IntStream ;
2119
2220import static org .hamcrest .Matchers .containsString ;
2321
24- public class JDKVectorLibraryTests extends VectorSimilarityFunctionsTests {
22+ public class JDKVectorLibraryInt7uTests extends VectorSimilarityFunctionsTests {
2523
2624 // bounds of the range of values that can be seen by int7 scalar quantized vectors
2725 static final byte MIN_INT7_VALUE = 0 ;
2826 static final byte MAX_INT7_VALUE = 127 ;
2927
30- static final Class <IllegalArgumentException > IAE = IllegalArgumentException .class ;
31- static final Class <IndexOutOfBoundsException > IOOBE = IndexOutOfBoundsException .class ;
32-
33- static final int [] VECTOR_DIMS = { 1 , 4 , 6 , 8 , 13 , 16 , 25 , 31 , 32 , 33 , 64 , 100 , 128 , 207 , 256 , 300 , 512 , 702 , 1023 , 1024 , 1025 };
34-
35- final int size ;
36-
37- static Arena arena ;
38-
39- final double delta ;
40-
41- public JDKVectorLibraryTests (int size ) {
42- this .size = size ;
43- this .delta = 1e-5 * size ; // scale the delta with the size
28+ public JDKVectorLibraryInt7uTests (int size ) {
29+ super (size );
4430 }
4531
4632 @ BeforeClass
47- public static void setup () {
48- arena = Arena . ofConfined ();
33+ public static void beforeClass () {
34+ VectorSimilarityFunctionsTests . setup ();
4935 }
5036
5137 @ AfterClass
52- public static void cleanup () {
53- arena . close ();
38+ public static void afterClass () {
39+ VectorSimilarityFunctionsTests . cleanup ();
5440 }
5541
5642 @ ParametersFactory
5743 public static Iterable <Object []> parametersFactory () {
58- return () -> IntStream . of ( VECTOR_DIMS ). boxed (). map ( i -> new Object [] { i }). iterator ();
44+ return VectorSimilarityFunctionsTests . parametersFactory ();
5945 }
6046
6147 public void testInt7BinaryVectors () {
@@ -79,7 +65,7 @@ public void testInt7BinaryVectors() {
7965 // dot product
8066 int expected = dotProductScalar (values [first ], values [second ]);
8167 assertEquals (expected , dotProduct7u (nativeSeg1 , nativeSeg2 , dims ));
82- if (testWithHeapSegments ()) {
68+ if (supportsHeapSegments ()) {
8369 var heapSeg1 = MemorySegment .ofArray (values [first ]);
8470 var heapSeg2 = MemorySegment .ofArray (values [second ]);
8571 assertEquals (expected , dotProduct7u (heapSeg1 , heapSeg2 , dims ));
@@ -90,7 +76,7 @@ public void testInt7BinaryVectors() {
9076 // square distance
9177 expected = squareDistanceScalar (values [first ], values [second ]);
9278 assertEquals (expected , squareDistance7u (nativeSeg1 , nativeSeg2 , dims ));
93- if (testWithHeapSegments ()) {
79+ if (supportsHeapSegments ()) {
9480 var heapSeg1 = MemorySegment .ofArray (values [first ]);
9581 var heapSeg2 = MemorySegment .ofArray (values [second ]);
9682 assertEquals (expected , squareDistance7u (heapSeg1 , heapSeg2 , dims ));
@@ -100,10 +86,6 @@ public void testInt7BinaryVectors() {
10086 }
10187 }
10288
103- static boolean testWithHeapSegments () {
104- return Runtime .version ().feature () >= 22 ;
105- }
106-
10789 public void testIllegalDims () {
10890 assumeTrue (notSupportedMsg (), supported ());
10991 var segment = arena .allocate ((long ) size * 3 );
0 commit comments