faiss 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/ext/faiss/extconf.rb +1 -1
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/benchs/bench_6bit_codec.cpp +80 -0
- data/vendor/faiss/c_api/AutoTune_c.h +2 -0
- data/vendor/faiss/c_api/IndexShards_c.cpp +0 -6
- data/vendor/faiss/c_api/IndexShards_c.h +1 -4
- data/vendor/faiss/c_api/gpu/GpuAutoTune_c.cpp +4 -2
- data/vendor/faiss/c_api/gpu/GpuClonerOptions_c.cpp +1 -1
- data/vendor/faiss/c_api/gpu/GpuIndex_c.cpp +1 -1
- data/vendor/faiss/c_api/gpu/GpuResources_c.cpp +1 -1
- data/vendor/faiss/c_api/gpu/StandardGpuResources_c.cpp +1 -1
- data/vendor/faiss/demos/demo_imi_flat.cpp +5 -2
- data/vendor/faiss/demos/demo_imi_pq.cpp +6 -2
- data/vendor/faiss/demos/demo_ivfpq_indexing.cpp +7 -2
- data/vendor/faiss/{AutoTune.cpp → faiss/AutoTune.cpp} +9 -9
- data/vendor/faiss/{AutoTune.h → faiss/AutoTune.h} +0 -0
- data/vendor/faiss/{Clustering.cpp → faiss/Clustering.cpp} +13 -12
- data/vendor/faiss/{Clustering.h → faiss/Clustering.h} +0 -0
- data/vendor/faiss/{DirectMap.cpp → faiss/DirectMap.cpp} +0 -0
- data/vendor/faiss/{DirectMap.h → faiss/DirectMap.h} +0 -0
- data/vendor/faiss/{IVFlib.cpp → faiss/IVFlib.cpp} +86 -11
- data/vendor/faiss/{IVFlib.h → faiss/IVFlib.h} +26 -8
- data/vendor/faiss/{Index.cpp → faiss/Index.cpp} +0 -0
- data/vendor/faiss/{Index.h → faiss/Index.h} +1 -1
- data/vendor/faiss/{Index2Layer.cpp → faiss/Index2Layer.cpp} +12 -11
- data/vendor/faiss/{Index2Layer.h → faiss/Index2Layer.h} +0 -0
- data/vendor/faiss/{IndexBinary.cpp → faiss/IndexBinary.cpp} +2 -1
- data/vendor/faiss/{IndexBinary.h → faiss/IndexBinary.h} +0 -0
- data/vendor/faiss/{IndexBinaryFlat.cpp → faiss/IndexBinaryFlat.cpp} +0 -0
- data/vendor/faiss/{IndexBinaryFlat.h → faiss/IndexBinaryFlat.h} +0 -0
- data/vendor/faiss/{IndexBinaryFromFloat.cpp → faiss/IndexBinaryFromFloat.cpp} +1 -0
- data/vendor/faiss/{IndexBinaryFromFloat.h → faiss/IndexBinaryFromFloat.h} +0 -0
- data/vendor/faiss/{IndexBinaryHNSW.cpp → faiss/IndexBinaryHNSW.cpp} +1 -2
- data/vendor/faiss/{IndexBinaryHNSW.h → faiss/IndexBinaryHNSW.h} +0 -0
- data/vendor/faiss/{IndexBinaryHash.cpp → faiss/IndexBinaryHash.cpp} +16 -7
- data/vendor/faiss/{IndexBinaryHash.h → faiss/IndexBinaryHash.h} +2 -1
- data/vendor/faiss/{IndexBinaryIVF.cpp → faiss/IndexBinaryIVF.cpp} +10 -16
- data/vendor/faiss/{IndexBinaryIVF.h → faiss/IndexBinaryIVF.h} +1 -1
- data/vendor/faiss/{IndexFlat.cpp → faiss/IndexFlat.cpp} +0 -0
- data/vendor/faiss/{IndexFlat.h → faiss/IndexFlat.h} +0 -0
- data/vendor/faiss/{IndexHNSW.cpp → faiss/IndexHNSW.cpp} +63 -32
- data/vendor/faiss/{IndexHNSW.h → faiss/IndexHNSW.h} +0 -0
- data/vendor/faiss/{IndexIVF.cpp → faiss/IndexIVF.cpp} +129 -46
- data/vendor/faiss/{IndexIVF.h → faiss/IndexIVF.h} +7 -3
- data/vendor/faiss/{IndexIVFFlat.cpp → faiss/IndexIVFFlat.cpp} +6 -5
- data/vendor/faiss/{IndexIVFFlat.h → faiss/IndexIVFFlat.h} +0 -0
- data/vendor/faiss/{IndexIVFPQ.cpp → faiss/IndexIVFPQ.cpp} +9 -8
- data/vendor/faiss/{IndexIVFPQ.h → faiss/IndexIVFPQ.h} +4 -2
- data/vendor/faiss/{IndexIVFPQR.cpp → faiss/IndexIVFPQR.cpp} +3 -1
- data/vendor/faiss/{IndexIVFPQR.h → faiss/IndexIVFPQR.h} +0 -0
- data/vendor/faiss/{IndexIVFSpectralHash.cpp → faiss/IndexIVFSpectralHash.cpp} +1 -1
- data/vendor/faiss/{IndexIVFSpectralHash.h → faiss/IndexIVFSpectralHash.h} +0 -0
- data/vendor/faiss/{IndexLSH.cpp → faiss/IndexLSH.cpp} +0 -0
- data/vendor/faiss/{IndexLSH.h → faiss/IndexLSH.h} +0 -0
- data/vendor/faiss/{IndexLattice.cpp → faiss/IndexLattice.cpp} +0 -0
- data/vendor/faiss/{IndexLattice.h → faiss/IndexLattice.h} +0 -0
- data/vendor/faiss/{IndexPQ.cpp → faiss/IndexPQ.cpp} +6 -6
- data/vendor/faiss/{IndexPQ.h → faiss/IndexPQ.h} +3 -1
- data/vendor/faiss/{IndexPreTransform.cpp → faiss/IndexPreTransform.cpp} +0 -0
- data/vendor/faiss/{IndexPreTransform.h → faiss/IndexPreTransform.h} +0 -0
- data/vendor/faiss/{IndexReplicas.cpp → faiss/IndexReplicas.cpp} +102 -10
- data/vendor/faiss/{IndexReplicas.h → faiss/IndexReplicas.h} +6 -0
- data/vendor/faiss/{IndexScalarQuantizer.cpp → faiss/IndexScalarQuantizer.cpp} +3 -3
- data/vendor/faiss/{IndexScalarQuantizer.h → faiss/IndexScalarQuantizer.h} +0 -0
- data/vendor/faiss/{IndexShards.cpp → faiss/IndexShards.cpp} +37 -12
- data/vendor/faiss/{IndexShards.h → faiss/IndexShards.h} +3 -4
- data/vendor/faiss/{InvertedLists.cpp → faiss/InvertedLists.cpp} +2 -2
- data/vendor/faiss/{InvertedLists.h → faiss/InvertedLists.h} +1 -0
- data/vendor/faiss/{MatrixStats.cpp → faiss/MatrixStats.cpp} +0 -0
- data/vendor/faiss/{MatrixStats.h → faiss/MatrixStats.h} +0 -0
- data/vendor/faiss/{MetaIndexes.cpp → faiss/MetaIndexes.cpp} +5 -3
- data/vendor/faiss/{MetaIndexes.h → faiss/MetaIndexes.h} +0 -0
- data/vendor/faiss/{MetricType.h → faiss/MetricType.h} +0 -0
- data/vendor/faiss/{OnDiskInvertedLists.cpp → faiss/OnDiskInvertedLists.cpp} +141 -3
- data/vendor/faiss/{OnDiskInvertedLists.h → faiss/OnDiskInvertedLists.h} +27 -7
- data/vendor/faiss/{VectorTransform.cpp → faiss/VectorTransform.cpp} +4 -3
- data/vendor/faiss/{VectorTransform.h → faiss/VectorTransform.h} +0 -0
- data/vendor/faiss/{clone_index.cpp → faiss/clone_index.cpp} +0 -0
- data/vendor/faiss/{clone_index.h → faiss/clone_index.h} +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/GpuAutoTune.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/GpuAutoTune.h +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/GpuCloner.cpp +14 -14
- data/vendor/faiss/{gpu → faiss/gpu}/GpuCloner.h +6 -7
- data/vendor/faiss/{gpu → faiss/gpu}/GpuClonerOptions.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/GpuClonerOptions.h +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/GpuDistance.h +12 -4
- data/vendor/faiss/{gpu → faiss/gpu}/GpuFaissAssert.h +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndex.h +3 -9
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexBinaryFlat.h +7 -7
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexFlat.h +35 -10
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexIVF.h +1 -2
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexIVFFlat.h +4 -3
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexIVFPQ.h +21 -4
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexIVFScalarQuantizer.h +4 -3
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndicesOptions.h +0 -0
- data/vendor/faiss/faiss/gpu/GpuResources.cpp +200 -0
- data/vendor/faiss/faiss/gpu/GpuResources.h +264 -0
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +572 -0
- data/vendor/faiss/{gpu → faiss/gpu}/StandardGpuResources.h +83 -15
- data/vendor/faiss/{gpu → faiss/gpu}/impl/RemapIndices.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/impl/RemapIndices.h +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/perf/IndexWrapper-inl.h +1 -1
- data/vendor/faiss/{gpu → faiss/gpu}/perf/IndexWrapper.h +1 -1
- data/vendor/faiss/{gpu → faiss/gpu}/perf/PerfClustering.cpp +1 -1
- data/vendor/faiss/{gpu → faiss/gpu}/perf/PerfIVFPQAdd.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/perf/WriteIndex.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuIndexBinaryFlat.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuIndexFlat.cpp +1 -1
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuIndexIVFFlat.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuIndexIVFPQ.cpp +141 -52
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuMemoryException.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestUtils.cpp +4 -2
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestUtils.h +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/test/demo_ivfpq_indexing_gpu.cpp +7 -5
- data/vendor/faiss/{gpu → faiss/gpu}/utils/DeviceUtils.h +1 -1
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +213 -0
- data/vendor/faiss/{gpu → faiss/gpu}/utils/StackDeviceMemory.h +25 -40
- data/vendor/faiss/{gpu → faiss/gpu}/utils/StaticUtils.h +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/utils/Timer.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/utils/Timer.h +0 -0
- data/vendor/faiss/{impl → faiss/impl}/AuxIndexStructures.cpp +1 -0
- data/vendor/faiss/{impl → faiss/impl}/AuxIndexStructures.h +3 -1
- data/vendor/faiss/{impl → faiss/impl}/FaissAssert.h +1 -0
- data/vendor/faiss/{impl → faiss/impl}/FaissException.cpp +26 -0
- data/vendor/faiss/{impl → faiss/impl}/FaissException.h +4 -0
- data/vendor/faiss/{impl → faiss/impl}/HNSW.cpp +26 -26
- data/vendor/faiss/{impl → faiss/impl}/HNSW.h +19 -11
- data/vendor/faiss/{impl → faiss/impl}/PolysemousTraining.cpp +1 -1
- data/vendor/faiss/{impl → faiss/impl}/PolysemousTraining.h +1 -1
- data/vendor/faiss/{impl → faiss/impl}/ProductQuantizer-inl.h +0 -1
- data/vendor/faiss/{impl → faiss/impl}/ProductQuantizer.cpp +9 -9
- data/vendor/faiss/{impl → faiss/impl}/ProductQuantizer.h +0 -0
- data/vendor/faiss/{impl → faiss/impl}/ScalarQuantizer.cpp +63 -39
- data/vendor/faiss/{impl → faiss/impl}/ScalarQuantizer.h +1 -1
- data/vendor/faiss/{impl → faiss/impl}/ThreadedIndex-inl.h +0 -0
- data/vendor/faiss/{impl → faiss/impl}/ThreadedIndex.h +0 -0
- data/vendor/faiss/{impl → faiss/impl}/index_read.cpp +99 -116
- data/vendor/faiss/{impl → faiss/impl}/index_write.cpp +15 -50
- data/vendor/faiss/{impl → faiss/impl}/io.cpp +15 -10
- data/vendor/faiss/{impl → faiss/impl}/io.h +22 -8
- data/vendor/faiss/faiss/impl/io_macros.h +57 -0
- data/vendor/faiss/{impl → faiss/impl}/lattice_Zn.cpp +52 -36
- data/vendor/faiss/{impl → faiss/impl}/lattice_Zn.h +3 -3
- data/vendor/faiss/faiss/impl/platform_macros.h +24 -0
- data/vendor/faiss/{index_factory.cpp → faiss/index_factory.cpp} +33 -12
- data/vendor/faiss/{index_factory.h → faiss/index_factory.h} +0 -0
- data/vendor/faiss/{index_io.h → faiss/index_io.h} +55 -1
- data/vendor/faiss/faiss/python/python_callbacks.cpp +112 -0
- data/vendor/faiss/faiss/python/python_callbacks.h +45 -0
- data/vendor/faiss/{utils → faiss/utils}/Heap.cpp +5 -5
- data/vendor/faiss/{utils → faiss/utils}/Heap.h +1 -3
- data/vendor/faiss/{utils → faiss/utils}/WorkerThread.cpp +0 -0
- data/vendor/faiss/{utils → faiss/utils}/WorkerThread.h +0 -0
- data/vendor/faiss/{utils → faiss/utils}/distances.cpp +28 -13
- data/vendor/faiss/{utils → faiss/utils}/distances.h +2 -1
- data/vendor/faiss/{utils → faiss/utils}/distances_simd.cpp +5 -5
- data/vendor/faiss/{utils → faiss/utils}/extra_distances.cpp +8 -7
- data/vendor/faiss/{utils → faiss/utils}/extra_distances.h +0 -0
- data/vendor/faiss/{utils → faiss/utils}/hamming-inl.h +1 -3
- data/vendor/faiss/{utils → faiss/utils}/hamming.cpp +8 -7
- data/vendor/faiss/{utils → faiss/utils}/hamming.h +7 -1
- data/vendor/faiss/{utils → faiss/utils}/random.cpp +5 -5
- data/vendor/faiss/{utils → faiss/utils}/random.h +0 -0
- data/vendor/faiss/{utils → faiss/utils}/utils.cpp +27 -28
- data/vendor/faiss/{utils → faiss/utils}/utils.h +4 -0
- data/vendor/faiss/misc/test_blas.cpp +4 -1
- data/vendor/faiss/tests/test_binary_flat.cpp +0 -2
- data/vendor/faiss/tests/test_dealloc_invlists.cpp +6 -1
- data/vendor/faiss/tests/test_ivfpq_codec.cpp +4 -1
- data/vendor/faiss/tests/test_ivfpq_indexing.cpp +6 -4
- data/vendor/faiss/tests/test_lowlevel_ivf.cpp +12 -5
- data/vendor/faiss/tests/test_merge.cpp +6 -3
- data/vendor/faiss/tests/test_ondisk_ivf.cpp +7 -2
- data/vendor/faiss/tests/test_pairs_decoding.cpp +5 -1
- data/vendor/faiss/tests/test_params_override.cpp +7 -2
- data/vendor/faiss/tests/test_sliding_ivf.cpp +10 -4
- data/vendor/faiss/tutorial/cpp/1-Flat.cpp +14 -8
- data/vendor/faiss/tutorial/cpp/2-IVFFlat.cpp +11 -7
- data/vendor/faiss/tutorial/cpp/3-IVFPQ.cpp +12 -7
- data/vendor/faiss/tutorial/cpp/4-GPU.cpp +6 -3
- data/vendor/faiss/tutorial/cpp/5-Multiple-GPUs.cpp +7 -3
- metadata +154 -153
- data/vendor/faiss/gpu/GpuResources.cpp +0 -52
- data/vendor/faiss/gpu/GpuResources.h +0 -73
- data/vendor/faiss/gpu/StandardGpuResources.cpp +0 -303
- data/vendor/faiss/gpu/utils/DeviceMemory.cpp +0 -77
- data/vendor/faiss/gpu/utils/DeviceMemory.h +0 -71
- data/vendor/faiss/gpu/utils/MemorySpace.cpp +0 -89
- data/vendor/faiss/gpu/utils/MemorySpace.h +0 -44
- data/vendor/faiss/gpu/utils/StackDeviceMemory.cpp +0 -239
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97fd4d583754d20a5771e941fd5272205977c34b77eb9252e58f6016b90be52e
|
4
|
+
data.tar.gz: 26df73fc7891efd894e9ebf4ed37db2aaa3af8b62221cdd707cb287f920ad0a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 197143a79061c299b8f5e5ae76466db1a673e46f6d842615bed46170afadb6145e14df936262ec45f7e0d1eea889037cb3123c5a9348e32774eeb97414f180fd
|
7
|
+
data.tar.gz: 5a8e1ecebd43886d974e52fa216d86d9c03e3f8c04629eddc04a8be8df5c7ab4fc4c57398f2893d44718c788cd1853ae1bee06f64f1d49cdc5330cb03c5c0e6c
|
data/CHANGELOG.md
CHANGED
data/ext/faiss/extconf.rb
CHANGED
@@ -7,7 +7,7 @@ abort "OpenMP not found" unless have_library("omp") || have_library("gomp")
|
|
7
7
|
$CXXFLAGS << " -std=c++11 -march=native -DFINTEGER=int"
|
8
8
|
|
9
9
|
ext = File.expand_path(".", __dir__)
|
10
|
-
vendor = File.expand_path("../../vendor", __dir__)
|
10
|
+
vendor = File.expand_path("../../vendor/faiss", __dir__)
|
11
11
|
|
12
12
|
$srcs = Dir["{#{ext},#{vendor}/faiss,#{vendor}/faiss/impl,#{vendor}/faiss/utils}/*.{cpp}"]
|
13
13
|
$objs = $srcs.map { |v| v.sub(/cpp\z/, "o") }
|
data/lib/faiss/version.rb
CHANGED
@@ -0,0 +1,80 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
|
8
|
+
|
9
|
+
#include <cstdio>
|
10
|
+
#include <omp.h>
|
11
|
+
|
12
|
+
#include <faiss/impl/ScalarQuantizer.h>
|
13
|
+
#include <faiss/utils/utils.h>
|
14
|
+
#include <faiss/utils/random.h>
|
15
|
+
#include <faiss/utils/distances.h>
|
16
|
+
|
17
|
+
using namespace faiss;
|
18
|
+
|
19
|
+
int main() {
|
20
|
+
|
21
|
+
int d = 128;
|
22
|
+
int n = 2000;
|
23
|
+
|
24
|
+
std::vector<float> x(d * n);
|
25
|
+
|
26
|
+
float_rand(x.data(), d * n, 12345);
|
27
|
+
|
28
|
+
// make sure it's idempotent
|
29
|
+
ScalarQuantizer sq(d, ScalarQuantizer::QT_6bit);
|
30
|
+
|
31
|
+
omp_set_num_threads(1);
|
32
|
+
|
33
|
+
sq.train(n, x.data());
|
34
|
+
|
35
|
+
size_t code_size = sq.code_size;
|
36
|
+
printf("code size: %ld\n", sq.code_size);
|
37
|
+
|
38
|
+
// encode
|
39
|
+
std::vector<uint8_t> codes(code_size * n);
|
40
|
+
sq.compute_codes(x.data(), codes.data(), n);
|
41
|
+
|
42
|
+
// decode
|
43
|
+
std::vector<float> x2(d * n);
|
44
|
+
sq.decode(codes.data(), x2.data(), n);
|
45
|
+
|
46
|
+
printf("sqL2 recons error: %g\n",
|
47
|
+
fvec_L2sqr(x.data(), x2.data(), n * d) / n);
|
48
|
+
|
49
|
+
// encode again
|
50
|
+
std::vector<uint8_t> codes2(code_size * n);
|
51
|
+
sq.compute_codes(x2.data(), codes2.data(), n);
|
52
|
+
|
53
|
+
size_t ndiff = 0;
|
54
|
+
for (size_t i = 0; i < codes.size(); i++) {
|
55
|
+
if (codes[i] != codes2[i]) ndiff++;
|
56
|
+
}
|
57
|
+
|
58
|
+
printf("ndiff for idempotence: %ld / %ld\n", ndiff, codes.size());
|
59
|
+
|
60
|
+
std::unique_ptr<ScalarQuantizer::SQDistanceComputer>
|
61
|
+
dc(sq.get_distance_computer());
|
62
|
+
dc->codes = codes.data();
|
63
|
+
dc->code_size = sq.code_size;
|
64
|
+
printf("code size: %ld\n", dc->code_size);
|
65
|
+
|
66
|
+
double sum_dis = 0;
|
67
|
+
double t0 = getmillisecs();
|
68
|
+
for (int i = 0; i < n; i++) {
|
69
|
+
dc->set_query(&x[i * d]);
|
70
|
+
for (int j = 0; j < n; j++) {
|
71
|
+
sum_dis += (*dc)(j);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
printf("distances computed in %.3f ms, checksum=%g\n",
|
75
|
+
getmillisecs() - t0, sum_dis);
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
return 0;
|
80
|
+
}
|
@@ -31,6 +31,8 @@ void faiss_ParameterRange_values(FaissParameterRange*, double**, size_t*);
|
|
31
31
|
*/
|
32
32
|
FAISS_DECLARE_CLASS(ParameterSpace)
|
33
33
|
|
34
|
+
FAISS_DECLARE_DESTRUCTOR(ParameterSpace)
|
35
|
+
|
34
36
|
/// Parameter space default constructor
|
35
37
|
int faiss_ParameterSpace_new(FaissParameterSpace** space);
|
36
38
|
|
@@ -32,12 +32,6 @@ int faiss_IndexShards_add_shard(FaissIndexShards* index, FaissIndex* shard) {
|
|
32
32
|
} CATCH_AND_HANDLE
|
33
33
|
}
|
34
34
|
|
35
|
-
int faiss_IndexShards_sync_with_shard_indexes(FaissIndexShards* index) {
|
36
|
-
try {
|
37
|
-
reinterpret_cast<IndexShards*>(index)->sync_with_shard_indexes();
|
38
|
-
} CATCH_AND_HANDLE
|
39
|
-
}
|
40
|
-
|
41
35
|
FaissIndex* faiss_IndexShards_at(FaissIndexShards* index, int i) {
|
42
36
|
auto shard = reinterpret_cast<IndexShards*>(index)->at(i);
|
43
37
|
return reinterpret_cast<FaissIndex*>(shard);
|
@@ -31,12 +31,9 @@ int faiss_IndexShards_new_with_options(FaissIndexShards** p_index, idx_t d, int
|
|
31
31
|
|
32
32
|
int faiss_IndexShards_add_shard(FaissIndexShards* index, FaissIndex* shard);
|
33
33
|
|
34
|
-
/// update metric_type and ntotal
|
35
|
-
int faiss_IndexShards_sync_with_shard_indexes(FaissIndexShards* index);
|
36
|
-
|
37
34
|
FaissIndex* faiss_IndexShards_at(FaissIndexShards* index, int i);
|
38
35
|
|
39
36
|
#ifdef __cplusplus
|
40
37
|
}
|
41
38
|
#endif
|
42
|
-
#endif
|
39
|
+
#endif
|
@@ -12,8 +12,10 @@
|
|
12
12
|
#include "GpuClonerOptions_c.h"
|
13
13
|
#include "macros_impl.h"
|
14
14
|
#include "Index.h"
|
15
|
-
#include
|
16
|
-
#include
|
15
|
+
#include <faiss/gpu/GpuCloner.h>
|
16
|
+
#include <faiss/gpu/GpuResources.h>
|
17
|
+
#include <faiss/gpu/GpuAutoTune.h>
|
18
|
+
#include <faiss/gpu/GpuClonerOptions.h>
|
17
19
|
#include <vector>
|
18
20
|
|
19
21
|
using faiss::Index;
|
@@ -10,6 +10,7 @@
|
|
10
10
|
#include <cmath>
|
11
11
|
#include <cstdio>
|
12
12
|
#include <cstdlib>
|
13
|
+
#include <random>
|
13
14
|
|
14
15
|
#include <sys/time.h>
|
15
16
|
|
@@ -77,6 +78,8 @@ int main ()
|
|
77
78
|
// Use 4-1024 depending on the trade-off speed accuracy that you want
|
78
79
|
index.nprobe = 2048;
|
79
80
|
|
81
|
+
std::mt19937 rng;
|
82
|
+
std::uniform_real_distribution<> distrib;
|
80
83
|
|
81
84
|
{ // training
|
82
85
|
printf ("[%.3f s] Generating %ld vectors in %dD for training\n",
|
@@ -84,7 +87,7 @@ int main ()
|
|
84
87
|
|
85
88
|
std::vector <float> trainvecs (nt * d);
|
86
89
|
for (size_t i = 0; i < nt * d; i++) {
|
87
|
-
trainvecs[i] =
|
90
|
+
trainvecs[i] = distrib(rng);
|
88
91
|
}
|
89
92
|
|
90
93
|
printf ("[%.3f s] Training the index\n", elapsed() - t0);
|
@@ -101,7 +104,7 @@ int main ()
|
|
101
104
|
|
102
105
|
std::vector <float> database (nb * d);
|
103
106
|
for (size_t i = 0; i < nb * d; i++) {
|
104
|
-
database[i] =
|
107
|
+
database[i] = distrib(rng);
|
105
108
|
}
|
106
109
|
|
107
110
|
printf ("[%.3f s] Adding the vectors to the index\n", elapsed() - t0);
|
@@ -10,6 +10,7 @@
|
|
10
10
|
#include <cmath>
|
11
11
|
#include <cstdio>
|
12
12
|
#include <cstdlib>
|
13
|
+
#include <random>
|
13
14
|
|
14
15
|
#include <sys/time.h>
|
15
16
|
|
@@ -87,6 +88,9 @@ int main ()
|
|
87
88
|
index.nprobe = 2048;
|
88
89
|
|
89
90
|
|
91
|
+
std::mt19937 rng;
|
92
|
+
std::uniform_real_distribution<> distrib;
|
93
|
+
|
90
94
|
{ // training.
|
91
95
|
|
92
96
|
// The distribution of the training vectors should be the same
|
@@ -100,7 +104,7 @@ int main ()
|
|
100
104
|
std::vector <float> trainvecs (nt * d);
|
101
105
|
for (size_t i = 0; i < nt; i++) {
|
102
106
|
for (size_t j = 0; j < d; j++) {
|
103
|
-
trainvecs[i * d + j] =
|
107
|
+
trainvecs[i * d + j] = distrib(rng);
|
104
108
|
}
|
105
109
|
}
|
106
110
|
|
@@ -124,7 +128,7 @@ int main ()
|
|
124
128
|
std::vector <long> ids (nb);
|
125
129
|
for (size_t i = 0; i < nb; i++) {
|
126
130
|
for (size_t j = 0; j < d; j++) {
|
127
|
-
database[i * d + j] =
|
131
|
+
database[i * d + j] = distrib(rng);
|
128
132
|
}
|
129
133
|
ids[i] = 8760000000L + i;
|
130
134
|
}
|
@@ -10,6 +10,7 @@
|
|
10
10
|
#include <cmath>
|
11
11
|
#include <cstdio>
|
12
12
|
#include <cstdlib>
|
13
|
+
#include <random>
|
13
14
|
|
14
15
|
#include <sys/time.h>
|
15
16
|
|
@@ -54,13 +55,16 @@ int main ()
|
|
54
55
|
ncentroids, 4, 8);
|
55
56
|
|
56
57
|
|
58
|
+
std::mt19937 rng;
|
59
|
+
|
57
60
|
{ // training
|
58
61
|
printf ("[%.3f s] Generating %ld vectors in %dD for training\n",
|
59
62
|
elapsed() - t0, nt, d);
|
60
63
|
|
61
64
|
std::vector <float> trainvecs (nt * d);
|
65
|
+
std::uniform_real_distribution<> distrib;
|
62
66
|
for (size_t i = 0; i < nt * d; i++) {
|
63
|
-
trainvecs[i] =
|
67
|
+
trainvecs[i] = distrib(rng);
|
64
68
|
}
|
65
69
|
|
66
70
|
printf ("[%.3f s] Training the index\n",
|
@@ -86,8 +90,9 @@ int main ()
|
|
86
90
|
elapsed() - t0, nb);
|
87
91
|
|
88
92
|
std::vector <float> database (nb * d);
|
93
|
+
std::uniform_real_distribution<> distrib;
|
89
94
|
for (size_t i = 0; i < nb * d; i++) {
|
90
|
-
database[i] =
|
95
|
+
database[i] = distrib(rng);
|
91
96
|
}
|
92
97
|
|
93
98
|
printf ("[%.3f s] Adding the vectors to the index\n",
|
@@ -13,6 +13,7 @@
|
|
13
13
|
|
14
14
|
#include <faiss/AutoTune.h>
|
15
15
|
|
16
|
+
#include <cinttypes>
|
16
17
|
#include <cmath>
|
17
18
|
|
18
19
|
#include <faiss/impl/FaissAssert.h>
|
@@ -233,7 +234,7 @@ void OperatingPoints::display (bool only_optimal) const
|
|
233
234
|
{
|
234
235
|
const std::vector<OperatingPoint> &pts =
|
235
236
|
only_optimal ? optimal_pts : all_pts;
|
236
|
-
printf("Tested %
|
237
|
+
printf("Tested %zd operating points, %zd ones are optimal:\n",
|
237
238
|
all_pts.size(), optimal_pts.size());
|
238
239
|
|
239
240
|
for (int i = 0; i < pts.size(); i++) {
|
@@ -247,7 +248,7 @@ void OperatingPoints::display (bool only_optimal) const
|
|
247
248
|
}
|
248
249
|
}
|
249
250
|
}
|
250
|
-
printf ("cno=%
|
251
|
+
printf ("cno=%" PRId64 " key=%s perf=%.4f t=%.3f %s\n",
|
251
252
|
op.cno, op.key.c_str(), op.perf, op.t, star);
|
252
253
|
}
|
253
254
|
|
@@ -437,11 +438,10 @@ void ParameterSpace::set_index_parameters (Index *index, size_t cno) const
|
|
437
438
|
void ParameterSpace::set_index_parameters (
|
438
439
|
Index *index, const char *description_in) const
|
439
440
|
{
|
440
|
-
|
441
|
+
std::string description(description_in);
|
441
442
|
char *ptr;
|
442
|
-
memcpy (description, description_in, strlen(description_in) + 1);
|
443
443
|
|
444
|
-
for (char *tok = strtok_r (description, " ,", &ptr);
|
444
|
+
for (char *tok = strtok_r (&description[0], " ,", &ptr);
|
445
445
|
tok;
|
446
446
|
tok = strtok_r (nullptr, " ,", &ptr)) {
|
447
447
|
char name[100];
|
@@ -566,7 +566,7 @@ void ParameterSpace::set_index_parameter (
|
|
566
566
|
|
567
567
|
void ParameterSpace::display () const
|
568
568
|
{
|
569
|
-
printf ("ParameterSpace, %
|
569
|
+
printf ("ParameterSpace, %zd parameters, %zd combinations:\n",
|
570
570
|
parameter_ranges.size (), n_combinations ());
|
571
571
|
for (int i = 0; i < parameter_ranges.size(); i++) {
|
572
572
|
const ParameterRange & pr = parameter_ranges[i];
|
@@ -622,7 +622,7 @@ void ParameterSpace::explore (Index *index,
|
|
622
622
|
bool keep = ops->add (perf, t_search, combination_name (cno), cno);
|
623
623
|
|
624
624
|
if (verbose)
|
625
|
-
printf(" %
|
625
|
+
printf(" %zd/%zd: %s perf=%.3f t=%.3f s %s\n", cno, n_comb,
|
626
626
|
combination_name (cno).c_str(), perf, t_search,
|
627
627
|
keep ? "*" : "");
|
628
628
|
}
|
@@ -646,7 +646,7 @@ void ParameterSpace::explore (Index *index,
|
|
646
646
|
size_t cno = perm[xp];
|
647
647
|
|
648
648
|
if (verbose)
|
649
|
-
printf(" %
|
649
|
+
printf(" %zd/%d: cno=%zd %s ", xp, n_exp, cno,
|
650
650
|
combination_name (cno).c_str());
|
651
651
|
|
652
652
|
{
|
@@ -677,7 +677,7 @@ void ParameterSpace::explore (Index *index,
|
|
677
677
|
|
678
678
|
if (thread_over_batches) {
|
679
679
|
#pragma omp parallel for
|
680
|
-
for (
|
680
|
+
for (Index::idx_t q0 = 0; q0 < nq; q0 += batchsize) {
|
681
681
|
size_t q1 = q0 + batchsize;
|
682
682
|
if (q1 > nq) q1 = nq;
|
683
683
|
index->search (q1 - q0, xq + q0 * index->d,
|
File without changes
|
@@ -10,6 +10,7 @@
|
|
10
10
|
#include <faiss/Clustering.h>
|
11
11
|
#include <faiss/impl/AuxIndexStructures.h>
|
12
12
|
|
13
|
+
#include <cinttypes>
|
13
14
|
#include <cmath>
|
14
15
|
#include <cstdio>
|
15
16
|
#include <cstring>
|
@@ -97,7 +98,7 @@ idx_t subsample_training_set(
|
|
97
98
|
)
|
98
99
|
{
|
99
100
|
if (clus.verbose) {
|
100
|
-
printf("Sampling a subset of %
|
101
|
+
printf("Sampling a subset of %zd / %" PRId64 " for training\n",
|
101
102
|
clus.k * clus.max_points_per_centroid, nx);
|
102
103
|
}
|
103
104
|
std::vector<int> perm (nx);
|
@@ -190,7 +191,7 @@ void compute_centroids (size_t d, size_t k, size_t n,
|
|
190
191
|
}
|
191
192
|
|
192
193
|
#pragma omp parallel for
|
193
|
-
for (
|
194
|
+
for (idx_t ci = 0; ci < k; ci++) {
|
194
195
|
if (hassign[ci] == 0) {
|
195
196
|
continue;
|
196
197
|
}
|
@@ -209,7 +210,7 @@ void compute_centroids (size_t d, size_t k, size_t n,
|
|
209
210
|
/** Handle empty clusters by splitting larger ones.
|
210
211
|
*
|
211
212
|
* It works by slightly changing the centroids to make 2 clusters from
|
212
|
-
* a single one. Takes the same
|
213
|
+
* a single one. Takes the same arguments as compute_centroids.
|
213
214
|
*
|
214
215
|
* @return nb of spliting operations (larger is worse)
|
215
216
|
*/
|
@@ -269,8 +270,8 @@ void Clustering::train_encoded (idx_t nx, const uint8_t *x_in,
|
|
269
270
|
const float *weights) {
|
270
271
|
|
271
272
|
FAISS_THROW_IF_NOT_FMT (nx >= k,
|
272
|
-
"Number of training points (%
|
273
|
-
"as large as number of clusters (%
|
273
|
+
"Number of training points (%" PRId64 ") should be at least "
|
274
|
+
"as large as number of clusters (%zd)", nx, k);
|
274
275
|
|
275
276
|
FAISS_THROW_IF_NOT_FMT ((!codec || codec->d == d),
|
276
277
|
"Codec dimension %d not the same as data dimension %d",
|
@@ -288,7 +289,7 @@ void Clustering::train_encoded (idx_t nx, const uint8_t *x_in,
|
|
288
289
|
// reports.
|
289
290
|
const float *x = reinterpret_cast<const float *>(x_in);
|
290
291
|
for (size_t i = 0; i < nx * d; i++) {
|
291
|
-
FAISS_THROW_IF_NOT_MSG (
|
292
|
+
FAISS_THROW_IF_NOT_MSG (std::isfinite (x[i]),
|
292
293
|
"input contains NaN's or Inf's");
|
293
294
|
}
|
294
295
|
}
|
@@ -307,15 +308,15 @@ void Clustering::train_encoded (idx_t nx, const uint8_t *x_in,
|
|
307
308
|
del3.reset (weights_new); weights = weights_new;
|
308
309
|
} else if (nx < k * min_points_per_centroid) {
|
309
310
|
fprintf (stderr,
|
310
|
-
"WARNING clustering %
|
311
|
-
"please provide at least %
|
311
|
+
"WARNING clustering %" PRId64 " points to %zd centroids: "
|
312
|
+
"please provide at least %" PRId64 " training points\n",
|
312
313
|
nx, k, idx_t(k) * min_points_per_centroid);
|
313
314
|
}
|
314
315
|
|
315
316
|
if (nx == k) {
|
316
317
|
// this is a corner case, just copy training set to clusters
|
317
318
|
if (verbose) {
|
318
|
-
printf("Number of training points (%
|
319
|
+
printf("Number of training points (%" PRId64 ") same as number of "
|
319
320
|
"clusters, just copying\n", nx);
|
320
321
|
}
|
321
322
|
centroids.resize (d * k);
|
@@ -336,11 +337,11 @@ void Clustering::train_encoded (idx_t nx, const uint8_t *x_in,
|
|
336
337
|
|
337
338
|
|
338
339
|
if (verbose) {
|
339
|
-
printf("Clustering %
|
340
|
+
printf("Clustering %" PRId64 " points in %zdD to %zd clusters, "
|
340
341
|
"redo %d times, %d iterations\n",
|
341
|
-
|
342
|
+
nx, d, k, nredo, niter);
|
342
343
|
if (codec) {
|
343
|
-
printf("Input data encoded in %
|
344
|
+
printf("Input data encoded in %zd bytes per vector\n",
|
344
345
|
codec->sa_code_size ());
|
345
346
|
}
|
346
347
|
}
|