faiss 0.3.0 → 0.3.2

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 (216) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +1 -1
  5. data/ext/faiss/extconf.rb +9 -2
  6. data/ext/faiss/index.cpp +1 -1
  7. data/ext/faiss/index_binary.cpp +2 -2
  8. data/ext/faiss/product_quantizer.cpp +1 -1
  9. data/lib/faiss/version.rb +1 -1
  10. data/vendor/faiss/faiss/AutoTune.cpp +7 -7
  11. data/vendor/faiss/faiss/AutoTune.h +1 -2
  12. data/vendor/faiss/faiss/Clustering.cpp +39 -22
  13. data/vendor/faiss/faiss/Clustering.h +40 -21
  14. data/vendor/faiss/faiss/IVFlib.cpp +26 -12
  15. data/vendor/faiss/faiss/Index.cpp +1 -1
  16. data/vendor/faiss/faiss/Index.h +40 -10
  17. data/vendor/faiss/faiss/Index2Layer.cpp +7 -7
  18. data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +176 -166
  19. data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.cpp +15 -15
  20. data/vendor/faiss/faiss/IndexBinary.cpp +9 -4
  21. data/vendor/faiss/faiss/IndexBinary.h +8 -19
  22. data/vendor/faiss/faiss/IndexBinaryFromFloat.cpp +2 -1
  23. data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +24 -31
  24. data/vendor/faiss/faiss/IndexBinaryHNSW.h +1 -1
  25. data/vendor/faiss/faiss/IndexBinaryHash.cpp +25 -50
  26. data/vendor/faiss/faiss/IndexBinaryIVF.cpp +107 -188
  27. data/vendor/faiss/faiss/IndexFastScan.cpp +95 -146
  28. data/vendor/faiss/faiss/IndexFastScan.h +9 -8
  29. data/vendor/faiss/faiss/IndexFlat.cpp +206 -10
  30. data/vendor/faiss/faiss/IndexFlat.h +20 -1
  31. data/vendor/faiss/faiss/IndexFlatCodes.cpp +170 -5
  32. data/vendor/faiss/faiss/IndexFlatCodes.h +23 -4
  33. data/vendor/faiss/faiss/IndexHNSW.cpp +231 -382
  34. data/vendor/faiss/faiss/IndexHNSW.h +62 -49
  35. data/vendor/faiss/faiss/IndexIDMap.cpp +69 -28
  36. data/vendor/faiss/faiss/IndexIDMap.h +24 -2
  37. data/vendor/faiss/faiss/IndexIVF.cpp +162 -56
  38. data/vendor/faiss/faiss/IndexIVF.h +46 -6
  39. data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +33 -26
  40. data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.h +6 -2
  41. data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +19 -46
  42. data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +4 -3
  43. data/vendor/faiss/faiss/IndexIVFFastScan.cpp +502 -401
  44. data/vendor/faiss/faiss/IndexIVFFastScan.h +63 -26
  45. data/vendor/faiss/faiss/IndexIVFFlat.cpp +15 -5
  46. data/vendor/faiss/faiss/IndexIVFFlat.h +3 -2
  47. data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.cpp +172 -0
  48. data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.h +56 -0
  49. data/vendor/faiss/faiss/IndexIVFPQ.cpp +79 -125
  50. data/vendor/faiss/faiss/IndexIVFPQ.h +6 -7
  51. data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +39 -52
  52. data/vendor/faiss/faiss/IndexIVFPQFastScan.h +4 -3
  53. data/vendor/faiss/faiss/IndexIVFPQR.cpp +45 -29
  54. data/vendor/faiss/faiss/IndexIVFPQR.h +5 -2
  55. data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +25 -27
  56. data/vendor/faiss/faiss/IndexIVFSpectralHash.h +6 -6
  57. data/vendor/faiss/faiss/IndexLSH.cpp +14 -16
  58. data/vendor/faiss/faiss/IndexLattice.cpp +1 -19
  59. data/vendor/faiss/faiss/IndexLattice.h +3 -22
  60. data/vendor/faiss/faiss/IndexNNDescent.cpp +3 -33
  61. data/vendor/faiss/faiss/IndexNNDescent.h +1 -1
  62. data/vendor/faiss/faiss/IndexNSG.cpp +11 -27
  63. data/vendor/faiss/faiss/IndexNSG.h +11 -11
  64. data/vendor/faiss/faiss/IndexNeuralNetCodec.cpp +56 -0
  65. data/vendor/faiss/faiss/IndexNeuralNetCodec.h +49 -0
  66. data/vendor/faiss/faiss/IndexPQ.cpp +72 -88
  67. data/vendor/faiss/faiss/IndexPQ.h +1 -4
  68. data/vendor/faiss/faiss/IndexPQFastScan.cpp +1 -1
  69. data/vendor/faiss/faiss/IndexPreTransform.cpp +25 -31
  70. data/vendor/faiss/faiss/IndexPreTransform.h +1 -1
  71. data/vendor/faiss/faiss/IndexRefine.cpp +54 -24
  72. data/vendor/faiss/faiss/IndexRefine.h +7 -0
  73. data/vendor/faiss/faiss/IndexReplicas.cpp +23 -26
  74. data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +25 -17
  75. data/vendor/faiss/faiss/IndexScalarQuantizer.h +6 -4
  76. data/vendor/faiss/faiss/IndexShards.cpp +21 -29
  77. data/vendor/faiss/faiss/IndexShardsIVF.cpp +1 -2
  78. data/vendor/faiss/faiss/MatrixStats.cpp +17 -32
  79. data/vendor/faiss/faiss/MatrixStats.h +21 -9
  80. data/vendor/faiss/faiss/MetaIndexes.cpp +35 -35
  81. data/vendor/faiss/faiss/MetricType.h +7 -2
  82. data/vendor/faiss/faiss/VectorTransform.cpp +13 -26
  83. data/vendor/faiss/faiss/VectorTransform.h +7 -7
  84. data/vendor/faiss/faiss/clone_index.cpp +15 -10
  85. data/vendor/faiss/faiss/clone_index.h +3 -0
  86. data/vendor/faiss/faiss/cppcontrib/detail/UintReader.h +95 -17
  87. data/vendor/faiss/faiss/cppcontrib/factory_tools.cpp +152 -0
  88. data/vendor/faiss/faiss/cppcontrib/factory_tools.h +24 -0
  89. data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-inl.h +83 -30
  90. data/vendor/faiss/faiss/gpu/GpuCloner.cpp +123 -8
  91. data/vendor/faiss/faiss/gpu/GpuCloner.h +22 -0
  92. data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +13 -0
  93. data/vendor/faiss/faiss/gpu/GpuDistance.h +46 -38
  94. data/vendor/faiss/faiss/gpu/GpuFaissAssert.h +1 -1
  95. data/vendor/faiss/faiss/gpu/GpuIndex.h +30 -12
  96. data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +282 -0
  97. data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +4 -4
  98. data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +14 -9
  99. data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +20 -3
  100. data/vendor/faiss/faiss/gpu/GpuIndexIVFPQ.h +22 -11
  101. data/vendor/faiss/faiss/gpu/GpuIndexIVFScalarQuantizer.h +1 -3
  102. data/vendor/faiss/faiss/gpu/GpuResources.cpp +24 -3
  103. data/vendor/faiss/faiss/gpu/GpuResources.h +39 -11
  104. data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +142 -17
  105. data/vendor/faiss/faiss/gpu/StandardGpuResources.h +57 -3
  106. data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.cpp +26 -21
  107. data/vendor/faiss/faiss/gpu/perf/PerfClustering.cpp +7 -1
  108. data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +8 -5
  109. data/vendor/faiss/faiss/gpu/test/TestGpuIndexBinaryFlat.cpp +25 -0
  110. data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +129 -9
  111. data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +332 -40
  112. data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +299 -208
  113. data/vendor/faiss/faiss/gpu/test/TestGpuMemoryException.cpp +1 -0
  114. data/vendor/faiss/faiss/gpu/test/demo_ivfpq_indexing_gpu.cpp +1 -1
  115. data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +6 -0
  116. data/vendor/faiss/faiss/gpu/utils/RaftUtils.h +75 -0
  117. data/vendor/faiss/faiss/gpu/utils/Timer.cpp +4 -1
  118. data/vendor/faiss/faiss/gpu/utils/Timer.h +1 -1
  119. data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +3 -1
  120. data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +5 -5
  121. data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +26 -1
  122. data/vendor/faiss/faiss/impl/AuxIndexStructures.h +10 -3
  123. data/vendor/faiss/faiss/impl/DistanceComputer.h +70 -1
  124. data/vendor/faiss/faiss/impl/FaissAssert.h +4 -2
  125. data/vendor/faiss/faiss/impl/FaissException.h +13 -34
  126. data/vendor/faiss/faiss/impl/HNSW.cpp +605 -186
  127. data/vendor/faiss/faiss/impl/HNSW.h +52 -30
  128. data/vendor/faiss/faiss/impl/IDSelector.h +4 -4
  129. data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +11 -9
  130. data/vendor/faiss/faiss/impl/LookupTableScaler.h +34 -0
  131. data/vendor/faiss/faiss/impl/NNDescent.cpp +42 -27
  132. data/vendor/faiss/faiss/impl/NSG.cpp +0 -29
  133. data/vendor/faiss/faiss/impl/NSG.h +1 -1
  134. data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +14 -12
  135. data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.h +1 -1
  136. data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +25 -22
  137. data/vendor/faiss/faiss/impl/ProductQuantizer.h +6 -2
  138. data/vendor/faiss/faiss/impl/Quantizer.h +1 -1
  139. data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +27 -1015
  140. data/vendor/faiss/faiss/impl/ResidualQuantizer.h +5 -63
  141. data/vendor/faiss/faiss/impl/ResultHandler.h +347 -172
  142. data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +1104 -147
  143. data/vendor/faiss/faiss/impl/ScalarQuantizer.h +3 -8
  144. data/vendor/faiss/faiss/impl/code_distance/code_distance-avx2.h +285 -42
  145. data/vendor/faiss/faiss/impl/code_distance/code_distance-avx512.h +248 -0
  146. data/vendor/faiss/faiss/impl/code_distance/code_distance-generic.h +21 -14
  147. data/vendor/faiss/faiss/impl/code_distance/code_distance.h +22 -12
  148. data/vendor/faiss/faiss/impl/index_read.cpp +74 -34
  149. data/vendor/faiss/faiss/impl/index_read_utils.h +37 -0
  150. data/vendor/faiss/faiss/impl/index_write.cpp +88 -51
  151. data/vendor/faiss/faiss/impl/io.cpp +23 -15
  152. data/vendor/faiss/faiss/impl/io.h +4 -4
  153. data/vendor/faiss/faiss/impl/io_macros.h +6 -0
  154. data/vendor/faiss/faiss/impl/lattice_Zn.cpp +1 -1
  155. data/vendor/faiss/faiss/impl/platform_macros.h +40 -1
  156. data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +14 -0
  157. data/vendor/faiss/faiss/impl/pq4_fast_scan.h +7 -6
  158. data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +52 -38
  159. data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +487 -49
  160. data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +960 -0
  161. data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.h +176 -0
  162. data/vendor/faiss/faiss/impl/simd_result_handlers.h +481 -225
  163. data/vendor/faiss/faiss/index_factory.cpp +41 -20
  164. data/vendor/faiss/faiss/index_io.h +12 -5
  165. data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +28 -8
  166. data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +3 -0
  167. data/vendor/faiss/faiss/invlists/DirectMap.cpp +10 -2
  168. data/vendor/faiss/faiss/invlists/InvertedLists.cpp +73 -17
  169. data/vendor/faiss/faiss/invlists/InvertedLists.h +26 -8
  170. data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +24 -9
  171. data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +2 -1
  172. data/vendor/faiss/faiss/python/python_callbacks.cpp +4 -4
  173. data/vendor/faiss/faiss/utils/Heap.cpp +3 -1
  174. data/vendor/faiss/faiss/utils/Heap.h +105 -0
  175. data/vendor/faiss/faiss/utils/NeuralNet.cpp +342 -0
  176. data/vendor/faiss/faiss/utils/NeuralNet.h +147 -0
  177. data/vendor/faiss/faiss/utils/WorkerThread.h +1 -0
  178. data/vendor/faiss/faiss/utils/bf16.h +36 -0
  179. data/vendor/faiss/faiss/utils/distances.cpp +147 -123
  180. data/vendor/faiss/faiss/utils/distances.h +86 -9
  181. data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +5 -5
  182. data/vendor/faiss/faiss/utils/distances_fused/avx512.h +2 -2
  183. data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +2 -2
  184. data/vendor/faiss/faiss/utils/distances_fused/distances_fused.h +1 -1
  185. data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +5 -5
  186. data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.h +1 -1
  187. data/vendor/faiss/faiss/utils/distances_simd.cpp +1589 -243
  188. data/vendor/faiss/faiss/utils/extra_distances-inl.h +70 -0
  189. data/vendor/faiss/faiss/utils/extra_distances.cpp +85 -137
  190. data/vendor/faiss/faiss/utils/extra_distances.h +3 -2
  191. data/vendor/faiss/faiss/utils/fp16-arm.h +29 -0
  192. data/vendor/faiss/faiss/utils/fp16.h +2 -0
  193. data/vendor/faiss/faiss/utils/hamming.cpp +163 -111
  194. data/vendor/faiss/faiss/utils/hamming.h +58 -0
  195. data/vendor/faiss/faiss/utils/hamming_distance/avx2-inl.h +16 -89
  196. data/vendor/faiss/faiss/utils/hamming_distance/common.h +1 -0
  197. data/vendor/faiss/faiss/utils/hamming_distance/generic-inl.h +19 -88
  198. data/vendor/faiss/faiss/utils/hamming_distance/hamdis-inl.h +58 -0
  199. data/vendor/faiss/faiss/utils/hamming_distance/neon-inl.h +14 -104
  200. data/vendor/faiss/faiss/utils/partitioning.cpp +3 -4
  201. data/vendor/faiss/faiss/utils/prefetch.h +77 -0
  202. data/vendor/faiss/faiss/utils/quantize_lut.cpp +0 -14
  203. data/vendor/faiss/faiss/utils/random.cpp +43 -0
  204. data/vendor/faiss/faiss/utils/random.h +25 -0
  205. data/vendor/faiss/faiss/utils/simdlib.h +10 -1
  206. data/vendor/faiss/faiss/utils/simdlib_avx2.h +0 -6
  207. data/vendor/faiss/faiss/utils/simdlib_avx512.h +296 -0
  208. data/vendor/faiss/faiss/utils/simdlib_neon.h +77 -79
  209. data/vendor/faiss/faiss/utils/simdlib_ppc64.h +1084 -0
  210. data/vendor/faiss/faiss/utils/sorting.cpp +140 -5
  211. data/vendor/faiss/faiss/utils/sorting.h +27 -0
  212. data/vendor/faiss/faiss/utils/transpose/transpose-avx512-inl.h +176 -0
  213. data/vendor/faiss/faiss/utils/utils.cpp +120 -7
  214. data/vendor/faiss/faiss/utils/utils.h +60 -20
  215. metadata +23 -4
  216. data/vendor/faiss/faiss/impl/code_distance/code_distance_avx512.h +0 -102
@@ -36,6 +36,34 @@ float fvec_L1(const float* x, const float* y, size_t d);
36
36
  /// infinity distance
37
37
  float fvec_Linf(const float* x, const float* y, size_t d);
38
38
 
39
+ /// Special version of inner product that computes 4 distances
40
+ /// between x and yi, which is performance oriented.
41
+ void fvec_inner_product_batch_4(
42
+ const float* x,
43
+ const float* y0,
44
+ const float* y1,
45
+ const float* y2,
46
+ const float* y3,
47
+ const size_t d,
48
+ float& dis0,
49
+ float& dis1,
50
+ float& dis2,
51
+ float& dis3);
52
+
53
+ /// Special version of L2sqr that computes 4 distances
54
+ /// between x and yi, which is performance oriented.
55
+ void fvec_L2sqr_batch_4(
56
+ const float* x,
57
+ const float* y0,
58
+ const float* y1,
59
+ const float* y2,
60
+ const float* y3,
61
+ const size_t d,
62
+ float& dis0,
63
+ float& dis1,
64
+ float& dis2,
65
+ float& dis3);
66
+
39
67
  /** Compute pairwise distances between sets of vectors
40
68
  *
41
69
  * @param d dimension of the vectors
@@ -170,8 +198,16 @@ void fvec_sub(size_t d, const float* a, const float* b, float* c);
170
198
  * Compute a subset of distances
171
199
  ***************************************************************************/
172
200
 
173
- /* compute the inner product between x and a subset y of ny vectors,
174
- whose indices are given by idy. */
201
+ /** compute the inner product between x and a subset y of ny vectors defined by
202
+ * ids
203
+ *
204
+ * ip(i, j) = inner_product(x(i, :), y(ids(i, j), :))
205
+ *
206
+ * @param ip output array, size nx * ny
207
+ * @param x first-term vector, size nx * d
208
+ * @param y second-term vector, size (max(ids) + 1) * d
209
+ * @param ids ids to sample from y, size nx * ny
210
+ */
175
211
  void fvec_inner_products_by_idx(
176
212
  float* ip,
177
213
  const float* x,
@@ -181,7 +217,16 @@ void fvec_inner_products_by_idx(
181
217
  size_t nx,
182
218
  size_t ny);
183
219
 
184
- /* same but for a subset in y indexed by idsy (ny vectors in total) */
220
+ /** compute the squared L2 distances between x and a subset y of ny vectors
221
+ * defined by ids
222
+ *
223
+ * dis(i, j) = inner_product(x(i, :), y(ids(i, j), :))
224
+ *
225
+ * @param dis output array, size nx * ny
226
+ * @param x first-term vector, size nx * d
227
+ * @param y second-term vector, size (max(ids) + 1) * d
228
+ * @param ids ids to sample from y, size nx * ny
229
+ */
185
230
  void fvec_L2sqr_by_idx(
186
231
  float* dis,
187
232
  const float* x,
@@ -208,7 +253,14 @@ void pairwise_indexed_L2sqr(
208
253
  const int64_t* iy,
209
254
  float* dis);
210
255
 
211
- /* same for inner product */
256
+ /** compute dis[j] = inner_product(x[ix[j]], y[iy[j]]) forall j=0..n-1
257
+ *
258
+ * @param x size (max(ix) + 1, d)
259
+ * @param y size (max(iy) + 1, d)
260
+ * @param ix size n
261
+ * @param iy size n
262
+ * @param dis size n
263
+ */
212
264
  void pairwise_indexed_inner_product(
213
265
  size_t d,
214
266
  size_t n,
@@ -233,7 +285,7 @@ FAISS_API extern int distance_compute_blas_database_bs;
233
285
  // rather than a heap
234
286
  FAISS_API extern int distance_compute_min_k_reservoir;
235
287
 
236
- /** Return the k nearest neighors of each of the nx vectors x among the ny
288
+ /** Return the k nearest neighbors of each of the nx vectors x among the ny
237
289
  * vector y, w.r.t to max inner product.
238
290
  *
239
291
  * @param x query vectors, size nx * d
@@ -249,7 +301,7 @@ void knn_inner_product(
249
301
  float_minheap_array_t* res,
250
302
  const IDSelector* sel = nullptr);
251
303
 
252
- /** Return the k nearest neighors of each of the nx vectors x among the ny
304
+ /** Return the k nearest neighbors of each of the nx vectors x among the ny
253
305
  * vector y, for the inner product metric.
254
306
  *
255
307
  * @param x query vectors, size nx * d
@@ -268,7 +320,7 @@ void knn_inner_product(
268
320
  int64_t* indexes,
269
321
  const IDSelector* sel = nullptr);
270
322
 
271
- /** Return the k nearest neighors of each of the nx vectors x among the ny
323
+ /** Return the k nearest neighbors of each of the nx vectors x among the ny
272
324
  * vector y, for the L2 distance
273
325
  * @param x query vectors, size nx * d
274
326
  * @param y database vectors, size ny * d
@@ -286,7 +338,7 @@ void knn_L2sqr(
286
338
  const float* y_norm2 = nullptr,
287
339
  const IDSelector* sel = nullptr);
288
340
 
289
- /** Return the k nearest neighors of each of the nx vectors x among the ny
341
+ /** Return the k nearest neighbors of each of the nx vectors x among the ny
290
342
  * vector y, for the L2 distance
291
343
  *
292
344
  * @param x query vectors, size nx * d
@@ -324,6 +376,7 @@ void knn_inner_products_by_idx(
324
376
  const int64_t* subset,
325
377
  size_t d,
326
378
  size_t nx,
379
+ size_t ny,
327
380
  size_t nsubset,
328
381
  size_t k,
329
382
  float* vals,
@@ -346,6 +399,7 @@ void knn_L2sqr_by_idx(
346
399
  const int64_t* subset,
347
400
  size_t d,
348
401
  size_t nx,
402
+ size_t ny,
349
403
  size_t nsubset,
350
404
  size_t k,
351
405
  float* vals,
@@ -359,7 +413,7 @@ void knn_L2sqr_by_idx(
359
413
  /// Forward declaration, see AuxIndexStructures.h
360
414
  struct RangeSearchResult;
361
415
 
362
- /** Return the k nearest neighors of each of the nx vectors x among the ny
416
+ /** Return the k nearest neighbors of each of the nx vectors x among the ny
363
417
  * vector y, w.r.t to max inner product
364
418
  *
365
419
  * @param x query vectors, size nx * d
@@ -406,4 +460,27 @@ void compute_PQ_dis_tables_dsub2(
406
460
  * Templatized versions of distance functions
407
461
  ***************************************************************************/
408
462
 
463
+ /***************************************************************************
464
+ * Misc matrix and vector manipulation functions
465
+ ***************************************************************************/
466
+
467
+ /** compute c := a + bf * b for a, b and c tables
468
+ *
469
+ * @param n size of the tables
470
+ * @param a size n
471
+ * @param b size n
472
+ * @param c restult table, size n
473
+ */
474
+ void fvec_madd(size_t n, const float* a, float bf, const float* b, float* c);
475
+
476
+ /** same as fvec_madd, also return index of the min of the result table
477
+ * @return index of the min of table c
478
+ */
479
+ int fvec_madd_and_argmin(
480
+ size_t n,
481
+ const float* a,
482
+ float bf,
483
+ const float* b,
484
+ float* c);
485
+
409
486
  } // namespace faiss
@@ -9,7 +9,7 @@
9
9
 
10
10
  #include <faiss/utils/distances_fused/avx512.h>
11
11
 
12
- #ifdef __AVX512__
12
+ #ifdef __AVX512F__
13
13
 
14
14
  #include <immintrin.h>
15
15
 
@@ -68,7 +68,7 @@ void kernel(
68
68
  const float* const __restrict y,
69
69
  const float* const __restrict y_transposed,
70
70
  size_t ny,
71
- SingleBestResultHandler<CMax<float, int64_t>>& res,
71
+ Top1BlockResultHandler<CMax<float, int64_t>>& res,
72
72
  const float* __restrict y_norms,
73
73
  size_t i) {
74
74
  const size_t ny_p =
@@ -231,7 +231,7 @@ void exhaustive_L2sqr_fused_cmax(
231
231
  const float* const __restrict y,
232
232
  size_t nx,
233
233
  size_t ny,
234
- SingleBestResultHandler<CMax<float, int64_t>>& res,
234
+ Top1BlockResultHandler<CMax<float, int64_t>>& res,
235
235
  const float* __restrict y_norms) {
236
236
  // BLAS does not like empty matrices
237
237
  if (nx == 0 || ny == 0) {
@@ -275,7 +275,7 @@ void exhaustive_L2sqr_fused_cmax(
275
275
  x, y, y_transposed.data(), ny, res, y_norms, i);
276
276
  }
277
277
 
278
- // Does nothing for SingleBestResultHandler, but
278
+ // Does nothing for Top1BlockResultHandler, but
279
279
  // keeping the call for the consistency.
280
280
  res.end_multiple();
281
281
  InterruptCallback::check();
@@ -289,7 +289,7 @@ bool exhaustive_L2sqr_fused_cmax_AVX512(
289
289
  size_t d,
290
290
  size_t nx,
291
291
  size_t ny,
292
- SingleBestResultHandler<CMax<float, int64_t>>& res,
292
+ Top1BlockResultHandler<CMax<float, int64_t>>& res,
293
293
  const float* y_norms) {
294
294
  // process only cases with certain dimensionalities
295
295
 
@@ -16,7 +16,7 @@
16
16
 
17
17
  #include <faiss/utils/Heap.h>
18
18
 
19
- #ifdef __AVX512__
19
+ #ifdef __AVX512F__
20
20
 
21
21
  namespace faiss {
22
22
 
@@ -28,7 +28,7 @@ bool exhaustive_L2sqr_fused_cmax_AVX512(
28
28
  size_t d,
29
29
  size_t nx,
30
30
  size_t ny,
31
- SingleBestResultHandler<CMax<float, int64_t>>& res,
31
+ Top1BlockResultHandler<CMax<float, int64_t>>& res,
32
32
  const float* y_norms);
33
33
 
34
34
  } // namespace faiss
@@ -20,14 +20,14 @@ bool exhaustive_L2sqr_fused_cmax(
20
20
  size_t d,
21
21
  size_t nx,
22
22
  size_t ny,
23
- SingleBestResultHandler<CMax<float, int64_t>>& res,
23
+ Top1BlockResultHandler<CMax<float, int64_t>>& res,
24
24
  const float* y_norms) {
25
25
  if (nx == 0 || ny == 0) {
26
26
  // nothing to do
27
27
  return true;
28
28
  }
29
29
 
30
- #ifdef __AVX512__
30
+ #ifdef __AVX512F__
31
31
  // avx512 kernel
32
32
  return exhaustive_L2sqr_fused_cmax_AVX512(x, y, d, nx, ny, res, y_norms);
33
33
  #elif defined(__AVX2__) || defined(__aarch64__)
@@ -34,7 +34,7 @@ bool exhaustive_L2sqr_fused_cmax(
34
34
  size_t d,
35
35
  size_t nx,
36
36
  size_t ny,
37
- SingleBestResultHandler<CMax<float, int64_t>>& res,
37
+ Top1BlockResultHandler<CMax<float, int64_t>>& res,
38
38
  const float* y_norms);
39
39
 
40
40
  } // namespace faiss
@@ -62,7 +62,7 @@ void kernel(
62
62
  const float* const __restrict y,
63
63
  const float* const __restrict y_transposed,
64
64
  const size_t ny,
65
- SingleBestResultHandler<CMax<float, int64_t>>& res,
65
+ Top1BlockResultHandler<CMax<float, int64_t>>& res,
66
66
  const float* __restrict y_norms,
67
67
  const size_t i) {
68
68
  const size_t ny_p =
@@ -73,7 +73,7 @@ void kernel(
73
73
 
74
74
  // prefetch the next point
75
75
  #if defined(__AVX2__)
76
- _mm_prefetch(xd_0 + DIM * sizeof(float), _MM_HINT_NTA);
76
+ _mm_prefetch((const char*)(xd_0 + DIM * sizeof(float)), _MM_HINT_NTA);
77
77
  #endif
78
78
 
79
79
  // load a single point from x
@@ -226,7 +226,7 @@ void exhaustive_L2sqr_fused_cmax(
226
226
  const float* const __restrict y,
227
227
  size_t nx,
228
228
  size_t ny,
229
- SingleBestResultHandler<CMax<float, int64_t>>& res,
229
+ Top1BlockResultHandler<CMax<float, int64_t>>& res,
230
230
  const float* __restrict y_norms) {
231
231
  // BLAS does not like empty matrices
232
232
  if (nx == 0 || ny == 0) {
@@ -270,7 +270,7 @@ void exhaustive_L2sqr_fused_cmax(
270
270
  x, y, y_transposed.data(), ny, res, y_norms, i);
271
271
  }
272
272
 
273
- // Does nothing for SingleBestResultHandler, but
273
+ // Does nothing for Top1BlockResultHandler, but
274
274
  // keeping the call for the consistency.
275
275
  res.end_multiple();
276
276
  InterruptCallback::check();
@@ -284,7 +284,7 @@ bool exhaustive_L2sqr_fused_cmax_simdlib(
284
284
  size_t d,
285
285
  size_t nx,
286
286
  size_t ny,
287
- SingleBestResultHandler<CMax<float, int64_t>>& res,
287
+ Top1BlockResultHandler<CMax<float, int64_t>>& res,
288
288
  const float* y_norms) {
289
289
  // Process only cases with certain dimensionalities.
290
290
  // An acceptable dimensionality value is limited by the number of
@@ -24,7 +24,7 @@ bool exhaustive_L2sqr_fused_cmax_simdlib(
24
24
  size_t d,
25
25
  size_t nx,
26
26
  size_t ny,
27
- SingleBestResultHandler<CMax<float, int64_t>>& res,
27
+ Top1BlockResultHandler<CMax<float, int64_t>>& res,
28
28
  const float* y_norms);
29
29
 
30
30
  } // namespace faiss