faiss 0.3.1 → 0.3.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 +8 -0
- data/LICENSE.txt +1 -1
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +2 -2
- data/vendor/faiss/faiss/AutoTune.h +3 -3
- data/vendor/faiss/faiss/Clustering.cpp +37 -6
- data/vendor/faiss/faiss/Clustering.h +12 -3
- data/vendor/faiss/faiss/IVFlib.cpp +6 -3
- data/vendor/faiss/faiss/IVFlib.h +2 -2
- data/vendor/faiss/faiss/Index.cpp +6 -2
- data/vendor/faiss/faiss/Index.h +30 -8
- data/vendor/faiss/faiss/Index2Layer.cpp +2 -2
- data/vendor/faiss/faiss/Index2Layer.h +2 -2
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +7 -7
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.h +2 -2
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.cpp +14 -16
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.h +2 -2
- data/vendor/faiss/faiss/IndexBinary.cpp +13 -2
- data/vendor/faiss/faiss/IndexBinary.h +8 -2
- data/vendor/faiss/faiss/IndexBinaryFlat.cpp +2 -3
- data/vendor/faiss/faiss/IndexBinaryFlat.h +2 -2
- data/vendor/faiss/faiss/IndexBinaryFromFloat.cpp +2 -2
- data/vendor/faiss/faiss/IndexBinaryFromFloat.h +2 -2
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +2 -7
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +3 -3
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +2 -3
- data/vendor/faiss/faiss/IndexBinaryHash.h +2 -2
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +3 -3
- data/vendor/faiss/faiss/IndexBinaryIVF.h +2 -2
- data/vendor/faiss/faiss/IndexFastScan.cpp +32 -18
- data/vendor/faiss/faiss/IndexFastScan.h +11 -2
- data/vendor/faiss/faiss/IndexFlat.cpp +13 -10
- data/vendor/faiss/faiss/IndexFlat.h +2 -2
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +170 -7
- data/vendor/faiss/faiss/IndexFlatCodes.h +25 -5
- data/vendor/faiss/faiss/IndexHNSW.cpp +156 -96
- data/vendor/faiss/faiss/IndexHNSW.h +54 -5
- data/vendor/faiss/faiss/IndexIDMap.cpp +19 -3
- data/vendor/faiss/faiss/IndexIDMap.h +5 -2
- data/vendor/faiss/faiss/IndexIVF.cpp +5 -6
- data/vendor/faiss/faiss/IndexIVF.h +13 -4
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +21 -7
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.h +5 -2
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +3 -14
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +2 -4
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +201 -91
- data/vendor/faiss/faiss/IndexIVFFastScan.h +33 -9
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +2 -2
- data/vendor/faiss/faiss/IndexIVFFlat.h +2 -2
- data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.cpp +2 -2
- data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.h +2 -2
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +3 -6
- data/vendor/faiss/faiss/IndexIVFPQ.h +2 -2
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +7 -14
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +2 -4
- data/vendor/faiss/faiss/IndexIVFPQR.cpp +2 -2
- data/vendor/faiss/faiss/IndexIVFPQR.h +2 -2
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +2 -3
- data/vendor/faiss/faiss/IndexIVFSpectralHash.h +2 -2
- data/vendor/faiss/faiss/IndexLSH.cpp +2 -3
- data/vendor/faiss/faiss/IndexLSH.h +2 -2
- data/vendor/faiss/faiss/IndexLattice.cpp +3 -21
- data/vendor/faiss/faiss/IndexLattice.h +5 -24
- data/vendor/faiss/faiss/IndexNNDescent.cpp +2 -31
- data/vendor/faiss/faiss/IndexNNDescent.h +3 -3
- data/vendor/faiss/faiss/IndexNSG.cpp +2 -5
- data/vendor/faiss/faiss/IndexNSG.h +3 -3
- data/vendor/faiss/faiss/IndexNeuralNetCodec.cpp +56 -0
- data/vendor/faiss/faiss/IndexNeuralNetCodec.h +49 -0
- data/vendor/faiss/faiss/IndexPQ.cpp +26 -26
- data/vendor/faiss/faiss/IndexPQ.h +2 -2
- data/vendor/faiss/faiss/IndexPQFastScan.cpp +2 -5
- data/vendor/faiss/faiss/IndexPQFastScan.h +2 -11
- data/vendor/faiss/faiss/IndexPreTransform.cpp +2 -2
- data/vendor/faiss/faiss/IndexPreTransform.h +3 -3
- data/vendor/faiss/faiss/IndexRefine.cpp +46 -9
- data/vendor/faiss/faiss/IndexRefine.h +9 -2
- data/vendor/faiss/faiss/IndexReplicas.cpp +2 -2
- data/vendor/faiss/faiss/IndexReplicas.h +2 -2
- data/vendor/faiss/faiss/IndexRowwiseMinMax.cpp +2 -2
- data/vendor/faiss/faiss/IndexRowwiseMinMax.h +2 -2
- data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +5 -4
- data/vendor/faiss/faiss/IndexScalarQuantizer.h +2 -2
- data/vendor/faiss/faiss/IndexShards.cpp +2 -2
- data/vendor/faiss/faiss/IndexShards.h +2 -2
- data/vendor/faiss/faiss/IndexShardsIVF.cpp +2 -2
- data/vendor/faiss/faiss/IndexShardsIVF.h +2 -2
- data/vendor/faiss/faiss/MatrixStats.cpp +2 -2
- data/vendor/faiss/faiss/MatrixStats.h +2 -2
- data/vendor/faiss/faiss/MetaIndexes.cpp +2 -3
- data/vendor/faiss/faiss/MetaIndexes.h +2 -2
- data/vendor/faiss/faiss/MetricType.h +9 -4
- data/vendor/faiss/faiss/VectorTransform.cpp +2 -2
- data/vendor/faiss/faiss/VectorTransform.h +2 -2
- data/vendor/faiss/faiss/clone_index.cpp +2 -2
- data/vendor/faiss/faiss/clone_index.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/SaDecodeKernels.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/detail/CoarseBitType.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/detail/UintReader.h +97 -19
- data/vendor/faiss/faiss/cppcontrib/factory_tools.cpp +192 -0
- data/vendor/faiss/faiss/cppcontrib/factory_tools.h +29 -0
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-avx2-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-inl.h +85 -32
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-neon-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/MinMax-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/MinMaxFP16-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-avx2-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-neon-inl.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuAutoTune.cpp +2 -5
- data/vendor/faiss/faiss/gpu/GpuAutoTune.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +45 -13
- data/vendor/faiss/faiss/gpu/GpuCloner.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +12 -6
- data/vendor/faiss/faiss/gpu/GpuDistance.h +11 -7
- data/vendor/faiss/faiss/gpu/GpuFaissAssert.h +3 -3
- data/vendor/faiss/faiss/gpu/GpuIcmEncoder.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndex.h +10 -15
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +285 -0
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +8 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +4 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVFPQ.h +3 -3
- data/vendor/faiss/faiss/gpu/GpuIndexIVFScalarQuantizer.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndicesOptions.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuResources.cpp +7 -2
- data/vendor/faiss/faiss/gpu/GpuResources.h +11 -4
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +66 -11
- data/vendor/faiss/faiss/gpu/StandardGpuResources.h +15 -5
- data/vendor/faiss/faiss/gpu/impl/IndexUtils.h +2 -2
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.cpp +28 -23
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.h +2 -2
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.cpp +2 -2
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.h +2 -2
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper-inl.h +2 -2
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper.h +2 -2
- data/vendor/faiss/faiss/gpu/perf/PerfClustering.cpp +8 -2
- data/vendor/faiss/faiss/gpu/perf/PerfIVFPQAdd.cpp +2 -3
- data/vendor/faiss/faiss/gpu/perf/WriteIndex.cpp +2 -2
- data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +10 -7
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexBinaryFlat.cpp +2 -2
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +54 -54
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +144 -77
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +51 -51
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFScalarQuantizer.cpp +2 -2
- data/vendor/faiss/faiss/gpu/test/TestGpuMemoryException.cpp +3 -3
- data/vendor/faiss/faiss/gpu/test/TestGpuResidualQuantizer.cpp +70 -0
- data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +74 -4
- data/vendor/faiss/faiss/gpu/test/TestUtils.h +2 -2
- data/vendor/faiss/faiss/gpu/test/demo_ivfpq_indexing_gpu.cpp +3 -3
- data/vendor/faiss/faiss/gpu/utils/{RaftUtils.h → CuvsUtils.h} +12 -11
- data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +8 -2
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +2 -2
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.h +2 -2
- data/vendor/faiss/faiss/gpu/utils/StaticUtils.h +2 -2
- data/vendor/faiss/faiss/gpu/utils/Timer.cpp +6 -3
- data/vendor/faiss/faiss/gpu/utils/Timer.h +3 -3
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +79 -11
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +17 -5
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +27 -2
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +11 -3
- data/vendor/faiss/faiss/impl/CodePacker.cpp +2 -2
- data/vendor/faiss/faiss/impl/CodePacker.h +2 -2
- data/vendor/faiss/faiss/impl/DistanceComputer.h +48 -2
- data/vendor/faiss/faiss/impl/FaissAssert.h +6 -4
- data/vendor/faiss/faiss/impl/FaissException.cpp +2 -2
- data/vendor/faiss/faiss/impl/FaissException.h +2 -3
- data/vendor/faiss/faiss/impl/HNSW.cpp +378 -205
- data/vendor/faiss/faiss/impl/HNSW.h +55 -24
- data/vendor/faiss/faiss/impl/IDSelector.cpp +2 -2
- data/vendor/faiss/faiss/impl/IDSelector.h +2 -2
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +10 -10
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.h +2 -2
- data/vendor/faiss/faiss/impl/LookupTableScaler.h +36 -2
- data/vendor/faiss/faiss/impl/NNDescent.cpp +15 -10
- data/vendor/faiss/faiss/impl/NNDescent.h +2 -2
- data/vendor/faiss/faiss/impl/NSG.cpp +26 -49
- data/vendor/faiss/faiss/impl/NSG.h +20 -8
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +2 -2
- data/vendor/faiss/faiss/impl/PolysemousTraining.h +2 -2
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.cpp +2 -4
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.h +2 -2
- data/vendor/faiss/faiss/impl/ProductQuantizer-inl.h +2 -2
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +3 -2
- data/vendor/faiss/faiss/impl/ProductQuantizer.h +7 -3
- data/vendor/faiss/faiss/impl/Quantizer.h +2 -2
- data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +2 -36
- data/vendor/faiss/faiss/impl/ResidualQuantizer.h +3 -13
- data/vendor/faiss/faiss/impl/ResultHandler.h +153 -34
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +721 -104
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +5 -2
- data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +2 -2
- data/vendor/faiss/faiss/impl/ThreadedIndex.h +2 -2
- data/vendor/faiss/faiss/impl/code_distance/code_distance-avx2.h +7 -2
- data/vendor/faiss/faiss/impl/code_distance/code_distance-avx512.h +248 -0
- data/vendor/faiss/faiss/impl/code_distance/code_distance-generic.h +2 -2
- data/vendor/faiss/faiss/impl/code_distance/code_distance-sve.h +440 -0
- data/vendor/faiss/faiss/impl/code_distance/code_distance.h +55 -2
- data/vendor/faiss/faiss/impl/index_read.cpp +31 -20
- data/vendor/faiss/faiss/impl/index_read_utils.h +37 -0
- data/vendor/faiss/faiss/impl/index_write.cpp +30 -16
- data/vendor/faiss/faiss/impl/io.cpp +15 -7
- data/vendor/faiss/faiss/impl/io.h +6 -6
- data/vendor/faiss/faiss/impl/io_macros.h +8 -9
- data/vendor/faiss/faiss/impl/kmeans1d.cpp +2 -3
- data/vendor/faiss/faiss/impl/kmeans1d.h +2 -2
- data/vendor/faiss/faiss/impl/lattice_Zn.cpp +2 -3
- data/vendor/faiss/faiss/impl/lattice_Zn.h +2 -2
- data/vendor/faiss/faiss/impl/platform_macros.h +34 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +13 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +20 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +3 -3
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +450 -3
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +8 -8
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.h +3 -3
- data/vendor/faiss/faiss/impl/simd_result_handlers.h +151 -67
- data/vendor/faiss/faiss/index_factory.cpp +51 -34
- data/vendor/faiss/faiss/index_factory.h +2 -2
- data/vendor/faiss/faiss/index_io.h +14 -7
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +30 -10
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +5 -2
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +11 -3
- data/vendor/faiss/faiss/invlists/DirectMap.h +2 -2
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +57 -19
- data/vendor/faiss/faiss/invlists/InvertedLists.h +20 -11
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +2 -2
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +2 -2
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +23 -9
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +4 -3
- data/vendor/faiss/faiss/python/python_callbacks.cpp +5 -5
- data/vendor/faiss/faiss/python/python_callbacks.h +2 -2
- data/vendor/faiss/faiss/utils/AlignedTable.h +5 -3
- data/vendor/faiss/faiss/utils/Heap.cpp +2 -2
- data/vendor/faiss/faiss/utils/Heap.h +107 -2
- data/vendor/faiss/faiss/utils/NeuralNet.cpp +346 -0
- data/vendor/faiss/faiss/utils/NeuralNet.h +147 -0
- data/vendor/faiss/faiss/utils/WorkerThread.cpp +2 -2
- data/vendor/faiss/faiss/utils/WorkerThread.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/approx_topk.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/avx2-inl.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/generic.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/mode.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk_hamming/approx_topk_hamming.h +2 -2
- data/vendor/faiss/faiss/utils/bf16.h +36 -0
- data/vendor/faiss/faiss/utils/distances.cpp +249 -90
- data/vendor/faiss/faiss/utils/distances.h +8 -8
- data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/avx512.h +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.h +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.h +2 -2
- data/vendor/faiss/faiss/utils/distances_simd.cpp +1543 -56
- data/vendor/faiss/faiss/utils/extra_distances-inl.h +72 -2
- data/vendor/faiss/faiss/utils/extra_distances.cpp +87 -140
- data/vendor/faiss/faiss/utils/extra_distances.h +5 -4
- data/vendor/faiss/faiss/utils/fp16-arm.h +2 -2
- data/vendor/faiss/faiss/utils/fp16-fp16c.h +2 -2
- data/vendor/faiss/faiss/utils/fp16-inl.h +2 -2
- data/vendor/faiss/faiss/utils/fp16.h +2 -2
- data/vendor/faiss/faiss/utils/hamming-inl.h +2 -2
- data/vendor/faiss/faiss/utils/hamming.cpp +3 -4
- data/vendor/faiss/faiss/utils/hamming.h +2 -2
- data/vendor/faiss/faiss/utils/hamming_distance/avx2-inl.h +2 -2
- data/vendor/faiss/faiss/utils/hamming_distance/avx512-inl.h +490 -0
- data/vendor/faiss/faiss/utils/hamming_distance/common.h +2 -2
- data/vendor/faiss/faiss/utils/hamming_distance/generic-inl.h +6 -3
- data/vendor/faiss/faiss/utils/hamming_distance/hamdis-inl.h +7 -3
- data/vendor/faiss/faiss/utils/hamming_distance/neon-inl.h +5 -5
- data/vendor/faiss/faiss/utils/ordered_key_value.h +2 -2
- data/vendor/faiss/faiss/utils/partitioning.cpp +2 -2
- data/vendor/faiss/faiss/utils/partitioning.h +2 -2
- data/vendor/faiss/faiss/utils/prefetch.h +2 -2
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +2 -2
- data/vendor/faiss/faiss/utils/quantize_lut.h +2 -2
- data/vendor/faiss/faiss/utils/random.cpp +45 -2
- data/vendor/faiss/faiss/utils/random.h +27 -2
- data/vendor/faiss/faiss/utils/simdlib.h +12 -3
- data/vendor/faiss/faiss/utils/simdlib_avx2.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_avx512.h +296 -0
- data/vendor/faiss/faiss/utils/simdlib_emulated.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_neon.h +7 -4
- data/vendor/faiss/faiss/utils/simdlib_ppc64.h +1084 -0
- data/vendor/faiss/faiss/utils/sorting.cpp +2 -2
- data/vendor/faiss/faiss/utils/sorting.h +2 -2
- data/vendor/faiss/faiss/utils/transpose/transpose-avx2-inl.h +2 -2
- data/vendor/faiss/faiss/utils/transpose/transpose-avx512-inl.h +176 -0
- data/vendor/faiss/faiss/utils/utils.cpp +17 -10
- data/vendor/faiss/faiss/utils/utils.h +7 -3
- metadata +22 -11
- data/vendor/faiss/faiss/impl/code_distance/code_distance_avx512.h +0 -102
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -9,7 +9,9 @@
|
|
9
9
|
* and inner product */
|
10
10
|
|
11
11
|
#include <faiss/MetricType.h>
|
12
|
+
#include <faiss/impl/FaissAssert.h>
|
12
13
|
#include <faiss/utils/distances.h>
|
14
|
+
#include <cmath>
|
13
15
|
#include <type_traits>
|
14
16
|
|
15
17
|
namespace faiss {
|
@@ -130,4 +132,72 @@ inline float VectorDistance<METRIC_Jaccard>::operator()(
|
|
130
132
|
return accu_num / accu_den;
|
131
133
|
}
|
132
134
|
|
135
|
+
template <>
|
136
|
+
inline float VectorDistance<METRIC_NaNEuclidean>::operator()(
|
137
|
+
const float* x,
|
138
|
+
const float* y) const {
|
139
|
+
// https://scikit-learn.org/stable/modules/generated/sklearn.metrics.pairwise.nan_euclidean_distances.html
|
140
|
+
float accu = 0;
|
141
|
+
size_t present = 0;
|
142
|
+
for (size_t i = 0; i < d; i++) {
|
143
|
+
if (!std::isnan(x[i]) && !std::isnan(y[i])) {
|
144
|
+
float diff = x[i] - y[i];
|
145
|
+
accu += diff * diff;
|
146
|
+
present++;
|
147
|
+
}
|
148
|
+
}
|
149
|
+
if (present == 0) {
|
150
|
+
return NAN;
|
151
|
+
}
|
152
|
+
return float(d) / float(present) * accu;
|
153
|
+
}
|
154
|
+
|
155
|
+
template <>
|
156
|
+
inline float VectorDistance<METRIC_ABS_INNER_PRODUCT>::operator()(
|
157
|
+
const float* x,
|
158
|
+
const float* y) const {
|
159
|
+
float accu = 0;
|
160
|
+
for (size_t i = 0; i < d; i++) {
|
161
|
+
accu += fabs(x[i] * y[i]);
|
162
|
+
}
|
163
|
+
return accu;
|
164
|
+
}
|
165
|
+
|
166
|
+
/***************************************************************************
|
167
|
+
* Dispatching function that takes a metric type and a consumer object
|
168
|
+
* the consumer object should contain a retun type T and a operation template
|
169
|
+
* function f() that is called to perform the operation. The first argument
|
170
|
+
* of the function is the VectorDistance object. The rest are passed in as is.
|
171
|
+
**************************************************************************/
|
172
|
+
|
173
|
+
template <class Consumer, class... Types>
|
174
|
+
typename Consumer::T dispatch_VectorDistance(
|
175
|
+
size_t d,
|
176
|
+
MetricType metric,
|
177
|
+
float metric_arg,
|
178
|
+
Consumer& consumer,
|
179
|
+
Types... args) {
|
180
|
+
switch (metric) {
|
181
|
+
#define DISPATCH_VD(mt) \
|
182
|
+
case mt: { \
|
183
|
+
VectorDistance<mt> vd = {d, metric_arg}; \
|
184
|
+
return consumer.template f<VectorDistance<mt>>(vd, args...); \
|
185
|
+
}
|
186
|
+
DISPATCH_VD(METRIC_INNER_PRODUCT);
|
187
|
+
DISPATCH_VD(METRIC_L2);
|
188
|
+
DISPATCH_VD(METRIC_L1);
|
189
|
+
DISPATCH_VD(METRIC_Linf);
|
190
|
+
DISPATCH_VD(METRIC_Lp);
|
191
|
+
DISPATCH_VD(METRIC_Canberra);
|
192
|
+
DISPATCH_VD(METRIC_BrayCurtis);
|
193
|
+
DISPATCH_VD(METRIC_JensenShannon);
|
194
|
+
DISPATCH_VD(METRIC_Jaccard);
|
195
|
+
DISPATCH_VD(METRIC_NaNEuclidean);
|
196
|
+
DISPATCH_VD(METRIC_ABS_INNER_PRODUCT);
|
197
|
+
default:
|
198
|
+
FAISS_THROW_FMT("Invalid metric %d", metric);
|
199
|
+
}
|
200
|
+
#undef DISPATCH_VD
|
201
|
+
}
|
202
|
+
|
133
203
|
} // namespace faiss
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -15,7 +15,6 @@
|
|
15
15
|
|
16
16
|
#include <faiss/impl/AuxIndexStructures.h>
|
17
17
|
#include <faiss/impl/DistanceComputer.h>
|
18
|
-
#include <faiss/impl/FaissAssert.h>
|
19
18
|
#include <faiss/utils/utils.h>
|
20
19
|
|
21
20
|
namespace faiss {
|
@@ -26,73 +25,77 @@ namespace faiss {
|
|
26
25
|
|
27
26
|
namespace {
|
28
27
|
|
29
|
-
|
30
|
-
void
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
28
|
+
struct Run_pairwise_extra_distances {
|
29
|
+
using T = void;
|
30
|
+
|
31
|
+
template <class VD>
|
32
|
+
void f(VD vd,
|
33
|
+
int64_t nq,
|
34
|
+
const float* xq,
|
35
|
+
int64_t nb,
|
36
|
+
const float* xb,
|
37
|
+
float* dis,
|
38
|
+
int64_t ldq,
|
39
|
+
int64_t ldb,
|
40
|
+
int64_t ldd) {
|
40
41
|
#pragma omp parallel for if (nq > 10)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
42
|
+
for (int64_t i = 0; i < nq; i++) {
|
43
|
+
const float* xqi = xq + i * ldq;
|
44
|
+
const float* xbj = xb;
|
45
|
+
float* disi = dis + ldd * i;
|
46
|
+
|
47
|
+
for (int64_t j = 0; j < nb; j++) {
|
48
|
+
disi[j] = vd(xqi, xbj);
|
49
|
+
xbj += ldb;
|
50
|
+
}
|
49
51
|
}
|
50
52
|
}
|
51
|
-
}
|
52
|
-
|
53
|
-
template <class VD, class C>
|
54
|
-
void knn_extra_metrics_template(
|
55
|
-
VD vd,
|
56
|
-
const float* x,
|
57
|
-
const float* y,
|
58
|
-
size_t nx,
|
59
|
-
size_t ny,
|
60
|
-
HeapArray<C>* res) {
|
61
|
-
size_t k = res->k;
|
62
|
-
size_t d = vd.d;
|
63
|
-
size_t check_period = InterruptCallback::get_period_hint(ny * d);
|
64
|
-
check_period *= omp_get_max_threads();
|
53
|
+
};
|
65
54
|
|
66
|
-
|
67
|
-
|
55
|
+
struct Run_knn_extra_metrics {
|
56
|
+
using T = void;
|
57
|
+
template <class VD>
|
58
|
+
void f(VD vd,
|
59
|
+
const float* x,
|
60
|
+
const float* y,
|
61
|
+
size_t nx,
|
62
|
+
size_t ny,
|
63
|
+
size_t k,
|
64
|
+
float* distances,
|
65
|
+
int64_t* labels) {
|
66
|
+
size_t d = vd.d;
|
67
|
+
using C = typename VD::C;
|
68
|
+
size_t check_period = InterruptCallback::get_period_hint(ny * d);
|
69
|
+
check_period *= omp_get_max_threads();
|
70
|
+
|
71
|
+
for (size_t i0 = 0; i0 < nx; i0 += check_period) {
|
72
|
+
size_t i1 = std::min(i0 + check_period, nx);
|
68
73
|
|
69
74
|
#pragma omp parallel for
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
heap_replace_top<C>(k, simi, idxi, disij, j);
|
75
|
+
for (int64_t i = i0; i < i1; i++) {
|
76
|
+
const float* x_i = x + i * d;
|
77
|
+
const float* y_j = y;
|
78
|
+
size_t j;
|
79
|
+
float* simi = distances + k * i;
|
80
|
+
int64_t* idxi = labels + k * i;
|
81
|
+
|
82
|
+
// maxheap_heapify(k, simi, idxi);
|
83
|
+
heap_heapify<C>(k, simi, idxi);
|
84
|
+
for (j = 0; j < ny; j++) {
|
85
|
+
float disij = vd(x_i, y_j);
|
86
|
+
|
87
|
+
if (C::cmp(simi[0], disij)) {
|
88
|
+
heap_replace_top<C>(k, simi, idxi, disij, j);
|
89
|
+
}
|
90
|
+
y_j += d;
|
87
91
|
}
|
88
|
-
|
92
|
+
// maxheap_reorder(k, simi, idxi);
|
93
|
+
heap_reorder<C>(k, simi, idxi);
|
89
94
|
}
|
90
|
-
|
91
|
-
heap_reorder<C>(k, simi, idxi);
|
95
|
+
InterruptCallback::check();
|
92
96
|
}
|
93
|
-
InterruptCallback::check();
|
94
97
|
}
|
95
|
-
}
|
98
|
+
};
|
96
99
|
|
97
100
|
template <class VD>
|
98
101
|
struct ExtraDistanceComputer : FlatCodesDistanceComputer {
|
@@ -125,6 +128,19 @@ struct ExtraDistanceComputer : FlatCodesDistanceComputer {
|
|
125
128
|
}
|
126
129
|
};
|
127
130
|
|
131
|
+
struct Run_get_distance_computer {
|
132
|
+
using T = FlatCodesDistanceComputer*;
|
133
|
+
|
134
|
+
template <class VD>
|
135
|
+
FlatCodesDistanceComputer* f(
|
136
|
+
VD vd,
|
137
|
+
const float* xb,
|
138
|
+
size_t nb,
|
139
|
+
const float* q = nullptr) {
|
140
|
+
return new ExtraDistanceComputer<VD>(vd, xb, nb, q);
|
141
|
+
}
|
142
|
+
};
|
143
|
+
|
128
144
|
} // anonymous namespace
|
129
145
|
|
130
146
|
void pairwise_extra_distances(
|
@@ -148,29 +164,11 @@ void pairwise_extra_distances(
|
|
148
164
|
if (ldd == -1)
|
149
165
|
ldd = nb;
|
150
166
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
VectorDistance<METRIC_##kw> vd = {(size_t)d, metric_arg}; \
|
155
|
-
pairwise_extra_distances_template( \
|
156
|
-
vd, nq, xq, nb, xb, dis, ldq, ldb, ldd); \
|
157
|
-
break; \
|
158
|
-
}
|
159
|
-
HANDLE_VAR(L2);
|
160
|
-
HANDLE_VAR(L1);
|
161
|
-
HANDLE_VAR(Linf);
|
162
|
-
HANDLE_VAR(Canberra);
|
163
|
-
HANDLE_VAR(BrayCurtis);
|
164
|
-
HANDLE_VAR(JensenShannon);
|
165
|
-
HANDLE_VAR(Lp);
|
166
|
-
HANDLE_VAR(Jaccard);
|
167
|
-
#undef HANDLE_VAR
|
168
|
-
default:
|
169
|
-
FAISS_THROW_MSG("metric type not implemented");
|
170
|
-
}
|
167
|
+
Run_pairwise_extra_distances run;
|
168
|
+
dispatch_VectorDistance(
|
169
|
+
d, mt, metric_arg, run, nq, xq, nb, xb, dis, ldq, ldb, ldd);
|
171
170
|
}
|
172
171
|
|
173
|
-
template <class C>
|
174
172
|
void knn_extra_metrics(
|
175
173
|
const float* x,
|
176
174
|
const float* y,
|
@@ -179,73 +177,22 @@ void knn_extra_metrics(
|
|
179
177
|
size_t ny,
|
180
178
|
MetricType mt,
|
181
179
|
float metric_arg,
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
break; \
|
189
|
-
}
|
190
|
-
HANDLE_VAR(L2);
|
191
|
-
HANDLE_VAR(L1);
|
192
|
-
HANDLE_VAR(Linf);
|
193
|
-
HANDLE_VAR(Canberra);
|
194
|
-
HANDLE_VAR(BrayCurtis);
|
195
|
-
HANDLE_VAR(JensenShannon);
|
196
|
-
HANDLE_VAR(Lp);
|
197
|
-
HANDLE_VAR(Jaccard);
|
198
|
-
#undef HANDLE_VAR
|
199
|
-
default:
|
200
|
-
FAISS_THROW_MSG("metric type not implemented");
|
201
|
-
}
|
180
|
+
size_t k,
|
181
|
+
float* distances,
|
182
|
+
int64_t* indexes) {
|
183
|
+
Run_knn_extra_metrics run;
|
184
|
+
dispatch_VectorDistance(
|
185
|
+
d, mt, metric_arg, run, x, y, nx, ny, k, distances, indexes);
|
202
186
|
}
|
203
187
|
|
204
|
-
template void knn_extra_metrics<CMax<float, int64_t>>(
|
205
|
-
const float* x,
|
206
|
-
const float* y,
|
207
|
-
size_t d,
|
208
|
-
size_t nx,
|
209
|
-
size_t ny,
|
210
|
-
MetricType mt,
|
211
|
-
float metric_arg,
|
212
|
-
HeapArray<CMax<float, int64_t>>* res);
|
213
|
-
|
214
|
-
template void knn_extra_metrics<CMin<float, int64_t>>(
|
215
|
-
const float* x,
|
216
|
-
const float* y,
|
217
|
-
size_t d,
|
218
|
-
size_t nx,
|
219
|
-
size_t ny,
|
220
|
-
MetricType mt,
|
221
|
-
float metric_arg,
|
222
|
-
HeapArray<CMin<float, int64_t>>* res);
|
223
|
-
|
224
188
|
FlatCodesDistanceComputer* get_extra_distance_computer(
|
225
189
|
size_t d,
|
226
190
|
MetricType mt,
|
227
191
|
float metric_arg,
|
228
192
|
size_t nb,
|
229
193
|
const float* xb) {
|
230
|
-
|
231
|
-
|
232
|
-
case METRIC_##kw: { \
|
233
|
-
VectorDistance<METRIC_##kw> vd = {(size_t)d, metric_arg}; \
|
234
|
-
return new ExtraDistanceComputer<VectorDistance<METRIC_##kw>>( \
|
235
|
-
vd, xb, nb); \
|
236
|
-
}
|
237
|
-
HANDLE_VAR(L2);
|
238
|
-
HANDLE_VAR(L1);
|
239
|
-
HANDLE_VAR(Linf);
|
240
|
-
HANDLE_VAR(Canberra);
|
241
|
-
HANDLE_VAR(BrayCurtis);
|
242
|
-
HANDLE_VAR(JensenShannon);
|
243
|
-
HANDLE_VAR(Lp);
|
244
|
-
HANDLE_VAR(Jaccard);
|
245
|
-
#undef HANDLE_VAR
|
246
|
-
default:
|
247
|
-
FAISS_THROW_MSG("metric type not implemented");
|
248
|
-
}
|
194
|
+
Run_get_distance_computer run;
|
195
|
+
return dispatch_VectorDistance(d, mt, metric_arg, run, xb, nb);
|
249
196
|
}
|
250
197
|
|
251
198
|
} // namespace faiss
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -33,7 +33,6 @@ void pairwise_extra_distances(
|
|
33
33
|
int64_t ldb = -1,
|
34
34
|
int64_t ldd = -1);
|
35
35
|
|
36
|
-
template <class C>
|
37
36
|
void knn_extra_metrics(
|
38
37
|
const float* x,
|
39
38
|
const float* y,
|
@@ -42,7 +41,9 @@ void knn_extra_metrics(
|
|
42
41
|
size_t ny,
|
43
42
|
MetricType mt,
|
44
43
|
float metric_arg,
|
45
|
-
|
44
|
+
size_t k,
|
45
|
+
float* distances,
|
46
|
+
int64_t* indexes);
|
46
47
|
|
47
48
|
/** get a DistanceComputer that refers to this type of distance and
|
48
49
|
* indexes a flat array of size nb */
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
* Copyright (c)
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -24,7 +24,6 @@
|
|
24
24
|
#include <faiss/utils/hamming.h>
|
25
25
|
|
26
26
|
#include <algorithm>
|
27
|
-
#include <cmath>
|
28
27
|
#include <cstdio>
|
29
28
|
#include <memory>
|
30
29
|
#include <vector>
|
@@ -364,7 +363,7 @@ void fvec2bitvec(const float* __restrict x, uint8_t* __restrict b, size_t d) {
|
|
364
363
|
}
|
365
364
|
|
366
365
|
/* Same but for n vectors.
|
367
|
-
Ensure that the
|
366
|
+
Ensure that the output b is byte-aligned (pad with 0s). */
|
368
367
|
void fvecs2bitvecs(
|
369
368
|
const float* __restrict x,
|
370
369
|
uint8_t* __restrict b,
|