Skip to content

Commit d25298f

Browse files
committed
Fix compilation errors in ProductQuantization
1 parent fa808d6 commit d25298f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

jvector-base/src/main/java/io/github/jbellis/jvector/quantization/ProductQuantization.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.Arrays;
3535
import java.util.List;
3636
import java.util.Objects;
37+
import java.util.concurrent.Callable;
3738
import java.util.concurrent.ForkJoinPool;
3839
import java.util.concurrent.ThreadLocalRandom;
3940
import java.util.concurrent.atomic.AtomicReference;
@@ -183,12 +184,13 @@ public ProductQuantization refine(RandomAccessVectorValues ravv,
183184
}
184185
var vectors = vectorsMutable; // "effectively final" to make the closure happy
185186

186-
var refinedCodebooks = simdExecutor.submit(() -> IntStream.range(0, M).parallel().mapToObj(m -> {
187+
Callable<VectorFloat<?>[]> callable = () -> IntStream.range(0, M).parallel().mapToObj(m -> {
187188
VectorFloat<?>[] subvectors = extractSubvectors(vectors, m, subvectorSizesAndOffsets);
188189
var clusterer = new KMeansPlusPlusClusterer(subvectors, codebooks[m], anisotropicThreshold);
189190
return clusterer.cluster(anisotropicThreshold == UNWEIGHTED ? lloydsRounds : 0,
190191
anisotropicThreshold == UNWEIGHTED ? 0 : lloydsRounds);
191-
}).toArray(VectorFloat<?>[]::new)).join();
192+
}).toArray(VectorFloat<?>[]::new);
193+
var refinedCodebooks = simdExecutor.submit(callable).join();
192194

193195
return new ProductQuantization(refinedCodebooks, clusterCount, subvectorSizesAndOffsets, globalCentroid, anisotropicThreshold);
194196
}
@@ -459,11 +461,12 @@ public int getClusterCount() {
459461

460462
static VectorFloat<?>[] createCodebooks(List<VectorFloat<?>> vectors, int[][] subvectorSizeAndOffset, int clusters, float anisotropicThreshold, ForkJoinPool simdExecutor) {
461463
int M = subvectorSizeAndOffset.length;
462-
return simdExecutor.submit(() -> IntStream.range(0, M).parallel().mapToObj(m -> {
464+
Callable<VectorFloat<?>[]> callable = () -> IntStream.range(0, M).parallel().mapToObj(m -> {
463465
VectorFloat<?>[] subvectors = extractSubvectors(vectors, m, subvectorSizeAndOffset);
464466
var clusterer = new KMeansPlusPlusClusterer(subvectors, clusters, anisotropicThreshold);
465467
return clusterer.cluster(K_MEANS_ITERATIONS, anisotropicThreshold == UNWEIGHTED ? 0 : K_MEANS_ITERATIONS);
466-
}).toArray(VectorFloat<?>[]::new)).join();
468+
}).toArray(VectorFloat<?>[]::new);
469+
return simdExecutor.submit(callable).join();
467470
}
468471

469472
/**

0 commit comments

Comments
 (0)