faiss 0.1.2 → 0.1.3

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 (192) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/ext/faiss/extconf.rb +1 -1
  4. data/lib/faiss/version.rb +1 -1
  5. data/vendor/faiss/benchs/bench_6bit_codec.cpp +80 -0
  6. data/vendor/faiss/c_api/AutoTune_c.h +2 -0
  7. data/vendor/faiss/c_api/IndexShards_c.cpp +0 -6
  8. data/vendor/faiss/c_api/IndexShards_c.h +1 -4
  9. data/vendor/faiss/c_api/gpu/GpuAutoTune_c.cpp +4 -2
  10. data/vendor/faiss/c_api/gpu/GpuClonerOptions_c.cpp +1 -1
  11. data/vendor/faiss/c_api/gpu/GpuIndex_c.cpp +1 -1
  12. data/vendor/faiss/c_api/gpu/GpuResources_c.cpp +1 -1
  13. data/vendor/faiss/c_api/gpu/StandardGpuResources_c.cpp +1 -1
  14. data/vendor/faiss/demos/demo_imi_flat.cpp +5 -2
  15. data/vendor/faiss/demos/demo_imi_pq.cpp +6 -2
  16. data/vendor/faiss/demos/demo_ivfpq_indexing.cpp +7 -2
  17. data/vendor/faiss/{AutoTune.cpp → faiss/AutoTune.cpp} +9 -9
  18. data/vendor/faiss/{AutoTune.h → faiss/AutoTune.h} +0 -0
  19. data/vendor/faiss/{Clustering.cpp → faiss/Clustering.cpp} +13 -12
  20. data/vendor/faiss/{Clustering.h → faiss/Clustering.h} +0 -0
  21. data/vendor/faiss/{DirectMap.cpp → faiss/DirectMap.cpp} +0 -0
  22. data/vendor/faiss/{DirectMap.h → faiss/DirectMap.h} +0 -0
  23. data/vendor/faiss/{IVFlib.cpp → faiss/IVFlib.cpp} +86 -11
  24. data/vendor/faiss/{IVFlib.h → faiss/IVFlib.h} +26 -8
  25. data/vendor/faiss/{Index.cpp → faiss/Index.cpp} +0 -0
  26. data/vendor/faiss/{Index.h → faiss/Index.h} +1 -1
  27. data/vendor/faiss/{Index2Layer.cpp → faiss/Index2Layer.cpp} +12 -11
  28. data/vendor/faiss/{Index2Layer.h → faiss/Index2Layer.h} +0 -0
  29. data/vendor/faiss/{IndexBinary.cpp → faiss/IndexBinary.cpp} +2 -1
  30. data/vendor/faiss/{IndexBinary.h → faiss/IndexBinary.h} +0 -0
  31. data/vendor/faiss/{IndexBinaryFlat.cpp → faiss/IndexBinaryFlat.cpp} +0 -0
  32. data/vendor/faiss/{IndexBinaryFlat.h → faiss/IndexBinaryFlat.h} +0 -0
  33. data/vendor/faiss/{IndexBinaryFromFloat.cpp → faiss/IndexBinaryFromFloat.cpp} +1 -0
  34. data/vendor/faiss/{IndexBinaryFromFloat.h → faiss/IndexBinaryFromFloat.h} +0 -0
  35. data/vendor/faiss/{IndexBinaryHNSW.cpp → faiss/IndexBinaryHNSW.cpp} +1 -2
  36. data/vendor/faiss/{IndexBinaryHNSW.h → faiss/IndexBinaryHNSW.h} +0 -0
  37. data/vendor/faiss/{IndexBinaryHash.cpp → faiss/IndexBinaryHash.cpp} +16 -7
  38. data/vendor/faiss/{IndexBinaryHash.h → faiss/IndexBinaryHash.h} +2 -1
  39. data/vendor/faiss/{IndexBinaryIVF.cpp → faiss/IndexBinaryIVF.cpp} +10 -16
  40. data/vendor/faiss/{IndexBinaryIVF.h → faiss/IndexBinaryIVF.h} +1 -1
  41. data/vendor/faiss/{IndexFlat.cpp → faiss/IndexFlat.cpp} +0 -0
  42. data/vendor/faiss/{IndexFlat.h → faiss/IndexFlat.h} +0 -0
  43. data/vendor/faiss/{IndexHNSW.cpp → faiss/IndexHNSW.cpp} +63 -32
  44. data/vendor/faiss/{IndexHNSW.h → faiss/IndexHNSW.h} +0 -0
  45. data/vendor/faiss/{IndexIVF.cpp → faiss/IndexIVF.cpp} +129 -46
  46. data/vendor/faiss/{IndexIVF.h → faiss/IndexIVF.h} +7 -3
  47. data/vendor/faiss/{IndexIVFFlat.cpp → faiss/IndexIVFFlat.cpp} +6 -5
  48. data/vendor/faiss/{IndexIVFFlat.h → faiss/IndexIVFFlat.h} +0 -0
  49. data/vendor/faiss/{IndexIVFPQ.cpp → faiss/IndexIVFPQ.cpp} +9 -8
  50. data/vendor/faiss/{IndexIVFPQ.h → faiss/IndexIVFPQ.h} +4 -2
  51. data/vendor/faiss/{IndexIVFPQR.cpp → faiss/IndexIVFPQR.cpp} +3 -1
  52. data/vendor/faiss/{IndexIVFPQR.h → faiss/IndexIVFPQR.h} +0 -0
  53. data/vendor/faiss/{IndexIVFSpectralHash.cpp → faiss/IndexIVFSpectralHash.cpp} +1 -1
  54. data/vendor/faiss/{IndexIVFSpectralHash.h → faiss/IndexIVFSpectralHash.h} +0 -0
  55. data/vendor/faiss/{IndexLSH.cpp → faiss/IndexLSH.cpp} +0 -0
  56. data/vendor/faiss/{IndexLSH.h → faiss/IndexLSH.h} +0 -0
  57. data/vendor/faiss/{IndexLattice.cpp → faiss/IndexLattice.cpp} +0 -0
  58. data/vendor/faiss/{IndexLattice.h → faiss/IndexLattice.h} +0 -0
  59. data/vendor/faiss/{IndexPQ.cpp → faiss/IndexPQ.cpp} +6 -6
  60. data/vendor/faiss/{IndexPQ.h → faiss/IndexPQ.h} +3 -1
  61. data/vendor/faiss/{IndexPreTransform.cpp → faiss/IndexPreTransform.cpp} +0 -0
  62. data/vendor/faiss/{IndexPreTransform.h → faiss/IndexPreTransform.h} +0 -0
  63. data/vendor/faiss/{IndexReplicas.cpp → faiss/IndexReplicas.cpp} +102 -10
  64. data/vendor/faiss/{IndexReplicas.h → faiss/IndexReplicas.h} +6 -0
  65. data/vendor/faiss/{IndexScalarQuantizer.cpp → faiss/IndexScalarQuantizer.cpp} +3 -3
  66. data/vendor/faiss/{IndexScalarQuantizer.h → faiss/IndexScalarQuantizer.h} +0 -0
  67. data/vendor/faiss/{IndexShards.cpp → faiss/IndexShards.cpp} +37 -12
  68. data/vendor/faiss/{IndexShards.h → faiss/IndexShards.h} +3 -4
  69. data/vendor/faiss/{InvertedLists.cpp → faiss/InvertedLists.cpp} +2 -2
  70. data/vendor/faiss/{InvertedLists.h → faiss/InvertedLists.h} +1 -0
  71. data/vendor/faiss/{MatrixStats.cpp → faiss/MatrixStats.cpp} +0 -0
  72. data/vendor/faiss/{MatrixStats.h → faiss/MatrixStats.h} +0 -0
  73. data/vendor/faiss/{MetaIndexes.cpp → faiss/MetaIndexes.cpp} +5 -3
  74. data/vendor/faiss/{MetaIndexes.h → faiss/MetaIndexes.h} +0 -0
  75. data/vendor/faiss/{MetricType.h → faiss/MetricType.h} +0 -0
  76. data/vendor/faiss/{OnDiskInvertedLists.cpp → faiss/OnDiskInvertedLists.cpp} +141 -3
  77. data/vendor/faiss/{OnDiskInvertedLists.h → faiss/OnDiskInvertedLists.h} +27 -7
  78. data/vendor/faiss/{VectorTransform.cpp → faiss/VectorTransform.cpp} +4 -3
  79. data/vendor/faiss/{VectorTransform.h → faiss/VectorTransform.h} +0 -0
  80. data/vendor/faiss/{clone_index.cpp → faiss/clone_index.cpp} +0 -0
  81. data/vendor/faiss/{clone_index.h → faiss/clone_index.h} +0 -0
  82. data/vendor/faiss/{gpu → faiss/gpu}/GpuAutoTune.cpp +0 -0
  83. data/vendor/faiss/{gpu → faiss/gpu}/GpuAutoTune.h +0 -0
  84. data/vendor/faiss/{gpu → faiss/gpu}/GpuCloner.cpp +14 -14
  85. data/vendor/faiss/{gpu → faiss/gpu}/GpuCloner.h +6 -7
  86. data/vendor/faiss/{gpu → faiss/gpu}/GpuClonerOptions.cpp +0 -0
  87. data/vendor/faiss/{gpu → faiss/gpu}/GpuClonerOptions.h +0 -0
  88. data/vendor/faiss/{gpu → faiss/gpu}/GpuDistance.h +12 -4
  89. data/vendor/faiss/{gpu → faiss/gpu}/GpuFaissAssert.h +0 -0
  90. data/vendor/faiss/{gpu → faiss/gpu}/GpuIndex.h +3 -9
  91. data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexBinaryFlat.h +7 -7
  92. data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexFlat.h +35 -10
  93. data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexIVF.h +1 -2
  94. data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexIVFFlat.h +4 -3
  95. data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexIVFPQ.h +21 -4
  96. data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexIVFScalarQuantizer.h +4 -3
  97. data/vendor/faiss/{gpu → faiss/gpu}/GpuIndicesOptions.h +0 -0
  98. data/vendor/faiss/faiss/gpu/GpuResources.cpp +200 -0
  99. data/vendor/faiss/faiss/gpu/GpuResources.h +264 -0
  100. data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +572 -0
  101. data/vendor/faiss/{gpu → faiss/gpu}/StandardGpuResources.h +83 -15
  102. data/vendor/faiss/{gpu → faiss/gpu}/impl/RemapIndices.cpp +0 -0
  103. data/vendor/faiss/{gpu → faiss/gpu}/impl/RemapIndices.h +0 -0
  104. data/vendor/faiss/{gpu → faiss/gpu}/perf/IndexWrapper-inl.h +1 -1
  105. data/vendor/faiss/{gpu → faiss/gpu}/perf/IndexWrapper.h +1 -1
  106. data/vendor/faiss/{gpu → faiss/gpu}/perf/PerfClustering.cpp +1 -1
  107. data/vendor/faiss/{gpu → faiss/gpu}/perf/PerfIVFPQAdd.cpp +0 -0
  108. data/vendor/faiss/{gpu → faiss/gpu}/perf/WriteIndex.cpp +0 -0
  109. data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuIndexBinaryFlat.cpp +0 -0
  110. data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuIndexFlat.cpp +1 -1
  111. data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuIndexIVFFlat.cpp +0 -0
  112. data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuIndexIVFPQ.cpp +141 -52
  113. data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuMemoryException.cpp +0 -0
  114. data/vendor/faiss/{gpu → faiss/gpu}/test/TestUtils.cpp +4 -2
  115. data/vendor/faiss/{gpu → faiss/gpu}/test/TestUtils.h +0 -0
  116. data/vendor/faiss/{gpu → faiss/gpu}/test/demo_ivfpq_indexing_gpu.cpp +7 -5
  117. data/vendor/faiss/{gpu → faiss/gpu}/utils/DeviceUtils.h +1 -1
  118. data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +213 -0
  119. data/vendor/faiss/{gpu → faiss/gpu}/utils/StackDeviceMemory.h +25 -40
  120. data/vendor/faiss/{gpu → faiss/gpu}/utils/StaticUtils.h +0 -0
  121. data/vendor/faiss/{gpu → faiss/gpu}/utils/Timer.cpp +0 -0
  122. data/vendor/faiss/{gpu → faiss/gpu}/utils/Timer.h +0 -0
  123. data/vendor/faiss/{impl → faiss/impl}/AuxIndexStructures.cpp +1 -0
  124. data/vendor/faiss/{impl → faiss/impl}/AuxIndexStructures.h +3 -1
  125. data/vendor/faiss/{impl → faiss/impl}/FaissAssert.h +1 -0
  126. data/vendor/faiss/{impl → faiss/impl}/FaissException.cpp +26 -0
  127. data/vendor/faiss/{impl → faiss/impl}/FaissException.h +4 -0
  128. data/vendor/faiss/{impl → faiss/impl}/HNSW.cpp +26 -26
  129. data/vendor/faiss/{impl → faiss/impl}/HNSW.h +19 -11
  130. data/vendor/faiss/{impl → faiss/impl}/PolysemousTraining.cpp +1 -1
  131. data/vendor/faiss/{impl → faiss/impl}/PolysemousTraining.h +1 -1
  132. data/vendor/faiss/{impl → faiss/impl}/ProductQuantizer-inl.h +0 -1
  133. data/vendor/faiss/{impl → faiss/impl}/ProductQuantizer.cpp +9 -9
  134. data/vendor/faiss/{impl → faiss/impl}/ProductQuantizer.h +0 -0
  135. data/vendor/faiss/{impl → faiss/impl}/ScalarQuantizer.cpp +63 -39
  136. data/vendor/faiss/{impl → faiss/impl}/ScalarQuantizer.h +1 -1
  137. data/vendor/faiss/{impl → faiss/impl}/ThreadedIndex-inl.h +0 -0
  138. data/vendor/faiss/{impl → faiss/impl}/ThreadedIndex.h +0 -0
  139. data/vendor/faiss/{impl → faiss/impl}/index_read.cpp +99 -116
  140. data/vendor/faiss/{impl → faiss/impl}/index_write.cpp +15 -50
  141. data/vendor/faiss/{impl → faiss/impl}/io.cpp +15 -10
  142. data/vendor/faiss/{impl → faiss/impl}/io.h +22 -8
  143. data/vendor/faiss/faiss/impl/io_macros.h +57 -0
  144. data/vendor/faiss/{impl → faiss/impl}/lattice_Zn.cpp +52 -36
  145. data/vendor/faiss/{impl → faiss/impl}/lattice_Zn.h +3 -3
  146. data/vendor/faiss/faiss/impl/platform_macros.h +24 -0
  147. data/vendor/faiss/{index_factory.cpp → faiss/index_factory.cpp} +33 -12
  148. data/vendor/faiss/{index_factory.h → faiss/index_factory.h} +0 -0
  149. data/vendor/faiss/{index_io.h → faiss/index_io.h} +55 -1
  150. data/vendor/faiss/faiss/python/python_callbacks.cpp +112 -0
  151. data/vendor/faiss/faiss/python/python_callbacks.h +45 -0
  152. data/vendor/faiss/{utils → faiss/utils}/Heap.cpp +5 -5
  153. data/vendor/faiss/{utils → faiss/utils}/Heap.h +1 -3
  154. data/vendor/faiss/{utils → faiss/utils}/WorkerThread.cpp +0 -0
  155. data/vendor/faiss/{utils → faiss/utils}/WorkerThread.h +0 -0
  156. data/vendor/faiss/{utils → faiss/utils}/distances.cpp +28 -13
  157. data/vendor/faiss/{utils → faiss/utils}/distances.h +2 -1
  158. data/vendor/faiss/{utils → faiss/utils}/distances_simd.cpp +5 -5
  159. data/vendor/faiss/{utils → faiss/utils}/extra_distances.cpp +8 -7
  160. data/vendor/faiss/{utils → faiss/utils}/extra_distances.h +0 -0
  161. data/vendor/faiss/{utils → faiss/utils}/hamming-inl.h +1 -3
  162. data/vendor/faiss/{utils → faiss/utils}/hamming.cpp +8 -7
  163. data/vendor/faiss/{utils → faiss/utils}/hamming.h +7 -1
  164. data/vendor/faiss/{utils → faiss/utils}/random.cpp +5 -5
  165. data/vendor/faiss/{utils → faiss/utils}/random.h +0 -0
  166. data/vendor/faiss/{utils → faiss/utils}/utils.cpp +27 -28
  167. data/vendor/faiss/{utils → faiss/utils}/utils.h +4 -0
  168. data/vendor/faiss/misc/test_blas.cpp +4 -1
  169. data/vendor/faiss/tests/test_binary_flat.cpp +0 -2
  170. data/vendor/faiss/tests/test_dealloc_invlists.cpp +6 -1
  171. data/vendor/faiss/tests/test_ivfpq_codec.cpp +4 -1
  172. data/vendor/faiss/tests/test_ivfpq_indexing.cpp +6 -4
  173. data/vendor/faiss/tests/test_lowlevel_ivf.cpp +12 -5
  174. data/vendor/faiss/tests/test_merge.cpp +6 -3
  175. data/vendor/faiss/tests/test_ondisk_ivf.cpp +7 -2
  176. data/vendor/faiss/tests/test_pairs_decoding.cpp +5 -1
  177. data/vendor/faiss/tests/test_params_override.cpp +7 -2
  178. data/vendor/faiss/tests/test_sliding_ivf.cpp +10 -4
  179. data/vendor/faiss/tutorial/cpp/1-Flat.cpp +14 -8
  180. data/vendor/faiss/tutorial/cpp/2-IVFFlat.cpp +11 -7
  181. data/vendor/faiss/tutorial/cpp/3-IVFPQ.cpp +12 -7
  182. data/vendor/faiss/tutorial/cpp/4-GPU.cpp +6 -3
  183. data/vendor/faiss/tutorial/cpp/5-Multiple-GPUs.cpp +7 -3
  184. metadata +154 -153
  185. data/vendor/faiss/gpu/GpuResources.cpp +0 -52
  186. data/vendor/faiss/gpu/GpuResources.h +0 -73
  187. data/vendor/faiss/gpu/StandardGpuResources.cpp +0 -303
  188. data/vendor/faiss/gpu/utils/DeviceMemory.cpp +0 -77
  189. data/vendor/faiss/gpu/utils/DeviceMemory.h +0 -71
  190. data/vendor/faiss/gpu/utils/MemorySpace.cpp +0 -89
  191. data/vendor/faiss/gpu/utils/MemorySpace.h +0 -44
  192. data/vendor/faiss/gpu/utils/StackDeviceMemory.cpp +0 -239
@@ -14,7 +14,7 @@
14
14
  #include <cstring>
15
15
  #include <cmath>
16
16
 
17
- #ifdef __SSE__
17
+ #ifdef __SSE3__
18
18
  #include <immintrin.h>
19
19
  #endif
20
20
 
@@ -133,7 +133,7 @@ void fvec_L2sqr_ny_ref (float * dis,
133
133
  * SSE and AVX implementations
134
134
  */
135
135
 
136
- #ifdef __SSE__
136
+ #ifdef __SSE3__
137
137
 
138
138
  // reads 0 <= d < 4 floats as __m128
139
139
  static inline __m128 masked_read (int d, const float *x)
@@ -477,7 +477,7 @@ float fvec_Linf (const float * x, const float * y, size_t d)
477
477
  return _mm_cvtss_f32 (msum2);
478
478
  }
479
479
 
480
- #elif defined(__SSE__) // But not AVX
480
+ #elif defined(__SSE3__) // But not AVX
481
481
 
482
482
  float fvec_L1 (const float * x, const float * y, size_t d)
483
483
  {
@@ -677,7 +677,7 @@ static inline void fvec_madd_ref (size_t n, const float *a,
677
677
  c[i] = a[i] + bf * b[i];
678
678
  }
679
679
 
680
- #ifdef __SSE__
680
+ #ifdef __SSE3__
681
681
 
682
682
  static inline void fvec_madd_sse (size_t n, const float *a,
683
683
  float bf, const float *b, float *c) {
@@ -730,7 +730,7 @@ static inline int fvec_madd_and_argmin_ref (size_t n, const float *a,
730
730
  return imin;
731
731
  }
732
732
 
733
- #ifdef __SSE__
733
+ #ifdef __SSE3__
734
734
 
735
735
  static inline int fvec_madd_and_argmin_sse (
736
736
  size_t n, const float *a,
@@ -9,6 +9,7 @@
9
9
 
10
10
  #include <faiss/utils/distances.h>
11
11
 
12
+ #include <algorithm>
12
13
  #include <cmath>
13
14
  #include <omp.h>
14
15
 
@@ -163,7 +164,7 @@ void knn_extra_metrics_template (
163
164
  size_t i1 = std::min(i0 + check_period, nx);
164
165
 
165
166
  #pragma omp parallel for
166
- for (size_t i = i0; i < i1; i++) {
167
+ for (int64_t i = i0; i < i1; i++) {
167
168
  const float * x_i = x + i * d;
168
169
  const float * y_j = y;
169
170
  size_t j;
@@ -245,7 +246,7 @@ void pairwise_extra_distances (
245
246
  switch(mt) {
246
247
  #define HANDLE_VAR(kw) \
247
248
  case METRIC_ ## kw: { \
248
- VectorDistance ## kw vd({(size_t)d}); \
249
+ VectorDistance ## kw vd = {(size_t)d}; \
249
250
  pairwise_extra_distances_template (vd, nq, xq, nb, xb, \
250
251
  dis, ldq, ldb, ldd); \
251
252
  break; \
@@ -258,7 +259,7 @@ void pairwise_extra_distances (
258
259
  HANDLE_VAR(JensenShannon);
259
260
  #undef HANDLE_VAR
260
261
  case METRIC_Lp: {
261
- VectorDistanceLp vd({(size_t)d, metric_arg});
262
+ VectorDistanceLp vd = {(size_t)d, metric_arg};
262
263
  pairwise_extra_distances_template (vd, nq, xq, nb, xb,
263
264
  dis, ldq, ldb, ldd);
264
265
  break;
@@ -280,7 +281,7 @@ void knn_extra_metrics (
280
281
  switch(mt) {
281
282
  #define HANDLE_VAR(kw) \
282
283
  case METRIC_ ## kw: { \
283
- VectorDistance ## kw vd({(size_t)d}); \
284
+ VectorDistance ## kw vd = {(size_t)d}; \
284
285
  knn_extra_metrics_template (vd, x, y, nx, ny, res); \
285
286
  break; \
286
287
  }
@@ -292,7 +293,7 @@ void knn_extra_metrics (
292
293
  HANDLE_VAR(JensenShannon);
293
294
  #undef HANDLE_VAR
294
295
  case METRIC_Lp: {
295
- VectorDistanceLp vd({(size_t)d, metric_arg});
296
+ VectorDistanceLp vd = {(size_t)d, metric_arg};
296
297
  knn_extra_metrics_template (vd, x, y, nx, ny, res);
297
298
  break;
298
299
  }
@@ -311,7 +312,7 @@ DistanceComputer *get_extra_distance_computer (
311
312
  switch(mt) {
312
313
  #define HANDLE_VAR(kw) \
313
314
  case METRIC_ ## kw: { \
314
- VectorDistance ## kw vd({(size_t)d}); \
315
+ VectorDistance ## kw vd = {(size_t)d}; \
315
316
  return new ExtraDistanceComputer<VectorDistance ## kw>(vd, xb, nb); \
316
317
  }
317
318
  HANDLE_VAR(L2);
@@ -322,7 +323,7 @@ DistanceComputer *get_extra_distance_computer (
322
323
  HANDLE_VAR(JensenShannon);
323
324
  #undef HANDLE_VAR
324
325
  case METRIC_Lp: {
325
- VectorDistanceLp vd({(size_t)d, metric_arg});
326
+ VectorDistanceLp vd = {(size_t)d, metric_arg};
326
327
  return new ExtraDistanceComputer<VectorDistanceLp> (vd, xb, nb);
327
328
  break;
328
329
  }
@@ -5,15 +5,13 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
-
9
-
10
8
  namespace faiss {
11
9
 
12
10
 
13
11
  inline BitstringWriter::BitstringWriter(uint8_t *code, int code_size):
14
12
  code (code), code_size (code_size), i(0)
15
13
  {
16
- bzero (code, code_size);
14
+ memset (code, 0, code_size);
17
15
  }
18
16
 
19
17
  inline void BitstringWriter::write(uint64_t x, int nbit) {
@@ -26,6 +26,7 @@
26
26
 
27
27
  #include <faiss/utils/hamming.h>
28
28
 
29
+ #include <algorithm>
29
30
  #include <vector>
30
31
  #include <memory>
31
32
  #include <stdio.h>
@@ -280,7 +281,7 @@ void hammings_knn_hc (
280
281
  for (size_t j0 = 0; j0 < n2; j0 += block_size) {
281
282
  const size_t j1 = std::min(j0 + block_size, n2);
282
283
  #pragma omp parallel for
283
- for (size_t i = 0; i < ha->nh; i++) {
284
+ for (int64_t i = 0; i < ha->nh; i++) {
284
285
  HammingComputer hc (bs1 + i * bytes_per_code, bytes_per_code);
285
286
 
286
287
  const uint8_t * bs2_ = bs2 + j0 * bytes_per_code;
@@ -332,7 +333,7 @@ void hammings_knn_mc (
332
333
  for (size_t j0 = 0; j0 < nb; j0 += block_size) {
333
334
  const size_t j1 = std::min(j0 + block_size, nb);
334
335
  #pragma omp parallel for
335
- for (size_t i = 0; i < na; ++i) {
336
+ for (int64_t i = 0; i < na; ++i) {
336
337
  for (size_t j = j0; j < j1; ++j) {
337
338
  cs[i].update_counter(b + j * bytes_per_code, j);
338
339
  }
@@ -379,7 +380,7 @@ void hammings_knn_hc_1 (
379
380
  }
380
381
 
381
382
  #pragma omp parallel for
382
- for (size_t i = 0; i < ha->nh; i++) {
383
+ for (int64_t i = 0; i < ha->nh; i++) {
383
384
  const uint64_t bs1_ = bs1 [i];
384
385
  const uint64_t * bs2_ = bs2;
385
386
  hamdis_t dis;
@@ -435,7 +436,7 @@ void fvecs2bitvecs (const float * x, uint8_t * b, size_t d, size_t n)
435
436
  {
436
437
  const int64_t ncodes = ((d + 7) / 8);
437
438
  #pragma omp parallel for if(n > 100000)
438
- for (size_t i = 0; i < n; i++)
439
+ for (int64_t i = 0; i < n; i++)
439
440
  fvec2bitvec (x + i * d, b + i * ncodes, d);
440
441
  }
441
442
 
@@ -449,7 +450,7 @@ void bitvecs2fvecs (
449
450
 
450
451
  const int64_t ncodes = ((d + 7) / 8);
451
452
  #pragma omp parallel for if(n > 100000)
452
- for (size_t i = 0; i < n; i++) {
453
+ for (int64_t i = 0; i < n; i++) {
453
454
  binary_to_real (d, b + i * ncodes, x + i * d);
454
455
  }
455
456
  }
@@ -497,7 +498,7 @@ void bitvec_shuffle (size_t n, size_t da, size_t db,
497
498
  size_t ldb = (db + 7) / 8;
498
499
 
499
500
  #pragma omp parallel for if(n > 10000)
500
- for (size_t i = 0; i < n; i++) {
501
+ for (int64_t i = 0; i < n; i++) {
501
502
  const uint8_t *ai = a + i * lda;
502
503
  uint8_t *bi = b + i * ldb;
503
504
  memset (bi, 0, ldb);
@@ -653,7 +654,7 @@ void hamming_range_search_template (
653
654
  RangeSearchPartialResult pres (res);
654
655
 
655
656
  #pragma omp for
656
- for (size_t i = 0; i < na; i++) {
657
+ for (int64_t i = 0; i < na; i++) {
657
658
  HammingComputer hc (a + i * code_size, code_size);
658
659
  const uint8_t * yi = b;
659
660
  RangeQueryResult & qres = pres.new_result (i);
@@ -27,6 +27,12 @@
27
27
 
28
28
  #include <stdint.h>
29
29
 
30
+ #ifdef _MSC_VER
31
+ #include <intrin.h>
32
+ #define __builtin_popcountl __popcnt64
33
+ #endif // _MSC_VER
34
+
35
+ #include <faiss/impl/platform_macros.h>
30
36
  #include <faiss/utils/Heap.h>
31
37
 
32
38
 
@@ -109,7 +115,7 @@ struct BitstringReader {
109
115
 
110
116
 
111
117
 
112
- extern size_t hamming_batch_size;
118
+ FAISS_API extern size_t hamming_batch_size;
113
119
 
114
120
  inline int popcount64(uint64_t x) {
115
121
  return __builtin_popcountl(x);
@@ -61,7 +61,7 @@ void float_rand (float * x, size_t n, int64_t seed)
61
61
  int a0 = rng0.rand_int (), b0 = rng0.rand_int ();
62
62
 
63
63
  #pragma omp parallel for
64
- for (size_t j = 0; j < nblock; j++) {
64
+ for (int64_t j = 0; j < nblock; j++) {
65
65
 
66
66
  RandomGenerator rng (a0 + j * b0);
67
67
 
@@ -83,7 +83,7 @@ void float_randn (float * x, size_t n, int64_t seed)
83
83
  int a0 = rng0.rand_int (), b0 = rng0.rand_int ();
84
84
 
85
85
  #pragma omp parallel for
86
- for (size_t j = 0; j < nblock; j++) {
86
+ for (int64_t j = 0; j < nblock; j++) {
87
87
  RandomGenerator rng (a0 + j * b0);
88
88
 
89
89
  double a = 0, b = 0, s = 0;
@@ -120,7 +120,7 @@ void int64_rand (int64_t * x, size_t n, int64_t seed)
120
120
  int a0 = rng0.rand_int (), b0 = rng0.rand_int ();
121
121
 
122
122
  #pragma omp parallel for
123
- for (size_t j = 0; j < nblock; j++) {
123
+ for (int64_t j = 0; j < nblock; j++) {
124
124
 
125
125
  RandomGenerator rng (a0 + j * b0);
126
126
 
@@ -140,7 +140,7 @@ void int64_rand_max (int64_t * x, size_t n, uint64_t max, int64_t seed)
140
140
  int a0 = rng0.rand_int (), b0 = rng0.rand_int ();
141
141
 
142
142
  #pragma omp parallel for
143
- for (size_t j = 0; j < nblock; j++) {
143
+ for (int64_t j = 0; j < nblock; j++) {
144
144
 
145
145
  RandomGenerator rng (a0 + j * b0);
146
146
 
@@ -176,7 +176,7 @@ void byte_rand (uint8_t * x, size_t n, int64_t seed)
176
176
  int a0 = rng0.rand_int (), b0 = rng0.rand_int ();
177
177
 
178
178
  #pragma omp parallel for
179
- for (size_t j = 0; j < nblock; j++) {
179
+ for (int64_t j = 0; j < nblock; j++) {
180
180
 
181
181
  RandomGenerator rng (a0 + j * b0);
182
182
 
@@ -14,9 +14,16 @@
14
14
  #include <cstring>
15
15
  #include <cmath>
16
16
 
17
- #include <sys/time.h>
18
17
  #include <sys/types.h>
18
+
19
+ #ifdef _MSC_VER
20
+ #define NOMINMAX
21
+ #include <windows.h>
22
+ #undef NOMINMAX
23
+ #else
24
+ #include <sys/time.h>
19
25
  #include <unistd.h>
26
+ #endif // !_MSC_VER
20
27
 
21
28
  #include <omp.h>
22
29
 
@@ -65,11 +72,22 @@ int sgemv_(const char *trans, FINTEGER *m, FINTEGER *n, float *alpha,
65
72
 
66
73
  namespace faiss {
67
74
 
75
+ #ifdef _MSC_VER
76
+ double getmillisecs() {
77
+ LARGE_INTEGER ts;
78
+ LARGE_INTEGER freq;
79
+ QueryPerformanceFrequency(&freq);
80
+ QueryPerformanceCounter(&ts);
81
+
82
+ return (ts.QuadPart * 1e3) / freq.QuadPart;
83
+ }
84
+ #else // _MSC_VER
68
85
  double getmillisecs () {
69
86
  struct timeval tv;
70
87
  gettimeofday (&tv, nullptr);
71
88
  return tv.tv_sec * 1e3 + tv.tv_usec * 1e-3;
72
89
  }
90
+ #endif // _MSC_VER
73
91
 
74
92
  uint64_t get_cycles () {
75
93
  #ifdef __x86_64__
@@ -103,11 +121,11 @@ size_t get_mem_usage_kb ()
103
121
  return sz;
104
122
  }
105
123
 
106
- #elif __APPLE__
124
+ #else
107
125
 
108
126
  size_t get_mem_usage_kb ()
109
127
  {
110
- fprintf(stderr, "WARN: get_mem_usage_kb not implemented on the mac\n");
128
+ fprintf(stderr, "WARN: get_mem_usage_kb not implemented on current architecture\n");
111
129
  return 0;
112
130
  }
113
131
 
@@ -173,25 +191,6 @@ void reflection_ref (const float * u, float * x, size_t n, size_t d, size_t nu)
173
191
  * Some matrix manipulation functions
174
192
  ***************************************************************************/
175
193
 
176
-
177
- /* This function exists because the Torch counterpart is extremly slow
178
- (not multi-threaded + unexpected overhead even in single thread).
179
- It is here to implement the usual property |x-y|^2=|x|^2+|y|^2-2<x|y> */
180
- void inner_product_to_L2sqr (float * __restrict dis,
181
- const float * nr1,
182
- const float * nr2,
183
- size_t n1, size_t n2)
184
- {
185
-
186
- #pragma omp parallel for
187
- for (size_t j = 0 ; j < n1 ; j++) {
188
- float * disj = dis + j * n2;
189
- for (size_t i = 0 ; i < n2 ; i++)
190
- disj[i] = nr1[j] + nr2[i] - 2 * disj[i];
191
- }
192
- }
193
-
194
-
195
194
  void matrix_qr (int m, int n, float *a)
196
195
  {
197
196
  FAISS_THROW_IF_NOT (m >= n);
@@ -251,7 +250,7 @@ size_t merge_result_table_with (size_t n, size_t k,
251
250
  std::vector<float> tmpD (k);
252
251
 
253
252
  #pragma omp for
254
- for (size_t i = 0; i < n; i++) {
253
+ for (int64_t i = 0; i < n; i++) {
255
254
  int64_t *lI0 = I0 + i * k;
256
255
  float *lD0 = D0 + i * k;
257
256
  const int64_t *lI1 = I1 + i * k;
@@ -319,7 +318,7 @@ size_t ranklist_intersection_size (size_t k1, const int64_t *v1,
319
318
  }
320
319
  k2 = wp;
321
320
  }
322
- const int64_t seen_flag = 1L << 60;
321
+ const int64_t seen_flag = int64_t{1} << 60;
323
322
  size_t count = 0;
324
323
  for (size_t i = 0; i < k1; i++) {
325
324
  int64_t q = v1 [i];
@@ -436,7 +435,7 @@ namespace {
436
435
  }
437
436
 
438
437
  // compute sub-ranges for each thread
439
- SegmentS s1s[nt], s2s[nt], sws[nt];
438
+ std::vector<SegmentS> s1s(nt), s2s(nt), sws(nt);
440
439
  s2s[0].i0 = s2.i0;
441
440
  s2s[nt - 1].i1 = s2.i1;
442
441
 
@@ -529,7 +528,7 @@ void fvec_argsort_parallel (size_t n, const float *vals,
529
528
 
530
529
  ArgsortComparator comp = {vals};
531
530
 
532
- SegmentS segs[nt];
531
+ std::vector<SegmentS> segs(nt);
533
532
 
534
533
  // independent sorts
535
534
  #pragma omp parallel for
@@ -598,8 +597,8 @@ const float *fvecs_maybe_subsample (
598
597
 
599
598
  size_t n2 = nmax;
600
599
  if (verbose) {
601
- printf (" Input training set too big (max size is %ld), sampling "
602
- "%ld / %ld vectors\n", nmax, n2, *n);
600
+ printf (" Input training set too big (max size is %zd), sampling "
601
+ "%zd / %zd vectors\n", nmax, n2, *n);
603
602
  }
604
603
  std::vector<int> subset (*n);
605
604
  rand_perm (subset.data (), *n, seed);
@@ -18,6 +18,10 @@
18
18
 
19
19
  #include <stdint.h>
20
20
 
21
+ #ifdef _MSC_VER
22
+ #define strtok_r strtok_s
23
+ #endif // _MSC_VER
24
+
21
25
  #include <faiss/utils/Heap.h>
22
26
 
23
27
 
@@ -7,6 +7,7 @@
7
7
 
8
8
  #include <cstdio>
9
9
  #include <cstdlib>
10
+ #include <random>
10
11
 
11
12
  #undef FINTEGER
12
13
  #define FINTEGER long
@@ -31,8 +32,10 @@ int sgeqrf_ (FINTEGER *m, FINTEGER *n, float *a, FINTEGER *lda,
31
32
  float *new_random_vec(int size)
32
33
  {
33
34
  float *x = new float[size];
35
+ std::mt19937 rng;
36
+ std::uniform_real_distribution<> distrib;
34
37
  for (int i = 0; i < size; i++)
35
- x[i] = drand48();
38
+ x[i] = distrib(rng);
36
39
  return x;
37
40
  }
38
41
 
@@ -23,8 +23,6 @@ TEST(BinaryFlat, accuracy) {
23
23
  // make the index object and train it
24
24
  faiss::IndexBinaryFlat index(d);
25
25
 
26
- srand(35);
27
-
28
26
  std::vector<uint8_t> database(nb * (d / 8));
29
27
  for (size_t i = 0; i < nb * (d / 8); i++) {
30
28
  database[i] = rand() % 0x100;
@@ -10,6 +10,7 @@
10
10
 
11
11
  #include <memory>
12
12
  #include <vector>
13
+ #include <random>
13
14
 
14
15
  #include <gtest/gtest.h>
15
16
 
@@ -19,6 +20,7 @@
19
20
  #include <faiss/index_io.h>
20
21
  #include <faiss/IVFlib.h>
21
22
 
23
+
22
24
  using namespace faiss;
23
25
 
24
26
  namespace {
@@ -38,12 +40,15 @@ size_t nb = 1000;
38
40
  // nb of queries
39
41
  size_t nq = 200;
40
42
 
43
+ std::mt19937 rng;
41
44
 
42
45
  std::vector<float> make_data(size_t n)
43
46
  {
44
47
  std::vector <float> database (n * d);
48
+ std::uniform_real_distribution<> distrib;
49
+
45
50
  for (size_t i = 0; i < n * d; i++) {
46
- database[i] = drand48();
51
+ database[i] = distrib(rng);
47
52
  }
48
53
  return database;
49
54
  }