faiss 0.6.5 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/ext/faiss/extconf.rb +1 -0
  4. data/ext/faiss/index.cpp +42 -0
  5. data/lib/faiss/version.rb +1 -1
  6. data/vendor/faiss/faiss/IVFlib.cpp +48 -51
  7. data/vendor/faiss/faiss/IVFlib.h +6 -2
  8. data/vendor/faiss/faiss/Index.cpp +2 -2
  9. data/vendor/faiss/faiss/Index.h +3 -3
  10. data/vendor/faiss/faiss/IndexBinary.cpp +2 -2
  11. data/vendor/faiss/faiss/IndexBinary.h +2 -2
  12. data/vendor/faiss/faiss/IndexBinaryFlat.cpp +1 -0
  13. data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +6 -3
  14. data/vendor/faiss/faiss/IndexBinaryIVF.cpp +6 -11
  15. data/vendor/faiss/faiss/IndexFastScan.cpp +1 -1
  16. data/vendor/faiss/faiss/IndexFlat.cpp +1 -1
  17. data/vendor/faiss/faiss/IndexHNSW.cpp +12 -10
  18. data/vendor/faiss/faiss/IndexHNSW.h +2 -5
  19. data/vendor/faiss/faiss/IndexIDMap.cpp +17 -4
  20. data/vendor/faiss/faiss/IndexIDMap.h +10 -5
  21. data/vendor/faiss/faiss/IndexIVF.cpp +68 -37
  22. data/vendor/faiss/faiss/IndexIVF.h +37 -1
  23. data/vendor/faiss/faiss/IndexIVFFastScan.cpp +5 -15
  24. data/vendor/faiss/faiss/IndexIVFFlat.h +6 -6
  25. data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +1 -1
  26. data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +28 -44
  27. data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +2 -11
  28. data/vendor/faiss/faiss/IndexIVFRaBitQSSD.cpp +1694 -0
  29. data/vendor/faiss/faiss/IndexIVFRaBitQSSD.h +288 -0
  30. data/vendor/faiss/faiss/IndexIVFSQFastScan.cpp +7 -2
  31. data/vendor/faiss/faiss/IndexNNDescent.cpp +21 -0
  32. data/vendor/faiss/faiss/IndexRaBitQ.cpp +189 -41
  33. data/vendor/faiss/faiss/IndexRaBitQ.h +5 -0
  34. data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +1 -1
  35. data/vendor/faiss/faiss/IndexRaBitQFastScan.h +2 -2
  36. data/vendor/faiss/faiss/SuperKMeans.cpp +2 -2
  37. data/vendor/faiss/faiss/VectorTransform.cpp +156 -9
  38. data/vendor/faiss/faiss/VectorTransform.h +24 -1
  39. data/vendor/faiss/faiss/factory_tools.cpp +19 -1
  40. data/vendor/faiss/faiss/gpu/Dataset.h +66 -14
  41. data/vendor/faiss/faiss/gpu/GpuIndexBinaryCagra.h +8 -2
  42. data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +8 -2
  43. data/vendor/faiss/faiss/gpu/impl/optimal_kmeans/GpuOptimalKMeans.h +184 -0
  44. data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +12 -4
  45. data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +6 -5
  46. data/vendor/faiss/faiss/gpu_metal/GpuIndexFlat.h +1 -1
  47. data/vendor/faiss/faiss/gpu_metal/MetalCloner.h +1 -1
  48. data/vendor/faiss/faiss/gpu_metal/MetalDistance.h +1 -1
  49. data/vendor/faiss/faiss/gpu_metal/MetalFlatKernels.h +1 -1
  50. data/vendor/faiss/faiss/gpu_metal/MetalIndex.h +1 -1
  51. data/vendor/faiss/faiss/gpu_metal/MetalIndexBinaryFlat.h +1 -1
  52. data/vendor/faiss/faiss/gpu_metal/MetalIndexFlat.h +1 -1
  53. data/vendor/faiss/faiss/gpu_metal/MetalIndexIVFFlat.h +1 -1
  54. data/vendor/faiss/faiss/gpu_metal/MetalIndexIVFPQ.h +1 -1
  55. data/vendor/faiss/faiss/gpu_metal/MetalKernels.h +1 -1
  56. data/vendor/faiss/faiss/gpu_metal/MetalPythonBridge.h +1 -1
  57. data/vendor/faiss/faiss/gpu_metal/MetalResources.h +1 -1
  58. data/vendor/faiss/faiss/gpu_metal/StandardMetalResources.h +1 -1
  59. data/vendor/faiss/faiss/gpu_metal/impl/MetalIVFFlat.h +1 -1
  60. data/vendor/faiss/faiss/gpu_metal/impl/MetalIVFPQ.h +1 -1
  61. data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +1 -1
  62. data/vendor/faiss/faiss/impl/ClusteringInitialization.cpp +31 -50
  63. data/vendor/faiss/faiss/impl/ClusteringInitialization.h +0 -15
  64. data/vendor/faiss/faiss/impl/CodePacker.cpp +2 -2
  65. data/vendor/faiss/faiss/impl/CodePackerRaBitQ.cpp +2 -2
  66. data/vendor/faiss/faiss/impl/DeterministicNNDescent.cpp +2167 -0
  67. data/vendor/faiss/faiss/impl/DeterministicNNDescent.h +301 -0
  68. data/vendor/faiss/faiss/impl/HNSW.cpp +2 -2
  69. data/vendor/faiss/faiss/impl/HNSW.h +2 -2
  70. data/vendor/faiss/faiss/impl/IDSelector.h +5 -4
  71. data/vendor/faiss/faiss/impl/NNDescent.h +4 -0
  72. data/vendor/faiss/faiss/impl/PiPNN.cpp +4 -2
  73. data/vendor/faiss/faiss/impl/PiPNN.h +1 -1
  74. data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +1 -1
  75. data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +0 -2
  76. data/vendor/faiss/faiss/impl/RaBitQUtils.h +29 -0
  77. data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +14 -13
  78. data/vendor/faiss/faiss/impl/ResultHandler.h +116 -0
  79. data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryIVF_impl.h +1 -3
  80. data/vendor/faiss/faiss/impl/expanded_scanners.h +29 -24
  81. data/vendor/faiss/faiss/impl/fast_scan/fast_scan.cpp +68 -6
  82. data/vendor/faiss/faiss/impl/fast_scan/fast_scan.h +43 -0
  83. data/vendor/faiss/faiss/impl/fast_scan/impl-avx2.cpp +15 -0
  84. data/vendor/faiss/faiss/impl/fast_scan/impl-avx512.cpp +115 -0
  85. data/vendor/faiss/faiss/impl/fast_scan/impl-neon.cpp +13 -0
  86. data/vendor/faiss/faiss/impl/fast_scan/kernels_simd256.h +84 -0
  87. data/vendor/faiss/faiss/impl/fast_scan/kernels_simd512.h +0 -4
  88. data/vendor/faiss/faiss/impl/fast_scan/rabitq_result_handler.h +0 -1
  89. data/vendor/faiss/faiss/impl/fast_scan/simd_result_handlers.h +64 -55
  90. data/vendor/faiss/faiss/impl/hnsw/LockVector.h +1 -2
  91. data/vendor/faiss/faiss/impl/index_read.cpp +146 -9
  92. data/vendor/faiss/faiss/impl/index_write.cpp +29 -5
  93. data/vendor/faiss/faiss/impl/io.cpp +1 -0
  94. data/vendor/faiss/faiss/impl/io_macros.h +2 -2
  95. data/vendor/faiss/faiss/impl/mapped_io.cpp +3 -1
  96. data/vendor/faiss/faiss/impl/maybe_owned_vector.h +78 -41
  97. data/vendor/faiss/faiss/impl/nndescent/gram-avx2.cpp +121 -0
  98. data/vendor/faiss/faiss/impl/nndescent/gram-avx512.cpp +124 -0
  99. data/vendor/faiss/faiss/impl/nndescent/gram-neon.cpp +114 -0
  100. data/vendor/faiss/faiss/impl/nndescent/gram.h +66 -0
  101. data/vendor/faiss/faiss/impl/optimal_kmeans/BlockCombiner-avx512.cpp +431 -0
  102. data/vendor/faiss/faiss/impl/optimal_kmeans/BlockCombiner-inl.h +1157 -0
  103. data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeans.cpp +282 -0
  104. data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeans.h +226 -0
  105. data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeansCompressed.cpp +1567 -0
  106. data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeansCompressed.h +281 -0
  107. data/vendor/faiss/faiss/impl/pipnn/HashPrune.cpp +1 -1
  108. data/vendor/faiss/faiss/impl/platform_macros.h +47 -28
  109. data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQScanner_impl.h +6 -1
  110. data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQ_QueryTables.cpp +17 -17
  111. data/vendor/faiss/faiss/impl/result_handler/ResultHandler.cpp +68 -1
  112. data/vendor/faiss/faiss/impl/result_handler/avx2.cpp +70 -2
  113. data/vendor/faiss/faiss/impl/result_handler/avx512.cpp +2 -1
  114. data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer.cpp +1 -1
  115. data/vendor/faiss/faiss/impl/scalar_quantizer/scanners.h +26 -26
  116. data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx2.cpp +48 -45
  117. data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-impl.h +34 -32
  118. data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-spr.cpp +8 -6
  119. data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512.cpp +4 -3
  120. data/vendor/faiss/faiss/impl/scalar_quantizer/sq-neon.cpp +34 -33
  121. data/vendor/faiss/faiss/impl/simdlib/simdlib_avx512.h +20 -20
  122. data/vendor/faiss/faiss/impl/simdlib/simdlib_neon.h +4 -4
  123. data/vendor/faiss/faiss/impl/zerocopy_io.cpp +2 -1
  124. data/vendor/faiss/faiss/index_factory.cpp +30 -6
  125. data/vendor/faiss/faiss/invlists/DirectMap.cpp +1 -1
  126. data/vendor/faiss/faiss/invlists/DiskIOBackend.cpp +121 -0
  127. data/vendor/faiss/faiss/invlists/DiskIOBackend.h +71 -0
  128. data/vendor/faiss/faiss/invlists/InvertedLists.cpp +12 -9
  129. data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +26 -0
  130. data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +5 -0
  131. data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +9 -24
  132. data/vendor/faiss/faiss/invlists/RaBitQSSDInvertedLists.cpp +751 -0
  133. data/vendor/faiss/faiss/invlists/RaBitQSSDInvertedLists.h +224 -0
  134. data/vendor/faiss/faiss/svs/IndexSVSFaissUtils.h +2 -7
  135. data/vendor/faiss/faiss/svs/IndexSVSFlat.cpp +1 -1
  136. data/vendor/faiss/faiss/svs/IndexSVSIVF.cpp +2 -2
  137. data/vendor/faiss/faiss/svs/IndexSVSVamana.cpp +4 -4
  138. data/vendor/faiss/faiss/utils/WorkerThread.h +0 -1
  139. data/vendor/faiss/faiss/utils/distances.cpp +246 -34
  140. data/vendor/faiss/faiss/utils/distances.h +145 -2
  141. data/vendor/faiss/faiss/utils/extra_distances.h +2 -1
  142. data/vendor/faiss/faiss/utils/hamming-inl.h +3 -0
  143. data/vendor/faiss/faiss/utils/partitioning.cpp +2 -2
  144. data/vendor/faiss/faiss/utils/rabitq_simd.h +120 -6
  145. data/vendor/faiss/faiss/utils/simd_impl/distances_arm_sve.cpp +47 -7
  146. data/vendor/faiss/faiss/utils/simd_impl/distances_autovec-inl.h +7 -3
  147. data/vendor/faiss/faiss/utils/simd_impl/distances_avx2.cpp +47 -7
  148. data/vendor/faiss/faiss/utils/simd_impl/distances_avx512.cpp +50 -10
  149. data/vendor/faiss/faiss/utils/simd_impl/distances_simdlib256.h +3 -3
  150. data/vendor/faiss/faiss/utils/simd_impl/exhaustive_L2sqr_blas_cmax.h +13 -0
  151. data/vendor/faiss/faiss/utils/simd_impl/partitioning_simdlib256.h +16 -15
  152. data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx2.cpp +131 -36
  153. data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512.cpp +156 -45
  154. data/vendor/faiss/faiss/utils/simd_levels.cpp +3 -3
  155. data/vendor/faiss/faiss/utils/sorting.cpp +6 -5
  156. data/vendor/faiss/faiss/utils/utils.cpp +4 -0
  157. metadata +20 -1
@@ -22,7 +22,9 @@ TEST(TestCodePacking, NonInterleavedCodes_UnpackPack) {
22
22
  // deterministic
23
23
  auto seed = std::random_device()();
24
24
  std::mt19937 gen(seed);
25
- std::uniform_int_distribution<uint8_t> dist;
25
+ // uint8_t is not a conforming uniform_int_distribution type (N4950
26
+ // [rand.req.genl]/1.5); MSVC's STL rejects it. Use int over [0,255].
27
+ std::uniform_int_distribution<int> dist{0, 255};
26
28
 
27
29
  std::cout << "seed " << seed << "\n";
28
30
 
@@ -74,7 +76,9 @@ TEST(TestCodePacking, NonInterleavedCodes_PackUnpack) {
74
76
  // deterministic
75
77
  std::random_device rd;
76
78
  std::mt19937 gen(rd());
77
- std::uniform_int_distribution<uint8_t> dist;
79
+ // uint8_t is not a conforming uniform_int_distribution type (N4950
80
+ // [rand.req.genl]/1.5); MSVC's STL rejects it. Use int over [0,255].
81
+ std::uniform_int_distribution<int> dist{0, 255};
78
82
 
79
83
  for (auto bitsPerCode : {4, 5, 6, 8, 16, 32}) {
80
84
  for (auto dims : {1, 7, 8, 31, 32}) {
@@ -112,7 +116,9 @@ TEST(TestCodePacking, InterleavedCodes_UnpackPack) {
112
116
  // deterministic
113
117
  std::random_device rd;
114
118
  std::mt19937 gen(rd());
115
- std::uniform_int_distribution<uint8_t> dist;
119
+ // uint8_t is not a conforming uniform_int_distribution type (N4950
120
+ // [rand.req.genl]/1.5); MSVC's STL rejects it. Use int over [0,255].
121
+ std::uniform_int_distribution<int> dist{0, 255};
116
122
 
117
123
  for (auto bitsPerCode : {4, 5, 6, 8, 16, 32}) {
118
124
  for (auto dims : {1, 7, 8, 31, 32}) {
@@ -249,7 +255,9 @@ TEST(TestCodePacking, InterleavedCodes_PackUnpack) {
249
255
  // deterministic
250
256
  std::random_device rd;
251
257
  std::mt19937 gen(rd());
252
- std::uniform_int_distribution<uint8_t> dist;
258
+ // uint8_t is not a conforming uniform_int_distribution type (N4950
259
+ // [rand.req.genl]/1.5); MSVC's STL rejects it. Use int over [0,255].
260
+ std::uniform_int_distribution<int> dist{0, 255};
253
261
 
254
262
  for (auto bitsPerCode : {4, 5, 6, 8, 16, 32}) {
255
263
  for (auto dims : {1, 7, 8, 31, 32}) {
@@ -9,7 +9,7 @@
9
9
  #include <faiss/impl/IDSelector.h>
10
10
  #include <faiss/utils/random.h>
11
11
  #include <gtest/gtest.h>
12
- #include <time.h>
12
+ #include <chrono>
13
13
  #include <cmath>
14
14
  #include <set>
15
15
  #include <sstream>
@@ -100,10 +100,11 @@ std::mt19937 rng(1);
100
100
  std::uniform_int_distribution<> distrib;
101
101
 
102
102
  void newTestSeed() {
103
- struct timespec t;
104
- clock_gettime(CLOCK_REALTIME, &t);
105
-
106
- setTestSeed(t.tv_nsec);
103
+ auto ns = std::chrono::high_resolution_clock::now().time_since_epoch();
104
+ setTestSeed(
105
+ static_cast<long>(
106
+ std::chrono::duration_cast<std::chrono::nanoseconds>(ns)
107
+ .count()));
107
108
  }
108
109
 
109
110
  void setTestSeed(long seed) {
@@ -1,6 +1,6 @@
1
1
  // @lint-ignore-every LICENSELINT
2
2
  /**
3
- * Copyright (c) Meta Platforms, Inc. and its affiliates.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
@@ -1,6 +1,6 @@
1
1
  // @lint-ignore-every LICENSELINT
2
2
  /**
3
- * Copyright (c) Meta Platforms, Inc. and its affiliates.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
@@ -1,6 +1,6 @@
1
1
  // @lint-ignore-every LICENSELINT
2
2
  /**
3
- * Copyright (c) Meta Platforms, Inc. and its affiliates.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
@@ -1,6 +1,6 @@
1
1
  // @lint-ignore-every LICENSELINT
2
2
  /**
3
- * Copyright (c) Meta Platforms, Inc. and its affiliates.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
@@ -1,6 +1,6 @@
1
1
  // @lint-ignore-every LICENSELINT
2
2
  /**
3
- * Copyright (c) Meta Platforms, Inc. and its affiliates.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
@@ -1,6 +1,6 @@
1
1
  // @lint-ignore-every LICENSELINT
2
2
  /**
3
- * Copyright (c) Meta Platforms, Inc. and its affiliates.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
@@ -1,6 +1,6 @@
1
1
  // @lint-ignore-every LICENSELINT
2
2
  /**
3
- * Copyright (c) Meta Platforms, Inc. and its affiliates.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
@@ -1,6 +1,6 @@
1
1
  // @lint-ignore-every LICENSELINT
2
2
  /**
3
- * Copyright (c) Meta Platforms, Inc. and its affiliates.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
@@ -1,6 +1,6 @@
1
1
  // @lint-ignore-every LICENSELINT
2
2
  /**
3
- * Copyright (c) Meta Platforms, Inc. and its affiliates.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
@@ -1,6 +1,6 @@
1
1
  // @lint-ignore-every LICENSELINT
2
2
  /**
3
- * Copyright (c) Meta Platforms, Inc. and its affiliates.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
@@ -1,6 +1,6 @@
1
1
  // @lint-ignore-every LICENSELINT
2
2
  /**
3
- * Copyright (c) Meta Platforms, Inc. and its affiliates.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
@@ -1,6 +1,6 @@
1
1
  // @lint-ignore-every LICENSELINT
2
2
  /**
3
- * Copyright (c) Meta Platforms, Inc. and its affiliates.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
@@ -1,6 +1,6 @@
1
1
  // @lint-ignore-every LICENSELINT
2
2
  /**
3
- * Copyright (c) Meta Platforms, Inc. and its affiliates.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
@@ -1,6 +1,6 @@
1
1
  // @lint-ignore-every LICENSELINT
2
2
  /**
3
- * Copyright (c) Meta Platforms, Inc. and its affiliates.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
@@ -1,6 +1,6 @@
1
1
  // @lint-ignore-every LICENSELINT
2
2
  /**
3
- * Copyright (c) Meta Platforms, Inc. and its affiliates.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
@@ -123,7 +123,7 @@ RangeSearchPartialResult::RangeSearchPartialResult(RangeSearchResult* res_in)
123
123
 
124
124
  /// begin a new result
125
125
  RangeQueryResult& RangeSearchPartialResult::new_result(idx_t qno) {
126
- RangeQueryResult qres = {qno, 0, this};
126
+ RangeQueryResult qres = {qno, 0, this, {}};
127
127
  queries.push_back(qres);
128
128
  return queries.back();
129
129
  }
@@ -392,6 +392,22 @@ void validate_initialization(
392
392
  n_existing_centroids == 0 || existing_centroids != nullptr);
393
393
  }
394
394
 
395
+ void init_random(
396
+ const ClusteringInitialization& initializer,
397
+ size_t n,
398
+ const float* x,
399
+ float* centroids) {
400
+ const size_t d = initializer.d;
401
+ // Use rand_perm for backward compatibility with Clustering.cpp
402
+ // This ensures the same random sequence as the original implementation
403
+ std::vector<int> perm(n);
404
+ rand_perm(perm.data(), n, initializer.seed);
405
+
406
+ for (size_t i = 0; i < initializer.k; i++) {
407
+ std::memcpy(centroids + i * d, x + perm[i] * d, d * sizeof(float));
408
+ }
409
+ }
410
+
395
411
  } // namespace
396
412
 
397
413
  ClusteringInitialization::ClusteringInitialization(size_t d_in, size_t k_in)
@@ -408,66 +424,31 @@ void ClusteringInitialization::init_centroids(
408
424
 
409
425
  switch (method) {
410
426
  case ClusteringInitMethod::RANDOM:
411
- init_random(n, x, centroids);
427
+ init_random(*this, n, x, centroids);
412
428
  break;
413
429
  case ClusteringInitMethod::KMEANS_PLUS_PLUS:
414
- init_kmeans_plus_plus(
415
- n, x, centroids, n_existing_centroids, existing_centroids);
430
+ init_kmeans_plus_plus_impl(
431
+ *this,
432
+ n,
433
+ FloatRows{d, x},
434
+ centroids,
435
+ n_existing_centroids,
436
+ existing_centroids);
416
437
  break;
417
438
  case ClusteringInitMethod::AFK_MC2:
418
- init_afkmc2(
419
- n, x, centroids, n_existing_centroids, existing_centroids);
439
+ init_afkmc2_impl(
440
+ *this,
441
+ n,
442
+ FloatRows{d, x},
443
+ centroids,
444
+ n_existing_centroids,
445
+ existing_centroids);
420
446
  break;
421
447
  default:
422
448
  FAISS_THROW_MSG("Unknown initialization method");
423
449
  }
424
450
  }
425
451
 
426
- void ClusteringInitialization::init_random(
427
- size_t n,
428
- const float* x,
429
- float* centroids) const {
430
- // Use rand_perm for backward compatibility with Clustering.cpp
431
- // This ensures the same random sequence as the original implementation
432
- std::vector<int> perm(n);
433
- rand_perm(perm.data(), n, seed);
434
-
435
- // Copy selected points to centroids
436
- for (size_t i = 0; i < k; i++) {
437
- std::memcpy(centroids + i * d, x + perm[i] * d, d * sizeof(float));
438
- }
439
- }
440
-
441
- void ClusteringInitialization::init_kmeans_plus_plus(
442
- size_t n,
443
- const float* x,
444
- float* centroids,
445
- size_t n_existing_centroids,
446
- const float* existing_centroids) const {
447
- init_kmeans_plus_plus_impl(
448
- *this,
449
- n,
450
- FloatRows{d, x},
451
- centroids,
452
- n_existing_centroids,
453
- existing_centroids);
454
- }
455
-
456
- void ClusteringInitialization::init_afkmc2(
457
- size_t n,
458
- const float* x,
459
- float* centroids,
460
- size_t n_existing_centroids,
461
- const float* existing_centroids) const {
462
- init_afkmc2_impl(
463
- *this,
464
- n,
465
- FloatRows{d, x},
466
- centroids,
467
- n_existing_centroids,
468
- existing_centroids);
469
- }
470
-
471
452
  namespace detail {
472
453
 
473
454
  void init_centroids_fp16(
@@ -87,21 +87,6 @@ struct ClusteringInitialization {
87
87
  float* centroids,
88
88
  size_t n_existing_centroids = 0,
89
89
  const float* existing_centroids = nullptr) const;
90
-
91
- private:
92
- void init_random(size_t n, const float* x, float* centroids) const;
93
- void init_kmeans_plus_plus(
94
- size_t n,
95
- const float* x,
96
- float* centroids,
97
- size_t n_existing_centroids,
98
- const float* existing_centroids) const;
99
- void init_afkmc2(
100
- size_t n,
101
- const float* x,
102
- float* centroids,
103
- size_t n_existing_centroids,
104
- const float* existing_centroids) const;
105
90
  };
106
91
 
107
92
  } // namespace faiss
@@ -50,7 +50,7 @@ void CodePackerFlat::unpack_all(const uint8_t* block, uint8_t* flat_codes)
50
50
 
51
51
  void CodePackerFlat::pack_1(
52
52
  const uint8_t* flat_code,
53
- size_t offset,
53
+ [[maybe_unused]] size_t offset,
54
54
  uint8_t* block) const {
55
55
  assert(offset == 0);
56
56
  pack_all(flat_code, block);
@@ -58,7 +58,7 @@ void CodePackerFlat::pack_1(
58
58
 
59
59
  void CodePackerFlat::unpack_1(
60
60
  const uint8_t* block,
61
- size_t offset,
61
+ [[maybe_unused]] size_t offset,
62
62
  uint8_t* flat_code) const {
63
63
  assert(offset == 0);
64
64
  unpack_all(block, flat_code);
@@ -13,10 +13,10 @@
13
13
  namespace faiss {
14
14
 
15
15
  CodePackerRaBitQ::CodePackerRaBitQ(
16
- size_t nsq,
16
+ size_t nsq_in,
17
17
  size_t bbs,
18
18
  size_t aux_per_vector) {
19
- this->nsq = nsq;
19
+ nsq = nsq_in;
20
20
  this->aux_size_per_vec = aux_per_vector;
21
21
  nvec = bbs;
22
22
  const size_t pq4_bytes = (nsq * 4 + 7) / 8;