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
@@ -7,6 +7,7 @@
7
7
 
8
8
  #include <cstdio>
9
9
  #include <cstdlib>
10
+ #include <random>
10
11
 
11
12
  #include <gtest/gtest.h>
12
13
 
@@ -51,8 +52,10 @@ double eval_codec_error (long ncentroids, long m, const std::vector<float> &v)
51
52
  TEST(IVFPQ, codec) {
52
53
 
53
54
  std::vector <float> database (nb * d);
55
+ std::mt19937 rng;
56
+ std::uniform_real_distribution<> distrib;
54
57
  for (size_t i = 0; i < nb * d; i++) {
55
- database[i] = drand48();
58
+ database[i] = distrib(rng);
56
59
  }
57
60
 
58
61
  double err0 = eval_codec_error(16, 8, database);
@@ -8,6 +8,7 @@
8
8
 
9
9
  #include <cstdio>
10
10
  #include <cstdlib>
11
+ #include <random>
11
12
 
12
13
  #include <gtest/gtest.h>
13
14
 
@@ -39,13 +40,14 @@ TEST(IVFPQ, accuracy) {
39
40
  // index that gives the ground-truth
40
41
  faiss::IndexFlatL2 index_gt (d);
41
42
 
42
- srand48 (35);
43
+ std::mt19937 rng;
44
+ std::uniform_real_distribution<> distrib;
43
45
 
44
46
  { // training
45
47
 
46
48
  std::vector <float> trainvecs (nt * d);
47
49
  for (size_t i = 0; i < nt * d; i++) {
48
- trainvecs[i] = drand48();
50
+ trainvecs[i] = distrib(rng);
49
51
  }
50
52
  index.verbose = true;
51
53
  index.train (nt, trainvecs.data());
@@ -55,7 +57,7 @@ TEST(IVFPQ, accuracy) {
55
57
 
56
58
  std::vector <float> database (nb * d);
57
59
  for (size_t i = 0; i < nb * d; i++) {
58
- database[i] = drand48();
60
+ database[i] = distrib(rng);
59
61
  }
60
62
 
61
63
  index.add (nb, database.data());
@@ -69,7 +71,7 @@ TEST(IVFPQ, accuracy) {
69
71
 
70
72
  std::vector <float> queries (nq * d);
71
73
  for (size_t i = 0; i < nq * d; i++) {
72
- queries[i] = drand48();
74
+ queries[i] = distrib(rng);
73
75
  }
74
76
 
75
77
  std::vector<faiss::Index::idx_t> gt_nns (nq);
@@ -5,12 +5,14 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
+ #include <cinttypes>
8
9
  #include <cstdio>
9
10
  #include <cstdlib>
10
11
 
11
12
  #include <memory>
12
13
  #include <vector>
13
14
  #include <thread>
15
+ #include <random>
14
16
 
15
17
  #include <gtest/gtest.h>
16
18
 
@@ -23,6 +25,7 @@
23
25
  #include <faiss/IVFlib.h>
24
26
  #include <faiss/VectorTransform.h>
25
27
 
28
+
26
29
  using namespace faiss;
27
30
 
28
31
  namespace {
@@ -44,12 +47,15 @@ size_t nq = 200;
44
47
 
45
48
  int k = 10;
46
49
 
50
+ std::mt19937 rng;
51
+
47
52
 
48
53
  std::vector<float> make_data(size_t n)
49
54
  {
50
55
  std::vector <float> database (n * d);
56
+ std::uniform_real_distribution<> distrib;
51
57
  for (size_t i = 0; i < n * d; i++) {
52
- database[i] = drand48();
58
+ database[i] = distrib(rng);
53
59
  }
54
60
  return database;
55
61
  }
@@ -273,8 +279,9 @@ std::vector<uint8_t> make_data_binary(size_t n)
273
279
  {
274
280
 
275
281
  std::vector <uint8_t> database (n * nbit / 8);
282
+ std::uniform_int_distribution<> distrib;
276
283
  for (size_t i = 0; i < n * d; i++) {
277
- database[i] = lrand48();
284
+ database[i] = distrib(rng);
278
285
  }
279
286
  return database;
280
287
  }
@@ -376,7 +383,7 @@ void test_lowlevel_access_binary (const char *index_key) {
376
383
 
377
384
  printf("new before reroder: [");
378
385
  for (int j = 0; j < k; j++)
379
- printf("%ld,%d ", I[j], D[j]);
386
+ printf("%" PRId64 ",%d ", I[j], D[j]);
380
387
  printf("]\n");
381
388
 
382
389
  // re-order heap
@@ -384,10 +391,10 @@ void test_lowlevel_access_binary (const char *index_key) {
384
391
 
385
392
  printf("ref: [");
386
393
  for (int j = 0; j < k; j++)
387
- printf("%ld,%d ", I_ref[j], D_ref[j]);
394
+ printf("%" PRId64 ",%d ", I_ref[j], D_ref[j]);
388
395
  printf("]\nnew: [");
389
396
  for (int j = 0; j < k; j++)
390
- printf("%ld,%d ", I[j], D[j]);
397
+ printf("%" PRId64 ",%d ", I[j], D[j]);
391
398
  printf("]\n");
392
399
 
393
400
  // check that we have the same results as the reference search
@@ -7,6 +7,7 @@
7
7
 
8
8
  #include <cstdio>
9
9
  #include <cstdlib>
10
+ #include <random>
10
11
 
11
12
  #include <gtest/gtest.h>
12
13
 
@@ -70,11 +71,13 @@ struct CommonData {
70
71
 
71
72
  CommonData(): database (nb * d), queries (nq * d), ids(nb), quantizer (d) {
72
73
 
74
+ std::mt19937 rng;
75
+ std::uniform_real_distribution<> distrib;
73
76
  for (size_t i = 0; i < nb * d; i++) {
74
- database[i] = drand48();
77
+ database[i] = distrib(rng);
75
78
  }
76
79
  for (size_t i = 0; i < nq * d; i++) {
77
- queries[i] = drand48();
80
+ queries[i] = distrib(rng);
78
81
  }
79
82
  for (int i = 0; i < nb; i++) {
80
83
  ids[i] = 123 + 456 * i;
@@ -111,7 +114,7 @@ int compare_merged (faiss::IndexShards *index_shards, bool shift_ids,
111
114
  shift_ids);
112
115
  }
113
116
 
114
- index_shards->sync_with_shard_indexes();
117
+ index_shards->syncWithSubIndexes();
115
118
  } else {
116
119
  std::vector<const faiss::InvertedLists *> lists;
117
120
  faiss::IndexIVF *index0 = nullptr;
@@ -7,6 +7,7 @@
7
7
 
8
8
  #include <cstdio>
9
9
  #include <cstdlib>
10
+ #include <random>
10
11
 
11
12
  #include <omp.h>
12
13
 
@@ -69,8 +70,10 @@ TEST(ONDISK, make_invlists) {
69
70
 
70
71
  {
71
72
  std::vector<uint8_t> code(32);
73
+ std::mt19937 rng;
74
+ std::uniform_real_distribution<> distrib;
72
75
  for (int i = 0; i < nadd; i++) {
73
- double d = drand48();
76
+ double d = distrib(rng);
74
77
  int list_no = int(nlist * d * d); // skewed distribution
75
78
  int * ar = (int*)code.data();
76
79
  ar[0] = i;
@@ -183,8 +186,10 @@ TEST(ONDISK, make_invlists_threaded) {
183
186
 
184
187
  std::vector<int> list_nos (nadd);
185
188
 
189
+ std::mt19937 rng;
190
+ std::uniform_real_distribution<> distrib;
186
191
  for (int i = 0; i < nadd; i++) {
187
- double d = drand48();
192
+ double d = distrib(rng);
188
193
  list_nos[i] = int(nlist * d * d); // skewed distribution
189
194
  }
190
195
 
@@ -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
 
@@ -37,11 +38,14 @@ size_t nb = 8000;
37
38
  // nb of queries
38
39
  size_t nq = 200;
39
40
 
41
+ std::mt19937 rng;
42
+
40
43
  std::vector<float> make_data(size_t n)
41
44
  {
42
45
  std::vector <float> database (n * d);
46
+ std::uniform_real_distribution<> distrib;
43
47
  for (size_t i = 0; i < n * d; i++) {
44
- database[i] = drand48();
48
+ database[i] = distrib(rng);
45
49
  }
46
50
  return database;
47
51
  }
@@ -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/AutoTune.h>
20
21
  #include <faiss/IVFlib.h>
21
22
 
23
+
22
24
  using namespace faiss;
23
25
 
24
26
  namespace {
@@ -35,13 +37,15 @@ size_t nb = 1000;
35
37
  // nb of queries
36
38
  size_t nq = 200;
37
39
 
40
+ std::mt19937 rng;
38
41
 
39
42
 
40
43
  std::vector<float> make_data(size_t n)
41
44
  {
42
45
  std::vector <float> database (n * d);
46
+ std::uniform_real_distribution<> distrib;
43
47
  for (size_t i = 0; i < n * d; i++) {
44
- database[i] = drand48();
48
+ database[i] = distrib(rng);
45
49
  }
46
50
  return database;
47
51
  }
@@ -155,8 +159,9 @@ TEST(TPO, IVFFlatPP) {
155
159
 
156
160
  std::vector<uint8_t> make_data_binary(size_t n) {
157
161
  std::vector <uint8_t> database (n * d / 8);
162
+ std::uniform_int_distribution<> distrib;
158
163
  for (size_t i = 0; i < n * d / 8; i++) {
159
- database[i] = lrand48();
164
+ database[i] = distrib(rng);
160
165
  }
161
166
  return database;
162
167
  }
@@ -9,6 +9,7 @@
9
9
  #include <cstdlib>
10
10
 
11
11
  #include <memory>
12
+ #include <random>
12
13
  #include <vector>
13
14
 
14
15
  #include <gtest/gtest.h>
@@ -19,6 +20,7 @@
19
20
  #include <faiss/clone_index.h>
20
21
  #include <faiss/IVFlib.h>
21
22
 
23
+
22
24
  using namespace faiss;
23
25
 
24
26
  typedef Index::idx_t idx_t;
@@ -47,8 +49,10 @@ int window_size = 10;
47
49
  std::vector<float> make_data(size_t n)
48
50
  {
49
51
  std::vector <float> database (n * d);
52
+ std::mt19937 rng;
53
+ std::uniform_real_distribution<> distrib;
50
54
  for (size_t i = 0; i < n * d; i++) {
51
- database[i] = drand48();
55
+ database[i] = distrib(rng);
52
56
  }
53
57
  return database;
54
58
  }
@@ -92,8 +96,10 @@ void make_index_slices (const Index* trained_index,
92
96
 
93
97
  auto xb = make_data(nb * d);
94
98
  std::vector<faiss::Index::idx_t> ids (nb);
99
+ std::mt19937 rng;
100
+ std::uniform_int_distribution<> distrib;
95
101
  for (int j = 0; j < nb; j++) {
96
- ids[j] = lrand48();
102
+ ids[j] = distrib(rng);
97
103
  }
98
104
  index->add_with_ids (nb, xb.data(), ids.data());
99
105
  }
@@ -192,7 +198,7 @@ int test_sliding_invlists (const char *index_key) {
192
198
  // will be deleted by the index
193
199
  index_ivf->replace_invlists (ci, true);
194
200
 
195
- printf (" nb invlists = %ld\n", ils.size());
201
+ printf (" nb invlists = %zd\n", ils.size());
196
202
 
197
203
  auto new_res = search_index (index.get(), xq.data());
198
204
 
@@ -208,7 +214,7 @@ int test_sliding_invlists (const char *index_key) {
208
214
  if (ref_res[j] != new_res[j])
209
215
  ndiff++;
210
216
  }
211
- printf(" nb differences: %ld / %ld\n",
217
+ printf(" nb differences: %zd / %zd\n",
212
218
  ndiff, ref_res.size());
213
219
  EXPECT_EQ (ref_res, new_res);
214
220
  }
@@ -7,39 +7,45 @@
7
7
 
8
8
  #include <cstdio>
9
9
  #include <cstdlib>
10
+ #include <random>
10
11
 
11
12
  #include <faiss/IndexFlat.h>
12
13
 
14
+ // 64-bit int
15
+ using idx_t = faiss::Index::idx_t;
13
16
 
14
17
  int main() {
15
18
  int d = 64; // dimension
16
19
  int nb = 100000; // database size
17
20
  int nq = 10000; // nb of queries
18
21
 
22
+ std::mt19937 rng;
23
+ std::uniform_real_distribution<> distrib;
24
+
19
25
  float *xb = new float[d * nb];
20
26
  float *xq = new float[d * nq];
21
27
 
22
28
  for(int i = 0; i < nb; i++) {
23
29
  for(int j = 0; j < d; j++)
24
- xb[d * i + j] = drand48();
30
+ xb[d * i + j] = distrib(rng);
25
31
  xb[d * i] += i / 1000.;
26
32
  }
27
33
 
28
34
  for(int i = 0; i < nq; i++) {
29
35
  for(int j = 0; j < d; j++)
30
- xq[d * i + j] = drand48();
36
+ xq[d * i + j] = distrib(rng);
31
37
  xq[d * i] += i / 1000.;
32
38
  }
33
39
 
34
40
  faiss::IndexFlatL2 index(d); // call constructor
35
41
  printf("is_trained = %s\n", index.is_trained ? "true" : "false");
36
42
  index.add(nb, xb); // add vectors to the index
37
- printf("ntotal = %ld\n", index.ntotal);
43
+ printf("ntotal = %zd\n", index.ntotal);
38
44
 
39
45
  int k = 4;
40
46
 
41
47
  { // sanity check: search 5 first vectors of xb
42
- long *I = new long[k * 5];
48
+ idx_t *I = new idx_t[k * 5];
43
49
  float *D = new float[k * 5];
44
50
 
45
51
  index.search(5, xb, k, D, I);
@@ -48,7 +54,7 @@ int main() {
48
54
  printf("I=\n");
49
55
  for(int i = 0; i < 5; i++) {
50
56
  for(int j = 0; j < k; j++)
51
- printf("%5ld ", I[i * k + j]);
57
+ printf("%5zd ", I[i * k + j]);
52
58
  printf("\n");
53
59
  }
54
60
 
@@ -65,7 +71,7 @@ int main() {
65
71
 
66
72
 
67
73
  { // search xq
68
- long *I = new long[k * nq];
74
+ idx_t *I = new idx_t[k * nq];
69
75
  float *D = new float[k * nq];
70
76
 
71
77
  index.search(nq, xq, k, D, I);
@@ -74,14 +80,14 @@ int main() {
74
80
  printf("I (5 first results)=\n");
75
81
  for(int i = 0; i < 5; i++) {
76
82
  for(int j = 0; j < k; j++)
77
- printf("%5ld ", I[i * k + j]);
83
+ printf("%5zd ", I[i * k + j]);
78
84
  printf("\n");
79
85
  }
80
86
 
81
87
  printf("I (5 last results)=\n");
82
88
  for(int i = nq - 5; i < nq; i++) {
83
89
  for(int j = 0; j < k; j++)
84
- printf("%5ld ", I[i * k + j]);
90
+ printf("%5zd ", I[i * k + j]);
85
91
  printf("\n");
86
92
  }
87
93
 
@@ -8,28 +8,33 @@
8
8
  #include <cstdio>
9
9
  #include <cstdlib>
10
10
  #include <cassert>
11
+ #include <random>
11
12
 
12
13
  #include <faiss/IndexFlat.h>
13
14
  #include <faiss/IndexIVFFlat.h>
14
15
 
16
+ using idx_t = faiss::Index::idx_t;
15
17
 
16
18
  int main() {
17
19
  int d = 64; // dimension
18
20
  int nb = 100000; // database size
19
21
  int nq = 10000; // nb of queries
20
22
 
23
+ std::mt19937 rng;
24
+ std::uniform_real_distribution<> distrib;
25
+
21
26
  float *xb = new float[d * nb];
22
27
  float *xq = new float[d * nq];
23
28
 
24
29
  for(int i = 0; i < nb; i++) {
25
30
  for(int j = 0; j < d; j++)
26
- xb[d * i + j] = drand48();
31
+ xb[d * i + j] = distrib(rng);
27
32
  xb[d * i] += i / 1000.;
28
33
  }
29
34
 
30
35
  for(int i = 0; i < nq; i++) {
31
36
  for(int j = 0; j < d; j++)
32
- xq[d * i + j] = drand48();
37
+ xq[d * i + j] = distrib(rng);
33
38
  xq[d * i] += i / 1000.;
34
39
  }
35
40
 
@@ -38,15 +43,14 @@ int main() {
38
43
  int k = 4;
39
44
 
40
45
  faiss::IndexFlatL2 quantizer(d); // the other index
41
- faiss::IndexIVFFlat index(&quantizer, d, nlist, faiss::METRIC_L2);
42
- // here we specify METRIC_L2, by default it performs inner-product search
46
+ faiss::IndexIVFFlat index(&quantizer, d, nlist);
43
47
  assert(!index.is_trained);
44
48
  index.train(nb, xb);
45
49
  assert(index.is_trained);
46
50
  index.add(nb, xb);
47
51
 
48
52
  { // search xq
49
- long *I = new long[k * nq];
53
+ idx_t *I = new idx_t[k * nq];
50
54
  float *D = new float[k * nq];
51
55
 
52
56
  index.search(nq, xq, k, D, I);
@@ -54,7 +58,7 @@ int main() {
54
58
  printf("I=\n");
55
59
  for(int i = nq - 5; i < nq; i++) {
56
60
  for(int j = 0; j < k; j++)
57
- printf("%5ld ", I[i * k + j]);
61
+ printf("%5zd ", I[i * k + j]);
58
62
  printf("\n");
59
63
  }
60
64
 
@@ -64,7 +68,7 @@ int main() {
64
68
  printf("I=\n");
65
69
  for(int i = nq - 5; i < nq; i++) {
66
70
  for(int j = 0; j < k; j++)
67
- printf("%5ld ", I[i * k + j]);
71
+ printf("%5zd ", I[i * k + j]);
68
72
  printf("\n");
69
73
  }
70
74