@@ -60,10 +60,8 @@ protected final void checkOrdinal(int ord) {
6060 }
6161
6262 final void bulkScoreFromOrds (int firstOrd , int [] ordinals , float [] scores , int numNodes ) throws IOException {
63- // throw new UnsupportedOperationException("not implemented");
64-
65- MemorySegment segment = input .segmentSliceOrNull (0 , input .length ());
66- if (segment == null ) {
63+ MemorySegment vectorsSeg = input .segmentSliceOrNull (0 , input .length ());
64+ if (vectorsSeg == null ) {
6765 bulkFallbackScore (firstOrd , ordinals , scores , numNodes );
6866 } else {
6967 final int vectorLength = dims ;
@@ -72,7 +70,7 @@ final void bulkScoreFromOrds(int firstOrd, int[] ordinals, float[] scores, int n
7270 var ordinalsSeg = MemorySegment .ofArray (ordinals );
7371 var scoresSeg = MemorySegment .ofArray (scores );
7472 bulkScoreFromSegment (
75- segment ,
73+ vectorsSeg ,
7674 vectorLength ,
7775 vectorPitch ,
7876 firstOrd ,
@@ -87,7 +85,7 @@ final void bulkScoreFromOrds(int firstOrd, int[] ordinals, float[] scores, int n
8785 MemorySegment .copy (ordinals , 0 , ordinalsMemorySegment , ValueLayout .JAVA_INT , 0 , numNodes );
8886
8987 bulkScoreFromSegment (
90- segment ,
88+ vectorsSeg ,
9189 vectorLength ,
9290 vectorPitch ,
9391 firstOrd ,
@@ -99,17 +97,6 @@ final void bulkScoreFromOrds(int firstOrd, int[] ordinals, float[] scores, int n
9997 MemorySegment .copy (scoresMemorySegment , ValueLayout .JAVA_FLOAT , 0 , scores , 0 , numNodes );
10098 }
10199 }
102-
103- long firstByteOffset = (long ) firstOrd * vectorPitch ;
104- var aOffset = Float .intBitsToFloat (input .readInt (firstByteOffset + vectorLength ));
105- for (int i = 0 ; i < numNodes ; ++i ) {
106- var dotProduct = scores [i ];
107- var secondOrd = ordinals [i ];
108- long secondByteOffset = (long ) secondOrd * vectorPitch ;
109- var bOffset = Float .intBitsToFloat (input .readInt (secondByteOffset + vectorLength ));
110- float adjustedDistance = dotProduct * scoreCorrectionConstant + aOffset + bOffset ;
111- scores [i ] = Math .max ((1 + adjustedDistance ) / 2 , 0f );
112- }
113100 }
114101 }
115102
@@ -149,12 +136,14 @@ protected void bulkScoreFromSegment(
149136 var a = vectors .asSlice (firstByteOffset , vectorLength );
150137 var aOffset = Float .intBitsToFloat (vectors .asSlice (firstByteOffset + vectorLength , Float .BYTES ).get (ValueLayout .JAVA_INT , 0 ));
151138 for (int i = 0 ; i < numNodes ; ++i ) {
152- var secondOrd = ordinals .get (ValueLayout .JAVA_INT , i );
139+ var secondOrd = ordinals .getAtIndex (ValueLayout .JAVA_INT , i );
153140 long secondByteOffset = (long ) secondOrd * vectorPitch ;
154141 var b = vectors .asSlice (secondByteOffset , vectorLength );
155- var bOffset = Float .intBitsToFloat (vectors .asSlice (secondByteOffset + vectorLength , Float .BYTES ).get (ValueLayout .JAVA_INT , 0 ));
142+ var bOffset = Float .intBitsToFloat (
143+ vectors .asSlice (secondByteOffset + vectorLength , Float .BYTES ).getAtIndex (ValueLayout .JAVA_INT , 0 )
144+ );
156145 var score = scoreFromSegments (a , aOffset , b , bOffset );
157- scores .set (ValueLayout .JAVA_FLOAT , i , score );
146+ scores .setAtIndex (ValueLayout .JAVA_FLOAT , i , score );
158147 }
159148 }
160149
@@ -274,17 +263,17 @@ protected void bulkScoreFromSegment(
274263 );
275264
276265 // Java-side adjustment
277- // var aOffset = Float.intBitsToFloat(vectors.asSlice(firstByteOffset + vectorLength, Float.BYTES).get(ValueLayout.JAVA_INT, 0));
278- // for (int i = 0; i < numNodes; ++i) {
279- // var dotProduct = scores.getAtIndex(ValueLayout.JAVA_FLOAT, i);
280- // var secondOrd = ordinals.getAtIndex(ValueLayout.JAVA_INT, i);
281- // long secondByteOffset = (long) secondOrd * vectorPitch;
282- // var bOffset = Float.intBitsToFloat(
283- // vectors.asSlice(secondByteOffset + vectorLength, Float.BYTES).getAtIndex(ValueLayout.JAVA_INT, 0)
284- // );
285- // float adjustedDistance = dotProduct * scoreCorrectionConstant + aOffset + bOffset;
286- // scores.setAtIndex(ValueLayout.JAVA_FLOAT, i, Math.max((1 + adjustedDistance) / 2, 0f));
287- // }
266+ var aOffset = Float .intBitsToFloat (vectors .asSlice (firstByteOffset + vectorLength , Float .BYTES ).get (ValueLayout .JAVA_INT , 0 ));
267+ for (int i = 0 ; i < numNodes ; ++i ) {
268+ var dotProduct = scores .getAtIndex (ValueLayout .JAVA_FLOAT , i );
269+ var secondOrd = ordinals .getAtIndex (ValueLayout .JAVA_INT , i );
270+ long secondByteOffset = (long ) secondOrd * vectorPitch ;
271+ var bOffset = Float .intBitsToFloat (
272+ vectors .asSlice (secondByteOffset + vectorLength , Float .BYTES ).getAtIndex (ValueLayout .JAVA_INT , 0 )
273+ );
274+ float adjustedDistance = dotProduct * scoreCorrectionConstant + aOffset + bOffset ;
275+ scores .setAtIndex (ValueLayout .JAVA_FLOAT , i , Math .max ((1 + adjustedDistance ) / 2 , 0f ));
276+ }
288277 }
289278
290279 @ Override
0 commit comments