faiss 0.1.3 → 0.1.4
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/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/ext/faiss/extconf.rb +1 -1
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +36 -33
- data/vendor/faiss/faiss/AutoTune.h +6 -3
- data/vendor/faiss/faiss/Clustering.cpp +16 -12
- data/vendor/faiss/faiss/Index.cpp +3 -4
- data/vendor/faiss/faiss/Index.h +3 -3
- data/vendor/faiss/faiss/IndexBinary.cpp +3 -4
- data/vendor/faiss/faiss/IndexBinary.h +1 -1
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +2 -12
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +1 -2
- data/vendor/faiss/faiss/IndexFlat.cpp +0 -148
- data/vendor/faiss/faiss/IndexFlat.h +0 -51
- data/vendor/faiss/faiss/IndexHNSW.cpp +4 -5
- data/vendor/faiss/faiss/IndexIVF.cpp +118 -31
- data/vendor/faiss/faiss/IndexIVF.h +22 -15
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +3 -3
- data/vendor/faiss/faiss/IndexIVFFlat.h +2 -1
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +39 -15
- data/vendor/faiss/faiss/IndexIVFPQ.h +25 -9
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +1116 -0
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +166 -0
- data/vendor/faiss/faiss/IndexIVFPQR.cpp +8 -9
- data/vendor/faiss/faiss/IndexIVFPQR.h +2 -1
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +1 -2
- data/vendor/faiss/faiss/IndexPQ.cpp +34 -18
- data/vendor/faiss/faiss/IndexPQFastScan.cpp +536 -0
- data/vendor/faiss/faiss/IndexPQFastScan.h +111 -0
- data/vendor/faiss/faiss/IndexPreTransform.cpp +47 -0
- data/vendor/faiss/faiss/IndexPreTransform.h +2 -0
- data/vendor/faiss/faiss/IndexRefine.cpp +256 -0
- data/vendor/faiss/faiss/IndexRefine.h +73 -0
- data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +2 -2
- data/vendor/faiss/faiss/IndexScalarQuantizer.h +1 -1
- data/vendor/faiss/faiss/gpu/GpuDistance.h +1 -1
- data/vendor/faiss/faiss/gpu/GpuIndex.h +16 -9
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +8 -1
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +11 -11
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +19 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +28 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVFPQ.h +24 -14
- data/vendor/faiss/faiss/gpu/GpuIndexIVFScalarQuantizer.h +29 -2
- data/vendor/faiss/faiss/gpu/GpuResources.h +4 -0
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +60 -27
- data/vendor/faiss/faiss/gpu/StandardGpuResources.h +28 -6
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.cpp +547 -0
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.h +51 -0
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.cpp +3 -3
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.h +3 -2
- data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +274 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +7 -2
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +5 -1
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFScalarQuantizer.cpp +231 -0
- data/vendor/faiss/faiss/gpu/test/TestUtils.h +33 -0
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +1 -0
- data/vendor/faiss/faiss/gpu/utils/StaticUtils.h +6 -0
- data/vendor/faiss/faiss/gpu/utils/Timer.cpp +5 -6
- data/vendor/faiss/faiss/gpu/utils/Timer.h +2 -2
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +5 -4
- data/vendor/faiss/faiss/impl/HNSW.cpp +2 -4
- data/vendor/faiss/faiss/impl/PolysemousTraining.h +4 -4
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +22 -12
- data/vendor/faiss/faiss/impl/ProductQuantizer.h +2 -0
- data/vendor/faiss/faiss/impl/ResultHandler.h +452 -0
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +29 -19
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +6 -0
- data/vendor/faiss/faiss/impl/index_read.cpp +64 -96
- data/vendor/faiss/faiss/impl/index_write.cpp +34 -25
- data/vendor/faiss/faiss/impl/io.cpp +33 -2
- data/vendor/faiss/faiss/impl/io.h +7 -2
- data/vendor/faiss/faiss/impl/lattice_Zn.cpp +1 -15
- data/vendor/faiss/faiss/impl/platform_macros.h +44 -0
- data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +272 -0
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +169 -0
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +180 -0
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +354 -0
- data/vendor/faiss/faiss/impl/simd_result_handlers.h +559 -0
- data/vendor/faiss/faiss/index_factory.cpp +112 -7
- data/vendor/faiss/faiss/index_io.h +1 -48
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +151 -0
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +76 -0
- data/vendor/faiss/faiss/{DirectMap.cpp → invlists/DirectMap.cpp} +1 -1
- data/vendor/faiss/faiss/{DirectMap.h → invlists/DirectMap.h} +1 -1
- data/vendor/faiss/faiss/{InvertedLists.cpp → invlists/InvertedLists.cpp} +72 -1
- data/vendor/faiss/faiss/{InvertedLists.h → invlists/InvertedLists.h} +32 -1
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +107 -0
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +63 -0
- data/vendor/faiss/faiss/{OnDiskInvertedLists.cpp → invlists/OnDiskInvertedLists.cpp} +21 -6
- data/vendor/faiss/faiss/{OnDiskInvertedLists.h → invlists/OnDiskInvertedLists.h} +5 -2
- data/vendor/faiss/faiss/python/python_callbacks.h +8 -1
- data/vendor/faiss/faiss/utils/AlignedTable.h +141 -0
- data/vendor/faiss/faiss/utils/Heap.cpp +2 -4
- data/vendor/faiss/faiss/utils/Heap.h +61 -50
- data/vendor/faiss/faiss/utils/distances.cpp +164 -319
- data/vendor/faiss/faiss/utils/distances.h +28 -20
- data/vendor/faiss/faiss/utils/distances_simd.cpp +277 -49
- data/vendor/faiss/faiss/utils/extra_distances.cpp +1 -2
- data/vendor/faiss/faiss/utils/hamming-inl.h +4 -4
- data/vendor/faiss/faiss/utils/hamming.cpp +3 -6
- data/vendor/faiss/faiss/utils/hamming.h +2 -7
- data/vendor/faiss/faiss/utils/ordered_key_value.h +98 -0
- data/vendor/faiss/faiss/utils/partitioning.cpp +1256 -0
- data/vendor/faiss/faiss/utils/partitioning.h +69 -0
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +277 -0
- data/vendor/faiss/faiss/utils/quantize_lut.h +80 -0
- data/vendor/faiss/faiss/utils/simdlib.h +31 -0
- data/vendor/faiss/faiss/utils/simdlib_avx2.h +461 -0
- data/vendor/faiss/faiss/utils/simdlib_emulated.h +589 -0
- metadata +43 -141
- data/vendor/faiss/benchs/bench_6bit_codec.cpp +0 -80
- data/vendor/faiss/c_api/AutoTune_c.cpp +0 -83
- data/vendor/faiss/c_api/AutoTune_c.h +0 -66
- data/vendor/faiss/c_api/Clustering_c.cpp +0 -145
- data/vendor/faiss/c_api/Clustering_c.h +0 -123
- data/vendor/faiss/c_api/IndexFlat_c.cpp +0 -140
- data/vendor/faiss/c_api/IndexFlat_c.h +0 -115
- data/vendor/faiss/c_api/IndexIVFFlat_c.cpp +0 -64
- data/vendor/faiss/c_api/IndexIVFFlat_c.h +0 -58
- data/vendor/faiss/c_api/IndexIVF_c.cpp +0 -99
- data/vendor/faiss/c_api/IndexIVF_c.h +0 -142
- data/vendor/faiss/c_api/IndexLSH_c.cpp +0 -37
- data/vendor/faiss/c_api/IndexLSH_c.h +0 -40
- data/vendor/faiss/c_api/IndexPreTransform_c.cpp +0 -21
- data/vendor/faiss/c_api/IndexPreTransform_c.h +0 -32
- data/vendor/faiss/c_api/IndexShards_c.cpp +0 -38
- data/vendor/faiss/c_api/IndexShards_c.h +0 -39
- data/vendor/faiss/c_api/Index_c.cpp +0 -105
- data/vendor/faiss/c_api/Index_c.h +0 -183
- data/vendor/faiss/c_api/MetaIndexes_c.cpp +0 -49
- data/vendor/faiss/c_api/MetaIndexes_c.h +0 -49
- data/vendor/faiss/c_api/clone_index_c.cpp +0 -23
- data/vendor/faiss/c_api/clone_index_c.h +0 -32
- data/vendor/faiss/c_api/error_c.h +0 -42
- data/vendor/faiss/c_api/error_impl.cpp +0 -27
- data/vendor/faiss/c_api/error_impl.h +0 -16
- data/vendor/faiss/c_api/faiss_c.h +0 -58
- data/vendor/faiss/c_api/gpu/GpuAutoTune_c.cpp +0 -98
- data/vendor/faiss/c_api/gpu/GpuAutoTune_c.h +0 -56
- data/vendor/faiss/c_api/gpu/GpuClonerOptions_c.cpp +0 -52
- data/vendor/faiss/c_api/gpu/GpuClonerOptions_c.h +0 -68
- data/vendor/faiss/c_api/gpu/GpuIndex_c.cpp +0 -17
- data/vendor/faiss/c_api/gpu/GpuIndex_c.h +0 -30
- data/vendor/faiss/c_api/gpu/GpuIndicesOptions_c.h +0 -38
- data/vendor/faiss/c_api/gpu/GpuResources_c.cpp +0 -86
- data/vendor/faiss/c_api/gpu/GpuResources_c.h +0 -66
- data/vendor/faiss/c_api/gpu/StandardGpuResources_c.cpp +0 -54
- data/vendor/faiss/c_api/gpu/StandardGpuResources_c.h +0 -53
- data/vendor/faiss/c_api/gpu/macros_impl.h +0 -42
- data/vendor/faiss/c_api/impl/AuxIndexStructures_c.cpp +0 -220
- data/vendor/faiss/c_api/impl/AuxIndexStructures_c.h +0 -149
- data/vendor/faiss/c_api/index_factory_c.cpp +0 -26
- data/vendor/faiss/c_api/index_factory_c.h +0 -30
- data/vendor/faiss/c_api/index_io_c.cpp +0 -42
- data/vendor/faiss/c_api/index_io_c.h +0 -50
- data/vendor/faiss/c_api/macros_impl.h +0 -110
- data/vendor/faiss/demos/demo_imi_flat.cpp +0 -154
- data/vendor/faiss/demos/demo_imi_pq.cpp +0 -203
- data/vendor/faiss/demos/demo_ivfpq_indexing.cpp +0 -151
- data/vendor/faiss/demos/demo_sift1M.cpp +0 -252
- data/vendor/faiss/demos/demo_weighted_kmeans.cpp +0 -185
- data/vendor/faiss/misc/test_blas.cpp +0 -87
- data/vendor/faiss/tests/test_binary_flat.cpp +0 -62
- data/vendor/faiss/tests/test_dealloc_invlists.cpp +0 -188
- data/vendor/faiss/tests/test_ivfpq_codec.cpp +0 -70
- data/vendor/faiss/tests/test_ivfpq_indexing.cpp +0 -100
- data/vendor/faiss/tests/test_lowlevel_ivf.cpp +0 -573
- data/vendor/faiss/tests/test_merge.cpp +0 -260
- data/vendor/faiss/tests/test_omp_threads.cpp +0 -14
- data/vendor/faiss/tests/test_ondisk_ivf.cpp +0 -225
- data/vendor/faiss/tests/test_pairs_decoding.cpp +0 -193
- data/vendor/faiss/tests/test_params_override.cpp +0 -236
- data/vendor/faiss/tests/test_pq_encoding.cpp +0 -98
- data/vendor/faiss/tests/test_sliding_ivf.cpp +0 -246
- data/vendor/faiss/tests/test_threaded_index.cpp +0 -253
- data/vendor/faiss/tests/test_transfer_invlists.cpp +0 -159
- data/vendor/faiss/tutorial/cpp/1-Flat.cpp +0 -104
- data/vendor/faiss/tutorial/cpp/2-IVFFlat.cpp +0 -85
- data/vendor/faiss/tutorial/cpp/3-IVFPQ.cpp +0 -98
- data/vendor/faiss/tutorial/cpp/4-GPU.cpp +0 -122
- data/vendor/faiss/tutorial/cpp/5-Multiple-GPUs.cpp +0 -104
@@ -1,42 +0,0 @@
|
|
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
|
-
// Copyright 2004-present Facebook. All Rights Reserved.
|
9
|
-
// -*- c++ -*-
|
10
|
-
|
11
|
-
#ifndef GPU_MACROS_IMPL_H
|
12
|
-
#define GPU_MACROS_IMPL_H
|
13
|
-
#include "../macros_impl.h"
|
14
|
-
|
15
|
-
#undef DEFINE_GETTER
|
16
|
-
#define DEFINE_GETTER(clazz, ty, name) \
|
17
|
-
ty faiss_ ## clazz ## _ ## name (const Faiss ## clazz *obj) { \
|
18
|
-
return static_cast< ty >( \
|
19
|
-
reinterpret_cast< const faiss::gpu::clazz *>(obj)-> name \
|
20
|
-
); \
|
21
|
-
}
|
22
|
-
|
23
|
-
#undef DEFINE_SETTER
|
24
|
-
#define DEFINE_SETTER(clazz, ty, name) \
|
25
|
-
void faiss_ ## clazz ## _set_ ## name (Faiss ## clazz *obj, ty val) { \
|
26
|
-
reinterpret_cast< faiss::gpu::clazz *>(obj)-> name = val; \
|
27
|
-
}
|
28
|
-
|
29
|
-
#undef DEFINE_SETTER_STATIC
|
30
|
-
#define DEFINE_SETTER_STATIC(clazz, ty_to, ty_from, name) \
|
31
|
-
void faiss_ ## clazz ## _set_ ## name (Faiss ## clazz *obj, ty_from val) { \
|
32
|
-
reinterpret_cast< faiss::gpu::clazz *>(obj)-> name = \
|
33
|
-
static_cast< ty_to >(val); \
|
34
|
-
}
|
35
|
-
|
36
|
-
#undef DEFINE_DESTRUCTOR
|
37
|
-
#define DEFINE_DESTRUCTOR(clazz) \
|
38
|
-
void faiss_ ## clazz ## _free (Faiss ## clazz *obj) { \
|
39
|
-
delete reinterpret_cast<faiss::gpu::clazz *>(obj); \
|
40
|
-
}
|
41
|
-
|
42
|
-
#endif
|
@@ -1,220 +0,0 @@
|
|
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
|
-
// Copyright 2004-present Facebook. All Rights Reserved.
|
9
|
-
// -*- c++ -*-
|
10
|
-
|
11
|
-
#include "AuxIndexStructures_c.h"
|
12
|
-
#include "../../impl/AuxIndexStructures.h"
|
13
|
-
#include "../macros_impl.h"
|
14
|
-
#include <iostream>
|
15
|
-
|
16
|
-
using faiss::BufferList;
|
17
|
-
using faiss::IDSelector;
|
18
|
-
using faiss::IDSelectorBatch;
|
19
|
-
using faiss::IDSelectorRange;
|
20
|
-
using faiss::RangeSearchResult;
|
21
|
-
using faiss::RangeSearchPartialResult;
|
22
|
-
using faiss::RangeQueryResult;
|
23
|
-
using faiss::DistanceComputer;
|
24
|
-
|
25
|
-
DEFINE_GETTER(RangeSearchResult, size_t, nq)
|
26
|
-
|
27
|
-
int faiss_RangeSearchResult_new(FaissRangeSearchResult** p_rsr, idx_t nq) {
|
28
|
-
try {
|
29
|
-
*p_rsr = reinterpret_cast<FaissRangeSearchResult*>(
|
30
|
-
new RangeSearchResult(nq));
|
31
|
-
return 0;
|
32
|
-
} CATCH_AND_HANDLE
|
33
|
-
}
|
34
|
-
|
35
|
-
int faiss_RangeSearchResult_new_with(FaissRangeSearchResult** p_rsr, idx_t nq, int alloc_lims) {
|
36
|
-
try {
|
37
|
-
*p_rsr = reinterpret_cast<FaissRangeSearchResult*>(
|
38
|
-
new RangeSearchResult(nq, static_cast<bool>(alloc_lims)));
|
39
|
-
return 0;
|
40
|
-
} CATCH_AND_HANDLE
|
41
|
-
}
|
42
|
-
|
43
|
-
/// called when lims contains the nb of elements result entries
|
44
|
-
/// for each query
|
45
|
-
int faiss_RangeSearchResult_do_allocation(FaissRangeSearchResult* rsr) {
|
46
|
-
try {
|
47
|
-
reinterpret_cast<RangeSearchResult*>(rsr)->do_allocation();
|
48
|
-
return 0;
|
49
|
-
} CATCH_AND_HANDLE
|
50
|
-
}
|
51
|
-
|
52
|
-
DEFINE_DESTRUCTOR(RangeSearchResult)
|
53
|
-
|
54
|
-
/// getter for buffer_size
|
55
|
-
DEFINE_GETTER(RangeSearchResult, size_t, buffer_size)
|
56
|
-
|
57
|
-
/// getter for lims: size (nq + 1)
|
58
|
-
void faiss_RangeSearchResult_lims(FaissRangeSearchResult* rsr, size_t** lims) {
|
59
|
-
*lims = reinterpret_cast<RangeSearchResult*>(rsr)->lims;
|
60
|
-
}
|
61
|
-
|
62
|
-
/// getter for labels and respective distances (not sorted):
|
63
|
-
/// result for query i is labels[lims[i]:lims[i+1]]
|
64
|
-
void faiss_RangeSearchResult_labels(FaissRangeSearchResult* rsr, idx_t** labels, float** distances) {
|
65
|
-
auto sr = reinterpret_cast<RangeSearchResult*>(rsr);
|
66
|
-
*labels = sr->labels;
|
67
|
-
*distances = sr->distances;
|
68
|
-
}
|
69
|
-
|
70
|
-
DEFINE_DESTRUCTOR(IDSelector)
|
71
|
-
|
72
|
-
int faiss_IDSelector_is_member(const FaissIDSelector* sel, idx_t id) {
|
73
|
-
return reinterpret_cast<const IDSelector*>(sel)->is_member(id);
|
74
|
-
}
|
75
|
-
|
76
|
-
DEFINE_DESTRUCTOR(IDSelectorRange)
|
77
|
-
|
78
|
-
DEFINE_GETTER(IDSelectorRange, idx_t, imin)
|
79
|
-
DEFINE_GETTER(IDSelectorRange, idx_t, imax)
|
80
|
-
|
81
|
-
int faiss_IDSelectorRange_new(FaissIDSelectorRange** p_sel, idx_t imin, idx_t imax) {
|
82
|
-
try {
|
83
|
-
*p_sel = reinterpret_cast<FaissIDSelectorRange*>(
|
84
|
-
new IDSelectorRange(imin, imax)
|
85
|
-
);
|
86
|
-
return 0;
|
87
|
-
} CATCH_AND_HANDLE
|
88
|
-
}
|
89
|
-
|
90
|
-
DEFINE_GETTER(IDSelectorBatch, int, nbits)
|
91
|
-
DEFINE_GETTER(IDSelectorBatch, idx_t, mask)
|
92
|
-
|
93
|
-
int faiss_IDSelectorBatch_new(FaissIDSelectorBatch** p_sel, size_t n, const idx_t* indices) {
|
94
|
-
try {
|
95
|
-
*p_sel = reinterpret_cast<FaissIDSelectorBatch*>(
|
96
|
-
new IDSelectorBatch(n, indices)
|
97
|
-
);
|
98
|
-
return 0;
|
99
|
-
} CATCH_AND_HANDLE
|
100
|
-
}
|
101
|
-
|
102
|
-
// Below are structures used only by Index implementations
|
103
|
-
|
104
|
-
DEFINE_DESTRUCTOR(BufferList)
|
105
|
-
|
106
|
-
DEFINE_GETTER(BufferList, size_t, buffer_size)
|
107
|
-
DEFINE_GETTER(BufferList, size_t, wp)
|
108
|
-
|
109
|
-
int faiss_BufferList_append_buffer(FaissBufferList* bl) {
|
110
|
-
try {
|
111
|
-
reinterpret_cast<BufferList*>(bl)->append_buffer();
|
112
|
-
return 0;
|
113
|
-
} CATCH_AND_HANDLE
|
114
|
-
}
|
115
|
-
|
116
|
-
int faiss_BufferList_new(FaissBufferList** p_bl, size_t buffer_size) {
|
117
|
-
try {
|
118
|
-
*p_bl = reinterpret_cast<FaissBufferList*>(
|
119
|
-
new BufferList(buffer_size)
|
120
|
-
);
|
121
|
-
return 0;
|
122
|
-
} CATCH_AND_HANDLE
|
123
|
-
}
|
124
|
-
|
125
|
-
int faiss_BufferList_add(FaissBufferList* bl, idx_t id, float dis) {
|
126
|
-
try {
|
127
|
-
reinterpret_cast<BufferList*>(bl)->add(id, dis);
|
128
|
-
return 0;
|
129
|
-
} CATCH_AND_HANDLE
|
130
|
-
}
|
131
|
-
|
132
|
-
/// copy elemnts ofs:ofs+n-1 seen as linear data in the buffers to
|
133
|
-
/// tables dest_ids, dest_dis
|
134
|
-
int faiss_BufferList_copy_range(
|
135
|
-
FaissBufferList* bl, size_t ofs, size_t n, idx_t *dest_ids, float *dest_dis) {
|
136
|
-
try {
|
137
|
-
reinterpret_cast<BufferList*>(bl)->copy_range(ofs, n, dest_ids, dest_dis);
|
138
|
-
return 0;
|
139
|
-
} CATCH_AND_HANDLE
|
140
|
-
}
|
141
|
-
|
142
|
-
DEFINE_GETTER(RangeQueryResult, idx_t, qno)
|
143
|
-
DEFINE_GETTER(RangeQueryResult, size_t, nres)
|
144
|
-
DEFINE_GETTER_PERMISSIVE(RangeQueryResult, FaissRangeSearchPartialResult*, pres)
|
145
|
-
|
146
|
-
int faiss_RangeQueryResult_add(FaissRangeQueryResult* qr, float dis, idx_t id) {
|
147
|
-
try {
|
148
|
-
reinterpret_cast<RangeQueryResult*>(qr)->add(dis, id);
|
149
|
-
return 0;
|
150
|
-
} CATCH_AND_HANDLE
|
151
|
-
}
|
152
|
-
|
153
|
-
DEFINE_GETTER_PERMISSIVE(RangeSearchPartialResult, FaissRangeSearchResult*, res)
|
154
|
-
|
155
|
-
int faiss_RangeSearchPartialResult_new(
|
156
|
-
FaissRangeSearchPartialResult** p_res, FaissRangeSearchResult* res_in) {
|
157
|
-
try {
|
158
|
-
*p_res = reinterpret_cast<FaissRangeSearchPartialResult*>(
|
159
|
-
new RangeSearchPartialResult(
|
160
|
-
reinterpret_cast<RangeSearchResult*>(res_in))
|
161
|
-
);
|
162
|
-
return 0;
|
163
|
-
} CATCH_AND_HANDLE
|
164
|
-
}
|
165
|
-
|
166
|
-
int faiss_RangeSearchPartialResult_finalize(
|
167
|
-
FaissRangeSearchPartialResult* res) {
|
168
|
-
try {
|
169
|
-
reinterpret_cast<RangeSearchPartialResult*>(res)->finalize();
|
170
|
-
return 0;
|
171
|
-
} CATCH_AND_HANDLE
|
172
|
-
}
|
173
|
-
|
174
|
-
/// called by range_search before do_allocation
|
175
|
-
int faiss_RangeSearchPartialResult_set_lims(
|
176
|
-
FaissRangeSearchPartialResult* res) {
|
177
|
-
try {
|
178
|
-
reinterpret_cast<RangeSearchPartialResult*>(res)->set_lims();
|
179
|
-
return 0;
|
180
|
-
} CATCH_AND_HANDLE
|
181
|
-
}
|
182
|
-
|
183
|
-
int faiss_RangeSearchPartialResult_new_result(
|
184
|
-
FaissRangeSearchPartialResult* res, idx_t qno, FaissRangeQueryResult** qr) {
|
185
|
-
|
186
|
-
try {
|
187
|
-
auto q =
|
188
|
-
&reinterpret_cast<RangeSearchPartialResult*>(res)->new_result(qno);
|
189
|
-
if (qr) {
|
190
|
-
*qr = reinterpret_cast<FaissRangeQueryResult*>(&q);
|
191
|
-
}
|
192
|
-
return 0;
|
193
|
-
} CATCH_AND_HANDLE
|
194
|
-
}
|
195
|
-
|
196
|
-
DEFINE_DESTRUCTOR(DistanceComputer)
|
197
|
-
|
198
|
-
int faiss_DistanceComputer_set_query(FaissDistanceComputer *dc, const float *x) {
|
199
|
-
try {
|
200
|
-
reinterpret_cast<DistanceComputer*>(dc)->set_query(x);
|
201
|
-
return 0;
|
202
|
-
}
|
203
|
-
CATCH_AND_HANDLE
|
204
|
-
}
|
205
|
-
|
206
|
-
int faiss_DistanceComputer_vector_to_query_dis(FaissDistanceComputer *dc, idx_t i, float *qd) {
|
207
|
-
try {
|
208
|
-
*qd = reinterpret_cast<DistanceComputer*>(dc)->operator()(i);
|
209
|
-
return 0;
|
210
|
-
}
|
211
|
-
CATCH_AND_HANDLE
|
212
|
-
}
|
213
|
-
|
214
|
-
int faiss_DistanceComputer_symmetric_dis(FaissDistanceComputer *dc, idx_t i, idx_t j, float *vd) {
|
215
|
-
try {
|
216
|
-
*vd = reinterpret_cast<DistanceComputer*>(dc)->symmetric_dis(i, j);
|
217
|
-
return 0;
|
218
|
-
}
|
219
|
-
CATCH_AND_HANDLE
|
220
|
-
}
|
@@ -1,149 +0,0 @@
|
|
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
|
-
// Copyright 2004-present Facebook. All Rights Reserved.
|
9
|
-
// -*- c -*-
|
10
|
-
|
11
|
-
#ifndef FAISS_AUX_INDEX_STRUCTURES_C_H
|
12
|
-
#define FAISS_AUX_INDEX_STRUCTURES_C_H
|
13
|
-
|
14
|
-
#include "../Index_c.h"
|
15
|
-
#include "../faiss_c.h"
|
16
|
-
|
17
|
-
#ifdef __cplusplus
|
18
|
-
extern "C" {
|
19
|
-
#endif
|
20
|
-
|
21
|
-
FAISS_DECLARE_CLASS(RangeSearchResult)
|
22
|
-
|
23
|
-
FAISS_DECLARE_GETTER(RangeSearchResult, size_t, nq)
|
24
|
-
|
25
|
-
int faiss_RangeSearchResult_new(FaissRangeSearchResult** p_rsr, idx_t nq);
|
26
|
-
|
27
|
-
int faiss_RangeSearchResult_new_with(FaissRangeSearchResult** p_rsr, idx_t nq, int alloc_lims);
|
28
|
-
|
29
|
-
/// called when lims contains the nb of elements result entries
|
30
|
-
/// for each query
|
31
|
-
int faiss_RangeSearchResult_do_allocation(FaissRangeSearchResult* rsr);
|
32
|
-
|
33
|
-
FAISS_DECLARE_DESTRUCTOR(RangeSearchResult)
|
34
|
-
|
35
|
-
/// getter for buffer_size
|
36
|
-
FAISS_DECLARE_GETTER(RangeSearchResult, size_t, buffer_size)
|
37
|
-
|
38
|
-
/// getter for lims: size (nq + 1)
|
39
|
-
void faiss_RangeSearchResult_lims(
|
40
|
-
FaissRangeSearchResult* rsr, size_t** lims);
|
41
|
-
|
42
|
-
/// getter for labels and respective distances (not sorted):
|
43
|
-
/// result for query i is labels[lims[i]:lims[i+1]]
|
44
|
-
void faiss_RangeSearchResult_labels(
|
45
|
-
FaissRangeSearchResult* rsr, idx_t** labels, float** distances);
|
46
|
-
|
47
|
-
|
48
|
-
/** Encapsulates a set of ids to remove. */
|
49
|
-
FAISS_DECLARE_CLASS(IDSelector)
|
50
|
-
FAISS_DECLARE_DESTRUCTOR(IDSelector)
|
51
|
-
|
52
|
-
int faiss_IDSelector_is_member(const FaissIDSelector* sel, idx_t id);
|
53
|
-
|
54
|
-
/** remove ids between [imni, imax) */
|
55
|
-
FAISS_DECLARE_CLASS(IDSelectorRange)
|
56
|
-
FAISS_DECLARE_DESTRUCTOR(IDSelectorRange)
|
57
|
-
|
58
|
-
FAISS_DECLARE_GETTER(IDSelectorRange, idx_t, imin)
|
59
|
-
FAISS_DECLARE_GETTER(IDSelectorRange, idx_t, imax)
|
60
|
-
|
61
|
-
int faiss_IDSelectorRange_new(FaissIDSelectorRange** p_sel, idx_t imin, idx_t imax);
|
62
|
-
|
63
|
-
/** Remove ids from a set. Repetitions of ids in the indices set
|
64
|
-
* passed to the constructor does not hurt performance. The hash
|
65
|
-
* function used for the bloom filter and GCC's implementation of
|
66
|
-
* unordered_set are just the least significant bits of the id. This
|
67
|
-
* works fine for random ids or ids in sequences but will produce many
|
68
|
-
* hash collisions if lsb's are always the same */
|
69
|
-
FAISS_DECLARE_CLASS(IDSelectorBatch)
|
70
|
-
|
71
|
-
FAISS_DECLARE_GETTER(IDSelectorBatch, int, nbits)
|
72
|
-
FAISS_DECLARE_GETTER(IDSelectorBatch, idx_t, mask)
|
73
|
-
|
74
|
-
int faiss_IDSelectorBatch_new(FaissIDSelectorBatch** p_sel, size_t n, const idx_t* indices);
|
75
|
-
|
76
|
-
// Below are structures used only by Index implementations
|
77
|
-
|
78
|
-
/** List of temporary buffers used to store results before they are
|
79
|
-
* copied to the RangeSearchResult object. */
|
80
|
-
FAISS_DECLARE_CLASS(BufferList)
|
81
|
-
FAISS_DECLARE_DESTRUCTOR(BufferList)
|
82
|
-
|
83
|
-
FAISS_DECLARE_GETTER(BufferList, size_t, buffer_size)
|
84
|
-
FAISS_DECLARE_GETTER(BufferList, size_t, wp)
|
85
|
-
|
86
|
-
typedef struct FaissBuffer {
|
87
|
-
idx_t *ids;
|
88
|
-
float *dis;
|
89
|
-
} FaissBuffer;
|
90
|
-
|
91
|
-
int faiss_BufferList_append_buffer(FaissBufferList* bl);
|
92
|
-
|
93
|
-
int faiss_BufferList_new(FaissBufferList** p_bl, size_t buffer_size);
|
94
|
-
|
95
|
-
int faiss_BufferList_add(FaissBufferList* bl, idx_t id, float dis);
|
96
|
-
|
97
|
-
/// copy elemnts ofs:ofs+n-1 seen as linear data in the buffers to
|
98
|
-
/// tables dest_ids, dest_dis
|
99
|
-
int faiss_BufferList_copy_range(
|
100
|
-
FaissBufferList* bl, size_t ofs, size_t n, idx_t *dest_ids, float *dest_dis);
|
101
|
-
|
102
|
-
/// the entries in the buffers are split per query
|
103
|
-
FAISS_DECLARE_CLASS(RangeSearchPartialResult)
|
104
|
-
|
105
|
-
/// result structure for a single query
|
106
|
-
FAISS_DECLARE_CLASS(RangeQueryResult)
|
107
|
-
FAISS_DECLARE_GETTER(RangeQueryResult, idx_t, qno)
|
108
|
-
FAISS_DECLARE_GETTER(RangeQueryResult, size_t, nres)
|
109
|
-
FAISS_DECLARE_GETTER(RangeQueryResult, FaissRangeSearchPartialResult*, pres)
|
110
|
-
|
111
|
-
int faiss_RangeQueryResult_add(FaissRangeQueryResult* qr, float dis, idx_t id);
|
112
|
-
|
113
|
-
|
114
|
-
FAISS_DECLARE_GETTER(RangeSearchPartialResult, FaissRangeSearchResult*, res)
|
115
|
-
|
116
|
-
int faiss_RangeSearchPartialResult_new(
|
117
|
-
FaissRangeSearchPartialResult** p_res, FaissRangeSearchResult* res_in);
|
118
|
-
|
119
|
-
int faiss_RangeSearchPartialResult_finalize(
|
120
|
-
FaissRangeSearchPartialResult* res);
|
121
|
-
|
122
|
-
/// called by range_search before do_allocation
|
123
|
-
int faiss_RangeSearchPartialResult_set_lims(
|
124
|
-
FaissRangeSearchPartialResult* res);
|
125
|
-
|
126
|
-
int faiss_RangeSearchPartialResult_new_result(
|
127
|
-
FaissRangeSearchPartialResult* res, idx_t qno, FaissRangeQueryResult** qr);
|
128
|
-
|
129
|
-
|
130
|
-
FAISS_DECLARE_CLASS(DistanceComputer)
|
131
|
-
/// called before computing distances
|
132
|
-
int faiss_DistanceComputer_set_query(FaissDistanceComputer *dc, const float *x);
|
133
|
-
|
134
|
-
/**
|
135
|
-
* Compute distance of vector i to current query.
|
136
|
-
* This function corresponds to the function call operator: DistanceComputer::operator()
|
137
|
-
*/
|
138
|
-
int faiss_DistanceComputer_vector_to_query_dis( FaissDistanceComputer *dc, idx_t i, float *qd);
|
139
|
-
/// compute distance between two stored vectors
|
140
|
-
int faiss_DistanceComputer_symmetric_dis(FaissDistanceComputer *dc, idx_t i, idx_t j, float *vd);
|
141
|
-
|
142
|
-
FAISS_DECLARE_DESTRUCTOR(DistanceComputer)
|
143
|
-
|
144
|
-
|
145
|
-
#ifdef __cplusplus
|
146
|
-
}
|
147
|
-
#endif
|
148
|
-
|
149
|
-
#endif
|
@@ -1,26 +0,0 @@
|
|
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
|
-
// Copyright 2004-present Facebook. All Rights Reserved.
|
9
|
-
// -*- c++ -*-
|
10
|
-
|
11
|
-
#include <cstring>
|
12
|
-
#include "index_factory.h"
|
13
|
-
#include "index_factory_c.h"
|
14
|
-
#include "macros_impl.h"
|
15
|
-
|
16
|
-
using faiss::Index;
|
17
|
-
|
18
|
-
/** Build and index with the sequence of processing steps described in
|
19
|
-
* the string.
|
20
|
-
*/
|
21
|
-
int faiss_index_factory(FaissIndex** p_index, int d, const char* description, FaissMetricType metric) {
|
22
|
-
try {
|
23
|
-
*p_index = reinterpret_cast<FaissIndex*>(faiss::index_factory(
|
24
|
-
d, description, static_cast<faiss::MetricType>(metric)));
|
25
|
-
} CATCH_AND_HANDLE
|
26
|
-
}
|
@@ -1,30 +0,0 @@
|
|
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
|
-
// Copyright 2004-present Facebook. All Rights Reserved.
|
9
|
-
// -*- c -*-
|
10
|
-
|
11
|
-
#ifndef FAISS_INDEX_FACTORY_C_H
|
12
|
-
#define FAISS_INDEX_FACTORY_C_H
|
13
|
-
|
14
|
-
#include "faiss_c.h"
|
15
|
-
#include "Index_c.h"
|
16
|
-
|
17
|
-
#ifdef __cplusplus
|
18
|
-
extern "C" {
|
19
|
-
#endif
|
20
|
-
|
21
|
-
/** Build and index with the sequence of processing steps described in
|
22
|
-
* the string.
|
23
|
-
*/
|
24
|
-
int faiss_index_factory(FaissIndex** p_index, int d, const char* description, FaissMetricType metric);
|
25
|
-
|
26
|
-
#ifdef __cplusplus
|
27
|
-
}
|
28
|
-
#endif
|
29
|
-
|
30
|
-
#endif
|