faiss 0.2.0 → 0.2.4
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/LICENSE.txt +1 -1
- data/README.md +7 -7
- data/ext/faiss/extconf.rb +6 -3
- data/ext/faiss/numo.hpp +4 -4
- data/ext/faiss/utils.cpp +1 -1
- data/ext/faiss/utils.h +1 -1
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +292 -291
- data/vendor/faiss/faiss/AutoTune.h +55 -56
- data/vendor/faiss/faiss/Clustering.cpp +365 -194
- data/vendor/faiss/faiss/Clustering.h +102 -35
- data/vendor/faiss/faiss/IVFlib.cpp +171 -195
- data/vendor/faiss/faiss/IVFlib.h +48 -51
- data/vendor/faiss/faiss/Index.cpp +85 -103
- data/vendor/faiss/faiss/Index.h +54 -48
- data/vendor/faiss/faiss/Index2Layer.cpp +126 -224
- data/vendor/faiss/faiss/Index2Layer.h +22 -36
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +407 -0
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.h +195 -0
- data/vendor/faiss/faiss/IndexBinary.cpp +45 -37
- data/vendor/faiss/faiss/IndexBinary.h +140 -132
- data/vendor/faiss/faiss/IndexBinaryFlat.cpp +73 -53
- data/vendor/faiss/faiss/IndexBinaryFlat.h +29 -24
- data/vendor/faiss/faiss/IndexBinaryFromFloat.cpp +46 -43
- data/vendor/faiss/faiss/IndexBinaryFromFloat.h +16 -15
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +215 -232
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +25 -24
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +182 -177
- data/vendor/faiss/faiss/IndexBinaryHash.h +41 -34
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +489 -461
- data/vendor/faiss/faiss/IndexBinaryIVF.h +97 -68
- data/vendor/faiss/faiss/IndexFlat.cpp +115 -176
- data/vendor/faiss/faiss/IndexFlat.h +42 -59
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +67 -0
- data/vendor/faiss/faiss/IndexFlatCodes.h +47 -0
- data/vendor/faiss/faiss/IndexHNSW.cpp +372 -348
- data/vendor/faiss/faiss/IndexHNSW.h +57 -41
- data/vendor/faiss/faiss/IndexIVF.cpp +545 -453
- data/vendor/faiss/faiss/IndexIVF.h +169 -118
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +316 -0
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.h +121 -0
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +247 -252
- data/vendor/faiss/faiss/IndexIVFFlat.h +48 -51
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +459 -517
- data/vendor/faiss/faiss/IndexIVFPQ.h +75 -67
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +406 -372
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +82 -57
- data/vendor/faiss/faiss/IndexIVFPQR.cpp +104 -102
- data/vendor/faiss/faiss/IndexIVFPQR.h +33 -28
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +163 -150
- data/vendor/faiss/faiss/IndexIVFSpectralHash.h +38 -25
- data/vendor/faiss/faiss/IndexLSH.cpp +66 -113
- data/vendor/faiss/faiss/IndexLSH.h +20 -38
- data/vendor/faiss/faiss/IndexLattice.cpp +42 -56
- data/vendor/faiss/faiss/IndexLattice.h +11 -16
- data/vendor/faiss/faiss/IndexNNDescent.cpp +229 -0
- data/vendor/faiss/faiss/IndexNNDescent.h +72 -0
- data/vendor/faiss/faiss/IndexNSG.cpp +301 -0
- data/vendor/faiss/faiss/IndexNSG.h +85 -0
- data/vendor/faiss/faiss/IndexPQ.cpp +387 -495
- data/vendor/faiss/faiss/IndexPQ.h +64 -82
- data/vendor/faiss/faiss/IndexPQFastScan.cpp +143 -170
- data/vendor/faiss/faiss/IndexPQFastScan.h +46 -32
- data/vendor/faiss/faiss/IndexPreTransform.cpp +120 -150
- data/vendor/faiss/faiss/IndexPreTransform.h +33 -36
- data/vendor/faiss/faiss/IndexRefine.cpp +139 -127
- data/vendor/faiss/faiss/IndexRefine.h +32 -23
- data/vendor/faiss/faiss/IndexReplicas.cpp +147 -153
- data/vendor/faiss/faiss/IndexReplicas.h +62 -56
- data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +111 -172
- data/vendor/faiss/faiss/IndexScalarQuantizer.h +41 -59
- data/vendor/faiss/faiss/IndexShards.cpp +256 -240
- data/vendor/faiss/faiss/IndexShards.h +85 -73
- data/vendor/faiss/faiss/MatrixStats.cpp +112 -97
- data/vendor/faiss/faiss/MatrixStats.h +7 -10
- data/vendor/faiss/faiss/MetaIndexes.cpp +135 -157
- data/vendor/faiss/faiss/MetaIndexes.h +40 -34
- data/vendor/faiss/faiss/MetricType.h +7 -7
- data/vendor/faiss/faiss/VectorTransform.cpp +654 -475
- data/vendor/faiss/faiss/VectorTransform.h +64 -89
- data/vendor/faiss/faiss/clone_index.cpp +78 -73
- data/vendor/faiss/faiss/clone_index.h +4 -9
- data/vendor/faiss/faiss/gpu/GpuAutoTune.cpp +33 -38
- data/vendor/faiss/faiss/gpu/GpuAutoTune.h +11 -9
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +198 -171
- data/vendor/faiss/faiss/gpu/GpuCloner.h +53 -35
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.cpp +12 -14
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +27 -25
- data/vendor/faiss/faiss/gpu/GpuDistance.h +116 -112
- data/vendor/faiss/faiss/gpu/GpuFaissAssert.h +1 -2
- data/vendor/faiss/faiss/gpu/GpuIcmEncoder.h +60 -0
- data/vendor/faiss/faiss/gpu/GpuIndex.h +134 -137
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +76 -73
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +173 -162
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +67 -64
- data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +89 -86
- data/vendor/faiss/faiss/gpu/GpuIndexIVFPQ.h +150 -141
- data/vendor/faiss/faiss/gpu/GpuIndexIVFScalarQuantizer.h +101 -103
- data/vendor/faiss/faiss/gpu/GpuIndicesOptions.h +17 -16
- data/vendor/faiss/faiss/gpu/GpuResources.cpp +116 -128
- data/vendor/faiss/faiss/gpu/GpuResources.h +182 -186
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +433 -422
- data/vendor/faiss/faiss/gpu/StandardGpuResources.h +131 -130
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.cpp +468 -456
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.h +25 -19
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.cpp +22 -20
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.h +9 -8
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper-inl.h +39 -44
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper.h +16 -14
- data/vendor/faiss/faiss/gpu/perf/PerfClustering.cpp +77 -71
- data/vendor/faiss/faiss/gpu/perf/PerfIVFPQAdd.cpp +109 -88
- data/vendor/faiss/faiss/gpu/perf/WriteIndex.cpp +75 -64
- data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +230 -215
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexBinaryFlat.cpp +80 -86
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +284 -277
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +416 -416
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +611 -517
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFScalarQuantizer.cpp +166 -164
- data/vendor/faiss/faiss/gpu/test/TestGpuMemoryException.cpp +61 -53
- data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +274 -238
- data/vendor/faiss/faiss/gpu/test/TestUtils.h +73 -57
- data/vendor/faiss/faiss/gpu/test/demo_ivfpq_indexing_gpu.cpp +47 -50
- data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +79 -72
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +140 -146
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.h +69 -71
- data/vendor/faiss/faiss/gpu/utils/StaticUtils.h +21 -16
- data/vendor/faiss/faiss/gpu/utils/Timer.cpp +25 -29
- data/vendor/faiss/faiss/gpu/utils/Timer.h +30 -29
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +503 -0
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +175 -0
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +90 -120
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +81 -65
- data/vendor/faiss/faiss/impl/FaissAssert.h +73 -58
- data/vendor/faiss/faiss/impl/FaissException.cpp +56 -48
- data/vendor/faiss/faiss/impl/FaissException.h +41 -29
- data/vendor/faiss/faiss/impl/HNSW.cpp +606 -617
- data/vendor/faiss/faiss/impl/HNSW.h +179 -200
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +855 -0
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.h +244 -0
- data/vendor/faiss/faiss/impl/NNDescent.cpp +487 -0
- data/vendor/faiss/faiss/impl/NNDescent.h +154 -0
- data/vendor/faiss/faiss/impl/NSG.cpp +679 -0
- data/vendor/faiss/faiss/impl/NSG.h +199 -0
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +484 -454
- data/vendor/faiss/faiss/impl/PolysemousTraining.h +52 -55
- data/vendor/faiss/faiss/impl/ProductQuantizer-inl.h +26 -47
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +469 -459
- data/vendor/faiss/faiss/impl/ProductQuantizer.h +76 -87
- data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +758 -0
- data/vendor/faiss/faiss/impl/ResidualQuantizer.h +188 -0
- data/vendor/faiss/faiss/impl/ResultHandler.h +96 -132
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +647 -707
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +48 -46
- data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +129 -131
- data/vendor/faiss/faiss/impl/ThreadedIndex.h +61 -55
- data/vendor/faiss/faiss/impl/index_read.cpp +631 -480
- data/vendor/faiss/faiss/impl/index_write.cpp +547 -407
- data/vendor/faiss/faiss/impl/io.cpp +76 -95
- data/vendor/faiss/faiss/impl/io.h +31 -41
- data/vendor/faiss/faiss/impl/io_macros.h +60 -29
- data/vendor/faiss/faiss/impl/kmeans1d.cpp +301 -0
- data/vendor/faiss/faiss/impl/kmeans1d.h +48 -0
- data/vendor/faiss/faiss/impl/lattice_Zn.cpp +137 -186
- data/vendor/faiss/faiss/impl/lattice_Zn.h +40 -51
- data/vendor/faiss/faiss/impl/platform_macros.h +29 -8
- data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +77 -124
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +39 -48
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +41 -52
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +80 -117
- data/vendor/faiss/faiss/impl/simd_result_handlers.h +109 -137
- data/vendor/faiss/faiss/index_factory.cpp +619 -397
- data/vendor/faiss/faiss/index_factory.h +8 -6
- data/vendor/faiss/faiss/index_io.h +23 -26
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +67 -75
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +22 -24
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +96 -112
- data/vendor/faiss/faiss/invlists/DirectMap.h +29 -33
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +307 -364
- data/vendor/faiss/faiss/invlists/InvertedLists.h +151 -151
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +29 -34
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +17 -18
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +257 -293
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +50 -45
- data/vendor/faiss/faiss/python/python_callbacks.cpp +23 -26
- data/vendor/faiss/faiss/python/python_callbacks.h +9 -16
- data/vendor/faiss/faiss/utils/AlignedTable.h +79 -44
- data/vendor/faiss/faiss/utils/Heap.cpp +40 -48
- data/vendor/faiss/faiss/utils/Heap.h +186 -209
- data/vendor/faiss/faiss/utils/WorkerThread.cpp +67 -76
- data/vendor/faiss/faiss/utils/WorkerThread.h +32 -33
- data/vendor/faiss/faiss/utils/distances.cpp +305 -312
- data/vendor/faiss/faiss/utils/distances.h +170 -122
- data/vendor/faiss/faiss/utils/distances_simd.cpp +498 -508
- data/vendor/faiss/faiss/utils/extra_distances-inl.h +117 -0
- data/vendor/faiss/faiss/utils/extra_distances.cpp +113 -232
- data/vendor/faiss/faiss/utils/extra_distances.h +30 -29
- data/vendor/faiss/faiss/utils/hamming-inl.h +260 -209
- data/vendor/faiss/faiss/utils/hamming.cpp +375 -469
- data/vendor/faiss/faiss/utils/hamming.h +62 -85
- data/vendor/faiss/faiss/utils/ordered_key_value.h +16 -18
- data/vendor/faiss/faiss/utils/partitioning.cpp +393 -318
- data/vendor/faiss/faiss/utils/partitioning.h +26 -21
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +78 -66
- data/vendor/faiss/faiss/utils/quantize_lut.h +22 -20
- data/vendor/faiss/faiss/utils/random.cpp +39 -63
- data/vendor/faiss/faiss/utils/random.h +13 -16
- data/vendor/faiss/faiss/utils/simdlib.h +4 -2
- data/vendor/faiss/faiss/utils/simdlib_avx2.h +88 -85
- data/vendor/faiss/faiss/utils/simdlib_emulated.h +226 -165
- data/vendor/faiss/faiss/utils/simdlib_neon.h +832 -0
- data/vendor/faiss/faiss/utils/utils.cpp +304 -287
- data/vendor/faiss/faiss/utils/utils.h +54 -49
- metadata +29 -4
|
@@ -10,62 +10,56 @@
|
|
|
10
10
|
#ifndef FAISS_POLYSEMOUS_TRAINING_INCLUDED
|
|
11
11
|
#define FAISS_POLYSEMOUS_TRAINING_INCLUDED
|
|
12
12
|
|
|
13
|
-
|
|
14
13
|
#include <faiss/impl/ProductQuantizer.h>
|
|
15
14
|
|
|
16
|
-
|
|
17
15
|
namespace faiss {
|
|
18
16
|
|
|
19
|
-
|
|
20
17
|
/// parameters used for the simulated annealing method
|
|
21
18
|
struct SimulatedAnnealingParameters {
|
|
22
|
-
|
|
23
19
|
// optimization parameters
|
|
24
|
-
double init_temperature;
|
|
25
|
-
double temperature_decay;
|
|
26
|
-
|
|
27
|
-
int
|
|
28
|
-
int
|
|
20
|
+
double init_temperature; // init probability of accepting a bad swap
|
|
21
|
+
double temperature_decay; // at each iteration the temp is multiplied by
|
|
22
|
+
// this
|
|
23
|
+
int n_iter; // nb of iterations
|
|
24
|
+
int n_redo; // nb of runs of the simulation
|
|
25
|
+
int seed; // random seed
|
|
29
26
|
int verbose;
|
|
30
27
|
bool only_bit_flips; // restrict permutation changes to bit flips
|
|
31
|
-
bool init_random;
|
|
28
|
+
bool init_random; // initialize with a random permutation (not identity)
|
|
32
29
|
|
|
33
30
|
// set reasonable defaults
|
|
34
|
-
SimulatedAnnealingParameters
|
|
35
|
-
|
|
31
|
+
SimulatedAnnealingParameters();
|
|
36
32
|
};
|
|
37
33
|
|
|
38
|
-
|
|
39
34
|
/// abstract class for the loss function
|
|
40
35
|
struct PermutationObjective {
|
|
41
|
-
|
|
42
36
|
int n;
|
|
43
37
|
|
|
44
|
-
virtual double compute_cost
|
|
38
|
+
virtual double compute_cost(const int* perm) const = 0;
|
|
45
39
|
|
|
46
40
|
// what would the cost update be if iw and jw were swapped?
|
|
47
41
|
// default implementation just computes both and computes the difference
|
|
48
|
-
virtual double cost_update
|
|
42
|
+
virtual double cost_update(const int* perm, int iw, int jw) const;
|
|
49
43
|
|
|
50
|
-
virtual ~PermutationObjective
|
|
44
|
+
virtual ~PermutationObjective() {}
|
|
51
45
|
};
|
|
52
46
|
|
|
53
|
-
|
|
54
47
|
struct ReproduceDistancesObjective : PermutationObjective {
|
|
55
|
-
|
|
56
48
|
double dis_weight_factor;
|
|
57
49
|
|
|
58
|
-
static double sqr
|
|
50
|
+
static double sqr(double x) {
|
|
51
|
+
return x * x;
|
|
52
|
+
}
|
|
59
53
|
|
|
60
54
|
// weighting of distances: it is more important to reproduce small
|
|
61
55
|
// distances well
|
|
62
|
-
double dis_weight
|
|
56
|
+
double dis_weight(double x) const;
|
|
63
57
|
|
|
64
58
|
std::vector<double> source_dis; ///< "real" corrected distances (size n^2)
|
|
65
|
-
const double
|
|
59
|
+
const double* target_dis; ///< wanted distances (size n^2)
|
|
66
60
|
std::vector<double> weights; ///< weights for each distance (size n^2)
|
|
67
61
|
|
|
68
|
-
double get_source_dis
|
|
62
|
+
double get_source_dis(int i, int j) const;
|
|
69
63
|
|
|
70
64
|
// cost = quadratic difference between actual distance and Hamming distance
|
|
71
65
|
double compute_cost(const int* perm) const override;
|
|
@@ -74,16 +68,19 @@ struct ReproduceDistancesObjective : PermutationObjective {
|
|
|
74
68
|
// computed in O(n) instead of O(n^2) for the full re-computation
|
|
75
69
|
double cost_update(const int* perm, int iw, int jw) const override;
|
|
76
70
|
|
|
77
|
-
ReproduceDistancesObjective
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
71
|
+
ReproduceDistancesObjective(
|
|
72
|
+
int n,
|
|
73
|
+
const double* source_dis_in,
|
|
74
|
+
const double* target_dis_in,
|
|
75
|
+
double dis_weight_factor);
|
|
82
76
|
|
|
83
|
-
static void compute_mean_stdev
|
|
84
|
-
|
|
77
|
+
static void compute_mean_stdev(
|
|
78
|
+
const double* tab,
|
|
79
|
+
size_t n2,
|
|
80
|
+
double* mean_out,
|
|
81
|
+
double* stddev_out);
|
|
85
82
|
|
|
86
|
-
void set_affine_target_dis
|
|
83
|
+
void set_affine_target_dis(const double* source_dis_in);
|
|
87
84
|
|
|
88
85
|
~ReproduceDistancesObjective() override {}
|
|
89
86
|
};
|
|
@@ -91,39 +88,36 @@ struct ReproduceDistancesObjective : PermutationObjective {
|
|
|
91
88
|
struct RandomGenerator;
|
|
92
89
|
|
|
93
90
|
/// Simulated annealing optimization algorithm for permutations.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
PermutationObjective *obj;
|
|
91
|
+
struct SimulatedAnnealingOptimizer : SimulatedAnnealingParameters {
|
|
92
|
+
PermutationObjective* obj;
|
|
97
93
|
int n; ///< size of the permutation
|
|
98
|
-
FILE
|
|
94
|
+
FILE* logfile; /// logs values of the cost function
|
|
99
95
|
|
|
100
|
-
SimulatedAnnealingOptimizer
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
SimulatedAnnealingOptimizer(
|
|
97
|
+
PermutationObjective* obj,
|
|
98
|
+
const SimulatedAnnealingParameters& p);
|
|
99
|
+
RandomGenerator* rnd;
|
|
103
100
|
|
|
104
101
|
/// remember initial cost of optimization
|
|
105
102
|
double init_cost;
|
|
106
103
|
|
|
107
104
|
// main entry point. Perform the optimization loop, starting from
|
|
108
105
|
// and modifying permutation in-place
|
|
109
|
-
double optimize
|
|
106
|
+
double optimize(int* perm);
|
|
110
107
|
|
|
111
108
|
// run the optimization and return the best result in best_perm
|
|
112
|
-
double run_optimization
|
|
109
|
+
double run_optimization(int* best_perm);
|
|
113
110
|
|
|
114
|
-
virtual ~SimulatedAnnealingOptimizer
|
|
111
|
+
virtual ~SimulatedAnnealingOptimizer();
|
|
115
112
|
};
|
|
116
113
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
114
|
/// optimizes the order of indices in a ProductQuantizer
|
|
121
|
-
struct PolysemousTraining: SimulatedAnnealingParameters {
|
|
122
|
-
|
|
115
|
+
struct PolysemousTraining : SimulatedAnnealingParameters {
|
|
123
116
|
enum Optimization_type_t {
|
|
124
117
|
OT_None,
|
|
125
|
-
OT_ReproduceDistances_affine,
|
|
126
|
-
OT_Ranking_weighted_diff
|
|
118
|
+
OT_ReproduceDistances_affine, ///< default
|
|
119
|
+
OT_Ranking_weighted_diff ///< same as _2, but use rank of y+ - rank of
|
|
120
|
+
///< y-
|
|
127
121
|
};
|
|
128
122
|
Optimization_type_t optimization_type;
|
|
129
123
|
|
|
@@ -133,26 +127,29 @@ struct PolysemousTraining: SimulatedAnnealingParameters {
|
|
|
133
127
|
int ntrain_permutation;
|
|
134
128
|
double dis_weight_factor; ///< decay of exp that weights distance loss
|
|
135
129
|
|
|
130
|
+
/// refuse to train if it would require more than that amount of RAM
|
|
131
|
+
size_t max_memory;
|
|
132
|
+
|
|
136
133
|
// filename pattern for the logging of iterations
|
|
137
134
|
std::string log_pattern;
|
|
138
135
|
|
|
139
136
|
// sets default values
|
|
140
|
-
PolysemousTraining
|
|
137
|
+
PolysemousTraining();
|
|
141
138
|
|
|
142
139
|
/// reorder the centroids so that the Hamming distance becomes a
|
|
143
140
|
/// good approximation of the SDC distance (called by train)
|
|
144
|
-
void optimize_pq_for_hamming
|
|
145
|
-
|
|
141
|
+
void optimize_pq_for_hamming(ProductQuantizer& pq, size_t n, const float* x)
|
|
142
|
+
const;
|
|
146
143
|
|
|
147
144
|
/// called by optimize_pq_for_hamming
|
|
148
|
-
void optimize_ranking
|
|
145
|
+
void optimize_ranking(ProductQuantizer& pq, size_t n, const float* x) const;
|
|
149
146
|
/// called by optimize_pq_for_hamming
|
|
150
|
-
void optimize_reproduce_distances
|
|
147
|
+
void optimize_reproduce_distances(ProductQuantizer& pq) const;
|
|
151
148
|
|
|
149
|
+
/// make sure we don't blow up the memory
|
|
150
|
+
size_t memory_usage_per_thread(const ProductQuantizer& pq) const;
|
|
152
151
|
};
|
|
153
152
|
|
|
154
|
-
|
|
155
153
|
} // namespace faiss
|
|
156
154
|
|
|
157
|
-
|
|
158
155
|
#endif
|
|
@@ -7,20 +7,18 @@
|
|
|
7
7
|
|
|
8
8
|
namespace faiss {
|
|
9
9
|
|
|
10
|
-
inline
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
{
|
|
10
|
+
inline PQEncoderGeneric::PQEncoderGeneric(
|
|
11
|
+
uint8_t* code,
|
|
12
|
+
int nbits,
|
|
13
|
+
uint8_t offset)
|
|
14
|
+
: code(code), offset(offset), nbits(nbits), reg(0) {
|
|
15
15
|
assert(nbits <= 64);
|
|
16
16
|
if (offset > 0) {
|
|
17
17
|
reg = (*code & ((1 << offset) - 1));
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
inline
|
|
22
|
-
void PQEncoderGeneric::encode(uint64_t x)
|
|
23
|
-
{
|
|
21
|
+
inline void PQEncoderGeneric::encode(uint64_t x) {
|
|
24
22
|
reg |= (uint8_t)(x << offset);
|
|
25
23
|
x >>= (8 - offset);
|
|
26
24
|
if (offset + nbits >= 8) {
|
|
@@ -39,51 +37,39 @@ void PQEncoderGeneric::encode(uint64_t x)
|
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
inline
|
|
43
|
-
PQEncoderGeneric::~PQEncoderGeneric()
|
|
44
|
-
{
|
|
40
|
+
inline PQEncoderGeneric::~PQEncoderGeneric() {
|
|
45
41
|
if (offset > 0) {
|
|
46
42
|
*code = reg;
|
|
47
43
|
}
|
|
48
44
|
}
|
|
49
45
|
|
|
50
|
-
|
|
51
|
-
inline
|
|
52
|
-
PQEncoder8::PQEncoder8(uint8_t *code, int nbits)
|
|
53
|
-
: code(code) {
|
|
46
|
+
inline PQEncoder8::PQEncoder8(uint8_t* code, int nbits) : code(code) {
|
|
54
47
|
assert(8 == nbits);
|
|
55
48
|
}
|
|
56
49
|
|
|
57
|
-
inline
|
|
58
|
-
void PQEncoder8::encode(uint64_t x) {
|
|
50
|
+
inline void PQEncoder8::encode(uint64_t x) {
|
|
59
51
|
*code++ = (uint8_t)x;
|
|
60
52
|
}
|
|
61
53
|
|
|
62
|
-
inline
|
|
63
|
-
|
|
64
|
-
: code((uint16_t *)code) {
|
|
54
|
+
inline PQEncoder16::PQEncoder16(uint8_t* code, int nbits)
|
|
55
|
+
: code((uint16_t*)code) {
|
|
65
56
|
assert(16 == nbits);
|
|
66
57
|
}
|
|
67
58
|
|
|
68
|
-
inline
|
|
69
|
-
void PQEncoder16::encode(uint64_t x) {
|
|
59
|
+
inline void PQEncoder16::encode(uint64_t x) {
|
|
70
60
|
*code++ = (uint16_t)x;
|
|
71
61
|
}
|
|
72
62
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
nbits(nbits),
|
|
80
|
-
mask((1ull << nbits) - 1),
|
|
81
|
-
reg(0) {
|
|
63
|
+
inline PQDecoderGeneric::PQDecoderGeneric(const uint8_t* code, int nbits)
|
|
64
|
+
: code(code),
|
|
65
|
+
offset(0),
|
|
66
|
+
nbits(nbits),
|
|
67
|
+
mask((1ull << nbits) - 1),
|
|
68
|
+
reg(0) {
|
|
82
69
|
assert(nbits <= 64);
|
|
83
70
|
}
|
|
84
71
|
|
|
85
|
-
inline
|
|
86
|
-
uint64_t PQDecoderGeneric::decode() {
|
|
72
|
+
inline uint64_t PQDecoderGeneric::decode() {
|
|
87
73
|
if (offset == 0) {
|
|
88
74
|
reg = *code;
|
|
89
75
|
}
|
|
@@ -110,27 +96,20 @@ uint64_t PQDecoderGeneric::decode() {
|
|
|
110
96
|
return c & mask;
|
|
111
97
|
}
|
|
112
98
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
PQDecoder8::PQDecoder8(const uint8_t *code, int nbits)
|
|
116
|
-
: code(code) {
|
|
117
|
-
assert(8 == nbits);
|
|
99
|
+
inline PQDecoder8::PQDecoder8(const uint8_t* code, int nbits_in) : code(code) {
|
|
100
|
+
assert(8 == nbits_in);
|
|
118
101
|
}
|
|
119
102
|
|
|
120
|
-
inline
|
|
121
|
-
uint64_t PQDecoder8::decode() {
|
|
103
|
+
inline uint64_t PQDecoder8::decode() {
|
|
122
104
|
return (uint64_t)(*code++);
|
|
123
105
|
}
|
|
124
106
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
: code((uint16_t *)code) {
|
|
129
|
-
assert(16 == nbits);
|
|
107
|
+
inline PQDecoder16::PQDecoder16(const uint8_t* code, int nbits_in)
|
|
108
|
+
: code((uint16_t*)code) {
|
|
109
|
+
assert(16 == nbits_in);
|
|
130
110
|
}
|
|
131
111
|
|
|
132
|
-
inline
|
|
133
|
-
uint64_t PQDecoder16::decode() {
|
|
112
|
+
inline uint64_t PQDecoder16::decode() {
|
|
134
113
|
return (uint64_t)(*code++);
|
|
135
114
|
}
|
|
136
115
|
|