faiss 0.6.0 → 0.6.1
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 +4 -0
- data/ext/faiss/extconf.rb +2 -1
- data/ext/faiss/{index_rb.cpp → index.cpp} +1 -1
- data/ext/faiss/index_binary.cpp +1 -1
- data/ext/faiss/kmeans.cpp +1 -1
- data/ext/faiss/pca_matrix.cpp +1 -1
- data/ext/faiss/product_quantizer.cpp +1 -1
- data/ext/faiss/{utils_rb.cpp → utils.cpp} +1 -1
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +93 -80
- data/vendor/faiss/faiss/Clustering.cpp +39 -240
- data/vendor/faiss/faiss/Clustering.h +6 -0
- data/vendor/faiss/faiss/IVFlib.cpp +41 -21
- data/vendor/faiss/faiss/Index.cpp +6 -5
- data/vendor/faiss/faiss/Index.h +5 -5
- data/vendor/faiss/faiss/Index2Layer.cpp +37 -53
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +49 -37
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.cpp +36 -34
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.h +4 -1
- data/vendor/faiss/faiss/IndexBinary.cpp +5 -3
- data/vendor/faiss/faiss/IndexBinary.h +4 -4
- data/vendor/faiss/faiss/IndexBinaryFlat.cpp +1 -1
- data/vendor/faiss/faiss/IndexBinaryFlat.h +1 -1
- data/vendor/faiss/faiss/IndexBinaryFromFloat.cpp +4 -4
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +84 -92
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +9 -3
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +45 -236
- data/vendor/faiss/faiss/IndexBinaryHash.h +6 -6
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +87 -415
- data/vendor/faiss/faiss/IndexFastScan.cpp +72 -109
- data/vendor/faiss/faiss/IndexFastScan.h +25 -23
- data/vendor/faiss/faiss/IndexFlat.cpp +27 -20
- data/vendor/faiss/faiss/IndexFlat.h +21 -18
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +42 -19
- data/vendor/faiss/faiss/IndexHNSW.cpp +283 -145
- data/vendor/faiss/faiss/IndexHNSW.h +16 -2
- data/vendor/faiss/faiss/IndexIDMap.cpp +25 -21
- data/vendor/faiss/faiss/IndexIDMap.h +9 -7
- data/vendor/faiss/faiss/IndexIVF.cpp +465 -362
- data/vendor/faiss/faiss/IndexIVF.h +33 -12
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +77 -74
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +96 -93
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +4 -1
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +357 -238
- data/vendor/faiss/faiss/IndexIVFFastScan.h +42 -41
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +36 -68
- data/vendor/faiss/faiss/IndexIVFFlat.h +32 -0
- data/vendor/faiss/faiss/IndexIVFFlatPanorama.cpp +53 -30
- data/vendor/faiss/faiss/IndexIVFFlatPanorama.h +3 -1
- data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.cpp +18 -15
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +71 -843
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +151 -121
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +3 -0
- data/vendor/faiss/faiss/IndexIVFPQR.cpp +21 -17
- data/vendor/faiss/faiss/IndexIVFRaBitQ.cpp +26 -39
- data/vendor/faiss/faiss/IndexIVFRaBitQ.h +2 -1
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +475 -476
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +248 -93
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +41 -127
- data/vendor/faiss/faiss/IndexIVFSpectralHash.h +1 -1
- data/vendor/faiss/faiss/IndexLSH.cpp +36 -19
- data/vendor/faiss/faiss/IndexLattice.cpp +13 -13
- data/vendor/faiss/faiss/IndexNNDescent.cpp +36 -21
- data/vendor/faiss/faiss/IndexNNDescent.h +2 -2
- data/vendor/faiss/faiss/IndexNSG.cpp +39 -23
- data/vendor/faiss/faiss/IndexNeuralNetCodec.cpp +31 -11
- data/vendor/faiss/faiss/IndexPQ.cpp +128 -221
- data/vendor/faiss/faiss/IndexPQ.h +3 -2
- data/vendor/faiss/faiss/IndexPQFastScan.cpp +20 -14
- data/vendor/faiss/faiss/IndexPQFastScan.h +3 -0
- data/vendor/faiss/faiss/IndexPreTransform.cpp +25 -18
- data/vendor/faiss/faiss/IndexPreTransform.h +1 -1
- data/vendor/faiss/faiss/IndexRaBitQ.cpp +11 -36
- data/vendor/faiss/faiss/IndexRaBitQ.h +2 -1
- data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +41 -277
- data/vendor/faiss/faiss/IndexRaBitQFastScan.h +183 -27
- data/vendor/faiss/faiss/IndexRefine.cpp +30 -25
- data/vendor/faiss/faiss/IndexRefine.h +4 -4
- data/vendor/faiss/faiss/IndexReplicas.cpp +6 -6
- data/vendor/faiss/faiss/IndexRowwiseMinMax.cpp +15 -14
- data/vendor/faiss/faiss/IndexRowwiseMinMax.h +1 -1
- data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +82 -14
- data/vendor/faiss/faiss/IndexShards.cpp +10 -9
- data/vendor/faiss/faiss/IndexShardsIVF.cpp +21 -15
- data/vendor/faiss/faiss/MatrixStats.cpp +5 -4
- data/vendor/faiss/faiss/MetaIndexes.cpp +19 -17
- data/vendor/faiss/faiss/MetaIndexes.h +1 -1
- data/vendor/faiss/faiss/MetricType.h +14 -7
- data/vendor/faiss/faiss/SuperKMeans.cpp +656 -0
- data/vendor/faiss/faiss/SuperKMeans.h +97 -0
- data/vendor/faiss/faiss/VectorTransform.cpp +237 -149
- data/vendor/faiss/faiss/VectorTransform.h +16 -16
- data/vendor/faiss/faiss/build.cpp +23 -0
- data/vendor/faiss/faiss/build.h +15 -0
- data/vendor/faiss/faiss/clone_index.cpp +48 -47
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-avx2-inl.h +47 -47
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-inl.h +11 -0
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-avx2-inl.h +38 -38
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-inl.h +11 -0
- data/vendor/faiss/faiss/factory_tools.cpp +5 -0
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +6 -5
- data/vendor/faiss/faiss/gpu/GpuResources.h +1 -1
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +9 -9
- data/vendor/faiss/faiss/gpu/StandardGpuResources.h +4 -3
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +46 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +56 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +78 -1
- data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +72 -0
- data/vendor/faiss/faiss/gpu/test/TestUtils.h +23 -0
- data/vendor/faiss/faiss/gpu/utils/CuvsFilterConvert.h +1 -1
- data/vendor/faiss/faiss/gpu/utils/CuvsUtils.h +21 -10
- data/vendor/faiss/faiss/gpu_metal/GpuIndexFlat.h +22 -0
- data/vendor/faiss/faiss/gpu_metal/MetalCloner.h +35 -0
- data/vendor/faiss/faiss/gpu_metal/MetalFlatKernels.h +40 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndex.h +51 -0
- data/vendor/faiss/faiss/gpu_metal/MetalIndexFlat.h +65 -0
- data/vendor/faiss/faiss/gpu_metal/MetalKernels.h +66 -0
- data/vendor/faiss/faiss/gpu_metal/MetalResources.h +79 -0
- data/vendor/faiss/faiss/gpu_metal/StandardMetalResources.h +35 -0
- data/vendor/faiss/faiss/impl/AdSampling.cpp +103 -0
- data/vendor/faiss/faiss/impl/AdSampling.h +35 -0
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +29 -25
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +1 -0
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +10 -9
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +3 -0
- data/vendor/faiss/faiss/impl/ClusteringHelpers.cpp +244 -0
- data/vendor/faiss/faiss/impl/ClusteringHelpers.h +94 -0
- data/vendor/faiss/faiss/impl/ClusteringInitialization.cpp +16 -16
- data/vendor/faiss/faiss/impl/CodePacker.cpp +3 -3
- data/vendor/faiss/faiss/impl/CodePackerRaBitQ.cpp +1 -1
- data/vendor/faiss/faiss/impl/DistanceComputer.h +8 -8
- data/vendor/faiss/faiss/impl/FaissAssert.h +6 -3
- data/vendor/faiss/faiss/impl/FaissException.h +50 -3
- data/vendor/faiss/faiss/impl/HNSW.cpp +92 -317
- data/vendor/faiss/faiss/impl/HNSW.h +13 -34
- data/vendor/faiss/faiss/impl/IDSelector.cpp +15 -11
- data/vendor/faiss/faiss/impl/IDSelector.h +8 -8
- data/vendor/faiss/faiss/impl/InvertedListScannerStats.h +26 -0
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +82 -77
- data/vendor/faiss/faiss/impl/NNDescent.cpp +62 -25
- data/vendor/faiss/faiss/impl/NNDescent.h +6 -2
- data/vendor/faiss/faiss/impl/NSG.cpp +38 -21
- data/vendor/faiss/faiss/impl/NSG.h +4 -4
- data/vendor/faiss/faiss/impl/Panorama.cpp +23 -6
- data/vendor/faiss/faiss/impl/Panorama.h +258 -87
- data/vendor/faiss/faiss/impl/PdxLayout.cpp +93 -0
- data/vendor/faiss/faiss/impl/PdxLayout.h +41 -0
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +46 -32
- data/vendor/faiss/faiss/impl/PolysemousTraining.h +3 -3
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.cpp +35 -35
- data/vendor/faiss/faiss/impl/ProductQuantizer-inl.h +21 -16
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +30 -23
- data/vendor/faiss/faiss/impl/Quantizer.h +2 -2
- data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +55 -49
- data/vendor/faiss/faiss/impl/RaBitQUtils.h +65 -0
- data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +296 -283
- data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +26 -23
- data/vendor/faiss/faiss/impl/ResidualQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/ResultHandler.h +99 -75
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +52 -4
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +27 -1
- data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +14 -11
- data/vendor/faiss/faiss/impl/VisitedTable.h +7 -0
- data/vendor/faiss/faiss/impl/approx_topk/approx_topk.h +276 -0
- data/vendor/faiss/faiss/impl/approx_topk/avx2.cpp +68 -0
- data/vendor/faiss/faiss/{utils → impl}/approx_topk/generic.h +15 -8
- data/vendor/faiss/faiss/impl/approx_topk/neon.cpp +68 -0
- data/vendor/faiss/faiss/impl/approx_topk/rq_beam_search_tab-inl.h +169 -0
- data/vendor/faiss/faiss/impl/approx_topk/rq_beam_search_tab.h +117 -0
- data/vendor/faiss/faiss/impl/approx_topk/simdlib256-inl.h +146 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryHNSW_impl.h +73 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryHash_impl.h +270 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryIVF_impl.h +460 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexIVFSpectralHash_impl.h +159 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexPQ_impl.h +92 -0
- data/vendor/faiss/faiss/impl/binary_hamming/avx2.cpp +26 -0
- data/vendor/faiss/faiss/impl/binary_hamming/avx512.cpp +26 -0
- data/vendor/faiss/faiss/impl/binary_hamming/dispatch.h +143 -0
- data/vendor/faiss/faiss/impl/binary_hamming/neon.cpp +26 -0
- data/vendor/faiss/faiss/impl/binary_hamming/rvv.cpp +26 -0
- data/vendor/faiss/faiss/impl/expanded_scanners.h +8 -3
- data/vendor/faiss/faiss/impl/{FastScanDistancePostProcessing.h → fast_scan/FastScanDistancePostProcessing.h} +13 -6
- data/vendor/faiss/faiss/impl/{LookupTableScaler.h → fast_scan/LookupTableScaler.h} +16 -5
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops.h +237 -0
- data/vendor/faiss/faiss/impl/fast_scan/accumulate_loops_512.h +185 -0
- data/vendor/faiss/faiss/impl/fast_scan/decompose_qbs.h +229 -0
- data/vendor/faiss/faiss/impl/fast_scan/dispatching.h +268 -0
- data/vendor/faiss/faiss/impl/{pq4_fast_scan.cpp → fast_scan/fast_scan.cpp} +169 -2
- data/vendor/faiss/faiss/impl/fast_scan/fast_scan.h +341 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx2.cpp +36 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx512.cpp +40 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-neon.cpp +120 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-riscv.cpp +104 -0
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd256.h +213 -0
- data/vendor/faiss/faiss/impl/{pq4_fast_scan_search_qbs.cpp → fast_scan/kernels_simd512.h} +26 -356
- data/vendor/faiss/faiss/impl/fast_scan/rabitq_dispatching.h +90 -0
- data/vendor/faiss/faiss/impl/fast_scan/rabitq_result_handler.h +108 -0
- data/vendor/faiss/faiss/impl/{simd_result_handlers.h → fast_scan/simd_result_handlers.h} +282 -134
- data/vendor/faiss/faiss/impl/hnsw/LockVector.cpp +54 -0
- data/vendor/faiss/faiss/impl/hnsw/LockVector.h +64 -0
- data/vendor/faiss/faiss/impl/hnsw/MinimaxHeap.cpp +91 -0
- data/vendor/faiss/faiss/impl/hnsw/MinimaxHeap.h +64 -0
- data/vendor/faiss/faiss/impl/hnsw/avx2.cpp +104 -0
- data/vendor/faiss/faiss/impl/hnsw/avx512.cpp +111 -0
- data/vendor/faiss/faiss/impl/index_read.cpp +1132 -45
- data/vendor/faiss/faiss/impl/index_read_utils.h +1 -1
- data/vendor/faiss/faiss/impl/index_write.cpp +95 -13
- data/vendor/faiss/faiss/impl/io.cpp +6 -6
- data/vendor/faiss/faiss/impl/io_macros.h +33 -16
- data/vendor/faiss/faiss/impl/kmeans1d.cpp +10 -10
- data/vendor/faiss/faiss/impl/lattice_Zn.cpp +37 -23
- data/vendor/faiss/faiss/impl/lattice_Zn.h +6 -6
- data/vendor/faiss/faiss/impl/mapped_io.cpp +6 -6
- data/vendor/faiss/faiss/impl/platform_macros.h +11 -4
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQScanner_impl.h +549 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQ_QueryTables.cpp +245 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQ_QueryTables.h +105 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/PQDistanceComputer_impl.h +106 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/avx2.cpp +21 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/avx512.cpp +21 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/neon.cpp +21 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/{pq_code_distance-avx2.cpp → pq_code_distance-avx2.h} +9 -13
- data/vendor/faiss/faiss/impl/pq_code_distance/{pq_code_distance-avx512.cpp → pq_code_distance-avx512.h} +9 -57
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.cpp +29 -111
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.h +96 -0
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-inl.h +238 -5
- data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-sve.cpp +5 -7
- data/vendor/faiss/faiss/impl/pq_code_distance/rvv.cpp +68 -0
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +311 -477
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.h +1 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/codecs.h +1 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/distance_computers.h +3 -2
- data/vendor/faiss/faiss/impl/scalar_quantizer/quantizers.h +102 -11
- data/vendor/faiss/faiss/impl/scalar_quantizer/scanners.h +27 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/similarities.h +3 -3
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx2.cpp +148 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512.cpp +167 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-dispatch.h +59 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-neon.cpp +163 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-rvv.cpp +311 -0
- data/vendor/faiss/faiss/impl/scalar_quantizer/training.cpp +192 -8
- data/vendor/faiss/faiss/impl/scalar_quantizer/training.h +12 -0
- data/vendor/faiss/faiss/impl/simd_dispatch.h +100 -66
- data/vendor/faiss/faiss/impl/simdlib/simdlib.h +57 -0
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_avx2.h +264 -172
- data/vendor/faiss/faiss/impl/simdlib/simdlib_avx512.h +414 -0
- data/vendor/faiss/faiss/impl/simdlib/simdlib_dispatch.h +44 -0
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_emulated.h +231 -166
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_neon.h +270 -218
- data/vendor/faiss/faiss/{utils → impl/simdlib}/simdlib_ppc64.h +201 -160
- data/vendor/faiss/faiss/impl/svs_io.cpp +12 -3
- data/vendor/faiss/faiss/impl/svs_io.h +8 -2
- data/vendor/faiss/faiss/index_factory.cpp +86 -18
- data/vendor/faiss/faiss/index_io.h +24 -0
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +66 -16
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +24 -14
- data/vendor/faiss/faiss/invlists/DirectMap.h +4 -3
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +157 -73
- data/vendor/faiss/faiss/invlists/InvertedLists.h +86 -23
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +4 -4
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +13 -13
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSFaissUtils.h +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSFlat.cpp +2 -2
- data/vendor/faiss/faiss/svs/IndexSVSIVF.cpp +350 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVF.h +128 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVFLVQ.cpp +40 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVFLVQ.h +43 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVFLeanVec.cpp +225 -0
- data/vendor/faiss/faiss/svs/IndexSVSIVFLeanVec.h +71 -0
- data/vendor/faiss/faiss/svs/IndexSVSVamana.cpp +25 -1
- data/vendor/faiss/faiss/svs/IndexSVSVamana.h +18 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLVQ.h +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.cpp +12 -3
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.h +7 -2
- data/vendor/faiss/faiss/utils/Heap.cpp +10 -10
- data/vendor/faiss/faiss/utils/NeuralNet.cpp +47 -36
- data/vendor/faiss/faiss/utils/NeuralNet.h +1 -1
- data/vendor/faiss/faiss/utils/approx_topk_hamming/approx_topk_hamming.h +10 -4
- data/vendor/faiss/faiss/utils/distances.cpp +390 -560
- data/vendor/faiss/faiss/utils/distances.h +20 -1
- data/vendor/faiss/faiss/utils/distances_dispatch.h +117 -37
- data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +8 -7
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +33 -14
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.h +12 -1
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +16 -293
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based_neon.cpp +57 -0
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_kernel-inl.h +290 -0
- data/vendor/faiss/faiss/utils/distances_simd.cpp +5 -177
- data/vendor/faiss/faiss/utils/extra_distances.cpp +9 -8
- data/vendor/faiss/faiss/utils/extra_distances.h +32 -6
- data/vendor/faiss/faiss/utils/hamming-inl.h +13 -11
- data/vendor/faiss/faiss/utils/hamming.cpp +66 -517
- data/vendor/faiss/faiss/utils/hamming.h +92 -2
- data/vendor/faiss/faiss/utils/hamming_distance/common.h +287 -10
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx2.cpp +15 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_avx512.cpp +15 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx2.h +142 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-avx512.h +234 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-generic.h +368 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-neon.h +322 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer-rvv.h +39 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_computer.h +146 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_impl.h +481 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_neon.cpp +15 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamming_rvv.cpp +15 -0
- data/vendor/faiss/faiss/utils/partitioning.cpp +66 -987
- data/vendor/faiss/faiss/utils/partitioning.h +31 -0
- data/vendor/faiss/faiss/utils/popcount.h +29 -0
- data/vendor/faiss/faiss/utils/pq_code_distance.h +2 -2
- data/vendor/faiss/faiss/utils/prefetch.h +2 -2
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +30 -30
- data/vendor/faiss/faiss/utils/quantize_lut.h +1 -1
- data/vendor/faiss/faiss/utils/rabitq_simd.h +57 -536
- data/vendor/faiss/faiss/utils/random.cpp +6 -6
- data/vendor/faiss/faiss/utils/simd_impl/IVFFlatScanner-inl.h +51 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_aarch64.cpp +5 -1
- data/vendor/faiss/faiss/utils/simd_impl/distances_arm_sve.cpp +213 -4
- data/vendor/faiss/faiss/utils/simd_impl/distances_autovec-inl.h +163 -10
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx2.cpp +250 -4
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx512.cpp +7 -4
- data/vendor/faiss/faiss/utils/simd_impl/distances_rvv.cpp +189 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_simdlib256.h +195 -0
- data/vendor/faiss/faiss/utils/simd_impl/distances_sse-inl.h +2 -1
- data/vendor/faiss/faiss/utils/{distances_fused/simdlib_based.h → simd_impl/exhaustive_L2sqr_blas_cmax.h} +5 -10
- data/vendor/faiss/faiss/utils/simd_impl/hamming_impl.h +481 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_avx2.cpp +14 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_neon.cpp +14 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_simdlib256.h +1085 -0
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx2.cpp +355 -0
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512.cpp +477 -0
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_neon.cpp +55 -0
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_rvv.cpp +55 -0
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_dispatch.h +32 -0
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels.h +43 -0
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx2.cpp +57 -0
- data/vendor/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx512.cpp +45 -0
- data/vendor/faiss/faiss/utils/simd_levels.cpp +17 -5
- data/vendor/faiss/faiss/utils/simd_levels.h +93 -1
- data/vendor/faiss/faiss/utils/sorting.cpp +48 -36
- data/vendor/faiss/faiss/utils/utils.cpp +5 -5
- data/vendor/faiss/faiss/utils/utils.h +3 -3
- metadata +119 -34
- data/vendor/faiss/faiss/impl/RaBitQStats.cpp +0 -29
- data/vendor/faiss/faiss/impl/RaBitQStats.h +0 -56
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +0 -224
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +0 -230
- data/vendor/faiss/faiss/utils/approx_topk/approx_topk.h +0 -84
- data/vendor/faiss/faiss/utils/approx_topk/avx2-inl.h +0 -196
- data/vendor/faiss/faiss/utils/approx_topk/mode.h +0 -34
- data/vendor/faiss/faiss/utils/distances_fused/avx512.h +0 -36
- data/vendor/faiss/faiss/utils/extra_distances-inl.h +0 -235
- data/vendor/faiss/faiss/utils/hamming_distance/avx2-inl.h +0 -462
- data/vendor/faiss/faiss/utils/hamming_distance/avx512-inl.h +0 -490
- data/vendor/faiss/faiss/utils/hamming_distance/generic-inl.h +0 -449
- data/vendor/faiss/faiss/utils/hamming_distance/hamdis-inl.h +0 -87
- data/vendor/faiss/faiss/utils/hamming_distance/neon-inl.h +0 -524
- data/vendor/faiss/faiss/utils/simdlib.h +0 -42
- data/vendor/faiss/faiss/utils/simdlib_avx512.h +0 -365
- /data/ext/faiss/{utils_rb.h → utils.h} +0 -0
|
@@ -29,7 +29,7 @@ ArrayInvertedLists* set_array_invlist(
|
|
|
29
29
|
IndexIVF* ivf,
|
|
30
30
|
std::vector<std::vector<idx_t>>& ids);
|
|
31
31
|
void read_ProductQuantizer(ProductQuantizer* pq, IOReader* f);
|
|
32
|
-
void read_ScalarQuantizer(ScalarQuantizer* ivsc, IOReader* f);
|
|
32
|
+
void read_ScalarQuantizer(ScalarQuantizer* ivsc, IOReader* f, const Index& idx);
|
|
33
33
|
|
|
34
34
|
} // namespace faiss
|
|
35
35
|
|
|
@@ -53,6 +53,9 @@
|
|
|
53
53
|
#ifdef FAISS_ENABLE_SVS
|
|
54
54
|
#include <faiss/impl/svs_io.h>
|
|
55
55
|
#include <faiss/svs/IndexSVSFlat.h>
|
|
56
|
+
#include <faiss/svs/IndexSVSIVF.h>
|
|
57
|
+
#include <faiss/svs/IndexSVSIVFLVQ.h>
|
|
58
|
+
#include <faiss/svs/IndexSVSIVFLeanVec.h>
|
|
56
59
|
#include <faiss/svs/IndexSVSVamana.h>
|
|
57
60
|
#include <faiss/svs/IndexSVSVamanaLVQ.h>
|
|
58
61
|
#include <faiss/svs/IndexSVSVamanaLeanVec.h>
|
|
@@ -269,11 +272,20 @@ void write_InvertedLists(const InvertedLists* ils, IOWriter* f) {
|
|
|
269
272
|
} else if (
|
|
270
273
|
const auto& ailp =
|
|
271
274
|
dynamic_cast<const ArrayInvertedListsPanorama*>(ils)) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
275
|
+
if (ailp->pano.batch_size == Panorama::kDefaultBatchSize) {
|
|
276
|
+
uint32_t h = fourcc("ilpn");
|
|
277
|
+
WRITE1(h);
|
|
278
|
+
WRITE1(ailp->nlist);
|
|
279
|
+
WRITE1(ailp->code_size);
|
|
280
|
+
WRITE1(ailp->n_levels);
|
|
281
|
+
} else {
|
|
282
|
+
uint32_t h = fourcc("ilp2");
|
|
283
|
+
WRITE1(h);
|
|
284
|
+
WRITE1(ailp->nlist);
|
|
285
|
+
WRITE1(ailp->code_size);
|
|
286
|
+
WRITE1(ailp->n_levels);
|
|
287
|
+
WRITE1(ailp->pano.batch_size);
|
|
288
|
+
}
|
|
277
289
|
uint32_t list_type = fourcc("full");
|
|
278
290
|
WRITE1(list_type);
|
|
279
291
|
std::vector<size_t> sizes;
|
|
@@ -648,13 +660,13 @@ void write_index(const Index* idx, IOWriter* f, int io_flags) {
|
|
|
648
660
|
|
|
649
661
|
write_InvertedLists(ivaqfs->invlists, f);
|
|
650
662
|
} else if (
|
|
651
|
-
const ResidualCoarseQuantizer*
|
|
663
|
+
const ResidualCoarseQuantizer* idxrcq =
|
|
652
664
|
dynamic_cast<const ResidualCoarseQuantizer*>(idx)) {
|
|
653
665
|
uint32_t h = fourcc("ImRQ");
|
|
654
666
|
WRITE1(h);
|
|
655
667
|
write_index_header(idx, f);
|
|
656
|
-
write_ResidualQuantizer(&
|
|
657
|
-
WRITE1(
|
|
668
|
+
write_ResidualQuantizer(&idxrcq->rq, f);
|
|
669
|
+
WRITE1(idxrcq->beam_factor);
|
|
658
670
|
} else if (
|
|
659
671
|
const Index2Layer* idxp_2 = dynamic_cast<const Index2Layer*>(idx)) {
|
|
660
672
|
uint32_t h = fourcc("Ix2L");
|
|
@@ -707,10 +719,18 @@ void write_index(const Index* idx, IOWriter* f, int io_flags) {
|
|
|
707
719
|
} else if (
|
|
708
720
|
const IndexIVFFlatPanorama* ivfp =
|
|
709
721
|
dynamic_cast<const IndexIVFFlatPanorama*>(idx)) {
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
722
|
+
if (ivfp->batch_size == Panorama::kDefaultBatchSize) {
|
|
723
|
+
uint32_t h = fourcc("IwPn");
|
|
724
|
+
WRITE1(h);
|
|
725
|
+
write_ivf_header(ivfp, f);
|
|
726
|
+
WRITE1(ivfp->n_levels);
|
|
727
|
+
} else {
|
|
728
|
+
uint32_t h = fourcc("IwP2");
|
|
729
|
+
WRITE1(h);
|
|
730
|
+
write_ivf_header(ivfp, f);
|
|
731
|
+
WRITE1(ivfp->n_levels);
|
|
732
|
+
WRITE1(ivfp->batch_size);
|
|
733
|
+
}
|
|
714
734
|
write_InvertedLists(ivfp->invlists, f);
|
|
715
735
|
} else if (
|
|
716
736
|
const IndexIVFFlat* ivfl_2 =
|
|
@@ -1007,6 +1027,8 @@ void write_index(const Index* idx, IOWriter* f, int io_flags) {
|
|
|
1007
1027
|
h = fourcc("ILVQ"); // LVQ
|
|
1008
1028
|
} else if (lean != nullptr) {
|
|
1009
1029
|
h = fourcc("ISVL"); // LeanVec
|
|
1030
|
+
} else if (svs->stored_vectors_valid && !svs->stored_vectors.empty()) {
|
|
1031
|
+
h = fourcc("ISV2"); // uncompressed + stored_vectors
|
|
1010
1032
|
} else {
|
|
1011
1033
|
h = fourcc("ISVD"); // uncompressed
|
|
1012
1034
|
}
|
|
@@ -1049,6 +1071,10 @@ void write_index(const Index* idx, IOWriter* f, int io_flags) {
|
|
|
1049
1071
|
os.flush();
|
|
1050
1072
|
}
|
|
1051
1073
|
}
|
|
1074
|
+
|
|
1075
|
+
if (h == fourcc("ISV2")) {
|
|
1076
|
+
WRITEVECTOR(svs->stored_vectors);
|
|
1077
|
+
}
|
|
1052
1078
|
} else if (
|
|
1053
1079
|
const IndexSVSFlat* svs = dynamic_cast<const IndexSVSFlat*>(idx)) {
|
|
1054
1080
|
uint32_t h = fourcc("ISVF");
|
|
@@ -1065,6 +1091,62 @@ void write_index(const Index* idx, IOWriter* f, int io_flags) {
|
|
|
1065
1091
|
svs->serialize_impl(os);
|
|
1066
1092
|
os.flush();
|
|
1067
1093
|
}
|
|
1094
|
+
} else if (
|
|
1095
|
+
const IndexSVSIVF* svs_ivf =
|
|
1096
|
+
dynamic_cast<const IndexSVSIVF*>(idx)) {
|
|
1097
|
+
uint32_t h;
|
|
1098
|
+
auto* lvq = dynamic_cast<const IndexSVSIVFLVQ*>(svs_ivf);
|
|
1099
|
+
auto* lean = dynamic_cast<const IndexSVSIVFLeanVec*>(svs_ivf);
|
|
1100
|
+
if (lvq != nullptr) {
|
|
1101
|
+
h = fourcc("ISIQ"); // IndexSVSIVFLVQ
|
|
1102
|
+
} else if (lean != nullptr) {
|
|
1103
|
+
h = fourcc("ISIL"); // IndexSVSIVFLeanVec
|
|
1104
|
+
} else {
|
|
1105
|
+
h = fourcc("ISID"); // IndexSVSIVF
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
WRITE1(h);
|
|
1109
|
+
write_index_header(svs_ivf, f);
|
|
1110
|
+
WRITE1(svs_ivf->num_centroids);
|
|
1111
|
+
WRITE1(svs_ivf->minibatch_size);
|
|
1112
|
+
WRITE1(svs_ivf->num_iterations);
|
|
1113
|
+
WRITE1(svs_ivf->is_hierarchical);
|
|
1114
|
+
WRITE1(svs_ivf->training_fraction);
|
|
1115
|
+
WRITE1(svs_ivf->hierarchical_level1_clusters);
|
|
1116
|
+
WRITE1(svs_ivf->seed);
|
|
1117
|
+
WRITE1(svs_ivf->n_probes);
|
|
1118
|
+
WRITE1(svs_ivf->k_reorder);
|
|
1119
|
+
WRITE1(svs_ivf->num_threads);
|
|
1120
|
+
WRITE1(svs_ivf->intra_query_threads);
|
|
1121
|
+
WRITE1(svs_ivf->storage_kind);
|
|
1122
|
+
WRITE1(svs_ivf->is_static);
|
|
1123
|
+
|
|
1124
|
+
if (lean != nullptr) {
|
|
1125
|
+
WRITE1(lean->leanvec_d);
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
bool initialized = (svs_ivf->impl != nullptr);
|
|
1129
|
+
WRITE1(initialized);
|
|
1130
|
+
if (initialized) {
|
|
1131
|
+
faiss::BufferedIOWriter bwr(f);
|
|
1132
|
+
faiss::svs_io::WriterStreambuf wbuf(&bwr);
|
|
1133
|
+
std::ostream os(&wbuf);
|
|
1134
|
+
svs_ivf->serialize_impl(os);
|
|
1135
|
+
os.flush();
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
if (lean != nullptr) {
|
|
1139
|
+
// Store training data info
|
|
1140
|
+
bool trained = (lean->training_data != nullptr);
|
|
1141
|
+
WRITE1(trained);
|
|
1142
|
+
if (trained) {
|
|
1143
|
+
faiss::BufferedIOWriter bwr(f);
|
|
1144
|
+
faiss::svs_io::WriterStreambuf wbuf(&bwr);
|
|
1145
|
+
std::ostream os(&wbuf);
|
|
1146
|
+
lean->serialize_training_data(os);
|
|
1147
|
+
os.flush();
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1068
1150
|
}
|
|
1069
1151
|
#endif // FAISS_ENABLE_SVS
|
|
1070
1152
|
else if (
|
|
@@ -1165,7 +1247,7 @@ static void write_binary_multi_hash_map(
|
|
|
1165
1247
|
size_t ntotal,
|
|
1166
1248
|
IOWriter* f) {
|
|
1167
1249
|
int id_bits = 0;
|
|
1168
|
-
while ((ntotal > ((
|
|
1250
|
+
while ((ntotal > (size_t(1) << id_bits))) {
|
|
1169
1251
|
id_bits++;
|
|
1170
1252
|
}
|
|
1171
1253
|
WRITE1(id_bits);
|
|
@@ -134,14 +134,14 @@ int FileIOWriter::filedescriptor() {
|
|
|
134
134
|
* IO buffer
|
|
135
135
|
***********************************************************************/
|
|
136
136
|
|
|
137
|
-
BufferedIOReader::BufferedIOReader(IOReader*
|
|
138
|
-
: reader(
|
|
139
|
-
bsz(
|
|
137
|
+
BufferedIOReader::BufferedIOReader(IOReader* reader_in, size_t bsz_in)
|
|
138
|
+
: reader(reader_in),
|
|
139
|
+
bsz(bsz_in),
|
|
140
140
|
ofs(0),
|
|
141
141
|
ofs2(0),
|
|
142
142
|
b0(0),
|
|
143
143
|
b1(0),
|
|
144
|
-
buffer(
|
|
144
|
+
buffer(bsz_in) {}
|
|
145
145
|
|
|
146
146
|
size_t BufferedIOReader::operator()(void* ptr, size_t unitsize, size_t nitems) {
|
|
147
147
|
size_t size = unitsize * nitems;
|
|
@@ -184,8 +184,8 @@ size_t BufferedIOReader::operator()(void* ptr, size_t unitsize, size_t nitems) {
|
|
|
184
184
|
return nb / unitsize;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
BufferedIOWriter::BufferedIOWriter(IOWriter*
|
|
188
|
-
: writer(
|
|
187
|
+
BufferedIOWriter::BufferedIOWriter(IOWriter* writer_in, size_t bsz_in)
|
|
188
|
+
: writer(writer_in), bsz(bsz_in), ofs2(0), b0(0), buffer(bsz_in) {}
|
|
189
189
|
|
|
190
190
|
size_t BufferedIOWriter::operator()(
|
|
191
191
|
const void* ptr,
|
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
* always called f and thus is not passed in as a macro parameter.
|
|
18
18
|
**************************************************************/
|
|
19
19
|
|
|
20
|
+
namespace faiss {
|
|
21
|
+
size_t get_deserialization_vector_byte_limit();
|
|
22
|
+
} // namespace faiss
|
|
23
|
+
|
|
20
24
|
#define READANDCHECK(ptr, n) \
|
|
21
25
|
{ \
|
|
22
26
|
size_t ret = (*f)(ptr, sizeof(*(ptr)), n); \
|
|
@@ -37,14 +41,24 @@
|
|
|
37
41
|
READ1(x); \
|
|
38
42
|
}
|
|
39
43
|
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
(
|
|
47
|
-
|
|
44
|
+
// Rejects vectors whose total allocation would exceed the configurable
|
|
45
|
+
// byte limit (default 1 TB).
|
|
46
|
+
#define READVECTOR(vec) \
|
|
47
|
+
{ \
|
|
48
|
+
size_t size; \
|
|
49
|
+
READANDCHECK(&size, 1); \
|
|
50
|
+
FAISS_THROW_IF_NOT( \
|
|
51
|
+
size >= 0 && \
|
|
52
|
+
size < (faiss::get_deserialization_vector_byte_limit() / \
|
|
53
|
+
sizeof(*(vec).data()))); \
|
|
54
|
+
FAISS_THROW_IF_NOT_FMT( \
|
|
55
|
+
size <= SIZE_MAX / sizeof((vec)[0]), \
|
|
56
|
+
"READVECTOR: size %zu would overflow for element " \
|
|
57
|
+
"size %zu", \
|
|
58
|
+
size, \
|
|
59
|
+
sizeof((vec)[0])); \
|
|
60
|
+
(vec).resize(size); \
|
|
61
|
+
READANDCHECK((vec).data(), size); \
|
|
48
62
|
}
|
|
49
63
|
|
|
50
64
|
#define WRITEANDCHECK(ptr, n) \
|
|
@@ -78,12 +92,15 @@
|
|
|
78
92
|
WRITEANDCHECK((vec).data(), size * 4); \
|
|
79
93
|
}
|
|
80
94
|
|
|
81
|
-
#define READXBVECTOR(vec)
|
|
82
|
-
{
|
|
83
|
-
size_t size;
|
|
84
|
-
READANDCHECK(&size, 1);
|
|
85
|
-
FAISS_THROW_IF_NOT(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
95
|
+
#define READXBVECTOR(vec) \
|
|
96
|
+
{ \
|
|
97
|
+
size_t size; \
|
|
98
|
+
READANDCHECK(&size, 1); \
|
|
99
|
+
FAISS_THROW_IF_NOT( \
|
|
100
|
+
size >= 0 && \
|
|
101
|
+
size < (faiss::get_deserialization_vector_byte_limit() / \
|
|
102
|
+
(4 * sizeof(*(vec).data())))); \
|
|
103
|
+
size *= 4; \
|
|
104
|
+
(vec).resize(size); \
|
|
105
|
+
READANDCHECK((vec).data(), size); \
|
|
89
106
|
}
|
|
@@ -48,12 +48,12 @@ void interpolate(
|
|
|
48
48
|
const LookUpFunc& lookup,
|
|
49
49
|
idx_t* argmins) {
|
|
50
50
|
std::unordered_map<idx_t, idx_t> idx_to_col;
|
|
51
|
-
for (
|
|
51
|
+
for (size_t idx = 0; idx < cols.size(); ++idx) {
|
|
52
52
|
idx_to_col[cols[idx]] = idx;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
idx_t start = 0;
|
|
56
|
-
for (
|
|
56
|
+
for (size_t r = 0; r < rows.size(); r += 2) {
|
|
57
57
|
idx_t row = rows[r];
|
|
58
58
|
idx_t end = cols.size() - 1;
|
|
59
59
|
if (r < rows.size() - 1) {
|
|
@@ -107,7 +107,7 @@ void smawk_impl(
|
|
|
107
107
|
|
|
108
108
|
// call recursively on odd-indexed rows
|
|
109
109
|
std::vector<idx_t> odd_rows;
|
|
110
|
-
for (
|
|
110
|
+
for (size_t i = 1; i < rows.size(); i += 2) {
|
|
111
111
|
odd_rows.push_back(rows[i]);
|
|
112
112
|
}
|
|
113
113
|
smawk_impl(odd_rows, cols, lookup, argmins);
|
|
@@ -175,10 +175,10 @@ class Matrix {
|
|
|
175
175
|
idx_t ncols;
|
|
176
176
|
|
|
177
177
|
public:
|
|
178
|
-
Matrix(idx_t
|
|
179
|
-
this->nrows =
|
|
180
|
-
this->ncols =
|
|
181
|
-
data.resize(
|
|
178
|
+
Matrix(idx_t nrows_in, idx_t ncols_in) {
|
|
179
|
+
this->nrows = nrows_in;
|
|
180
|
+
this->ncols = ncols_in;
|
|
181
|
+
data.resize(nrows_in * ncols_in);
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
inline T& at(idx_t i, idx_t j) {
|
|
@@ -240,14 +240,14 @@ double kmeans1d(const float* x, size_t n, size_t nclusters, float* centroids) {
|
|
|
240
240
|
Matrix<float> D(nclusters, n);
|
|
241
241
|
Matrix<idx_t> T(nclusters, n);
|
|
242
242
|
|
|
243
|
-
for (idx_t m = 0; m < n; m++) {
|
|
243
|
+
for (idx_t m = 0; m < static_cast<idx_t>(n); m++) {
|
|
244
244
|
D.at(0, m) = CC(0, m);
|
|
245
245
|
T.at(0, m) = 0;
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
std::vector<idx_t> indices(nclusters, 0);
|
|
249
249
|
|
|
250
|
-
for (idx_t k = 1; k < nclusters; ++k) {
|
|
250
|
+
for (idx_t k = 1; k < static_cast<idx_t>(nclusters); ++k) {
|
|
251
251
|
// we define C here
|
|
252
252
|
auto C = [&D, &CC, &k](idx_t m, idx_t i) {
|
|
253
253
|
if (i == 0) {
|
|
@@ -259,7 +259,7 @@ double kmeans1d(const float* x, size_t n, size_t nclusters, float* centroids) {
|
|
|
259
259
|
|
|
260
260
|
std::vector<idx_t> argmins(n); // argmin of each row
|
|
261
261
|
smawk(n, n, C, argmins.data());
|
|
262
|
-
for (
|
|
262
|
+
for (size_t m = 0; m < argmins.size(); m++) {
|
|
263
263
|
idx_t idx = argmins[m];
|
|
264
264
|
D.at(k, m) = C(m, idx);
|
|
265
265
|
T.at(k, m) = idx;
|
|
@@ -41,7 +41,7 @@ struct Comb {
|
|
|
41
41
|
std::vector<uint64_t> tab; // Pascal's triangle
|
|
42
42
|
int nmax;
|
|
43
43
|
|
|
44
|
-
explicit Comb(int
|
|
44
|
+
explicit Comb(int nmax_in) : nmax(nmax_in) {
|
|
45
45
|
tab.resize(nmax * nmax, 0);
|
|
46
46
|
tab[0] = 1;
|
|
47
47
|
for (int i = 1; i < nmax; i++) {
|
|
@@ -172,9 +172,9 @@ void repeats_decode_64(
|
|
|
172
172
|
|
|
173
173
|
} // anonymous namespace
|
|
174
174
|
|
|
175
|
-
Repeats::Repeats(int
|
|
175
|
+
Repeats::Repeats(int dim_in, const float* c) : dim(dim_in) {
|
|
176
176
|
for (int i = 0; i < dim; i++) {
|
|
177
|
-
|
|
177
|
+
size_t j = 0;
|
|
178
178
|
for (;;) {
|
|
179
179
|
if (j == repeats.size()) {
|
|
180
180
|
repeats.push_back(Repeat{c[i], 1});
|
|
@@ -192,7 +192,7 @@ Repeats::Repeats(int dim, const float* c) : dim(dim) {
|
|
|
192
192
|
uint64_t Repeats::count() const {
|
|
193
193
|
uint64_t accu = 1;
|
|
194
194
|
int remain = dim;
|
|
195
|
-
for (
|
|
195
|
+
for (size_t i = 0; i < repeats.size(); i++) {
|
|
196
196
|
accu *= comb(remain, repeats[i].n);
|
|
197
197
|
remain -= repeats[i].n;
|
|
198
198
|
}
|
|
@@ -275,7 +275,7 @@ void EnumeratedVectors::encode_multi(size_t n, const float* c, uint64_t* codes)
|
|
|
275
275
|
#pragma omp parallel if (n > 1000)
|
|
276
276
|
{
|
|
277
277
|
#pragma omp for
|
|
278
|
-
for (
|
|
278
|
+
for (int64_t i = 0; i < static_cast<int64_t>(n); i++) {
|
|
279
279
|
codes[i] = encode(c + i * dim);
|
|
280
280
|
}
|
|
281
281
|
}
|
|
@@ -286,7 +286,7 @@ void EnumeratedVectors::decode_multi(size_t n, const uint64_t* codes, float* c)
|
|
|
286
286
|
#pragma omp parallel if (n > 1000)
|
|
287
287
|
{
|
|
288
288
|
#pragma omp for
|
|
289
|
-
for (
|
|
289
|
+
for (int64_t i = 0; i < static_cast<int64_t>(n); i++) {
|
|
290
290
|
decode(codes[i], c + i * dim);
|
|
291
291
|
}
|
|
292
292
|
}
|
|
@@ -325,11 +325,11 @@ void EnumeratedVectors::find_nn(
|
|
|
325
325
|
* ZnSphereSearch
|
|
326
326
|
**********************************************************/
|
|
327
327
|
|
|
328
|
-
ZnSphereSearch::ZnSphereSearch(int dim, int
|
|
328
|
+
ZnSphereSearch::ZnSphereSearch(int dim, int r2_in) : dimS(dim), r2(r2_in) {
|
|
329
329
|
FAISS_THROW_IF_NOT_MSG(
|
|
330
330
|
dim > 0 && dim <= 64, "ZnSphereSearch: dim must be in [1, 64]");
|
|
331
331
|
FAISS_THROW_IF_NOT_MSG(
|
|
332
|
-
|
|
332
|
+
r2_in >= 0 && r2_in <= 512,
|
|
333
333
|
"ZnSphereSearch: r2 must be in [0, 512] to avoid"
|
|
334
334
|
" excessive computation in sum_of_sq");
|
|
335
335
|
voc = sum_of_sq(r2, int(ceil(sqrt(r2)) + 1), dim);
|
|
@@ -404,8 +404,8 @@ void ZnSphereSearch::search_multi(
|
|
|
404
404
|
* ZnSphereCodec
|
|
405
405
|
**********************************************************/
|
|
406
406
|
|
|
407
|
-
ZnSphereCodec::ZnSphereCodec(int
|
|
408
|
-
: ZnSphereSearch(
|
|
407
|
+
ZnSphereCodec::ZnSphereCodec(int dim_in, int r2_in)
|
|
408
|
+
: ZnSphereSearch(dim_in, r2_in), EnumeratedVectors(dim_in) {
|
|
409
409
|
nv = 0;
|
|
410
410
|
for (int i = 0; i < natom; i++) {
|
|
411
411
|
Repeats repeats(dim, &voc[i * dim]);
|
|
@@ -497,10 +497,10 @@ void ZnSphereCodecRec::set_nv_cum(int ld, int r2t, int r2a, uint64_t cum) {
|
|
|
497
497
|
all_nv_cum[(ld * (r2 + 1) + r2t) * (r2 + 1) + r2a] = cum;
|
|
498
498
|
}
|
|
499
499
|
|
|
500
|
-
ZnSphereCodecRec::ZnSphereCodecRec(int
|
|
501
|
-
: EnumeratedVectors(
|
|
500
|
+
ZnSphereCodecRec::ZnSphereCodecRec(int dim_in, int r2_in)
|
|
501
|
+
: EnumeratedVectors(dim_in), r2(r2_in) {
|
|
502
502
|
FAISS_THROW_IF_NOT_MSG(
|
|
503
|
-
|
|
503
|
+
dim_in > 0 && r2_in >= 0, "invalid ZnSphereCodecRec parameters");
|
|
504
504
|
log2_dim = 0;
|
|
505
505
|
while (dim > (1 << log2_dim)) {
|
|
506
506
|
log2_dim++;
|
|
@@ -533,13 +533,13 @@ ZnSphereCodecRec::ZnSphereCodecRec(int dim, int r2)
|
|
|
533
533
|
|
|
534
534
|
for (int ld = 1; ld <= log2_dim; ld++) {
|
|
535
535
|
for (int r2sub = 0; r2sub <= r2; r2sub++) {
|
|
536
|
-
uint64_t
|
|
536
|
+
uint64_t nv_acc = 0;
|
|
537
537
|
for (int r2a = 0; r2a <= r2sub; r2a++) {
|
|
538
538
|
int r2b = r2sub - r2a;
|
|
539
|
-
set_nv_cum(ld, r2sub, r2a,
|
|
540
|
-
|
|
539
|
+
set_nv_cum(ld, r2sub, r2a, nv_acc);
|
|
540
|
+
nv_acc += get_nv(ld - 1, r2a) * get_nv(ld - 1, r2b);
|
|
541
541
|
}
|
|
542
|
-
all_nv[ld * (r2 + 1) + r2sub] =
|
|
542
|
+
all_nv[ld * (r2 + 1) + r2sub] = nv_acc;
|
|
543
543
|
}
|
|
544
544
|
}
|
|
545
545
|
nv = get_nv(log2_dim, r2);
|
|
@@ -554,17 +554,31 @@ ZnSphereCodecRec::ZnSphereCodecRec(int dim, int r2)
|
|
|
554
554
|
int cache_level = std::min(3, log2_dim - 1);
|
|
555
555
|
decode_cache_ld = 0;
|
|
556
556
|
assert(cache_level <= log2_dim);
|
|
557
|
+
|
|
557
558
|
decode_cache.resize((r2 + 1));
|
|
558
559
|
|
|
560
|
+
// The decode cache stores total_cache_entries * dimsub floats.
|
|
561
|
+
// Cap at 2^27 total floats (~512 MB), aligned with the nv_cum
|
|
562
|
+
// memory cap above which also uses 2^27 entries. The entry count
|
|
563
|
+
// grows as the number of lattice points in dimension
|
|
564
|
+
// 2^cache_level, which is O(r2^(dim/2)) -- much faster than the
|
|
565
|
+
// O(r2^2) growth of nv_cum.
|
|
566
|
+
size_t total_cache_entries = 0;
|
|
567
|
+
int dimsub = (1 << cache_level);
|
|
568
|
+
|
|
559
569
|
for (int r2sub = 0; r2sub <= r2; r2sub++) {
|
|
560
570
|
int ld = cache_level;
|
|
561
571
|
uint64_t nvi = get_nv(ld, r2sub);
|
|
572
|
+
total_cache_entries += nvi;
|
|
573
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
574
|
+
total_cache_entries <= (size_t(1) << 27) / dimsub,
|
|
575
|
+
"ZnSphereCodecRec: r2 too large, decode cache "
|
|
576
|
+
"would require excessive memory");
|
|
562
577
|
std::vector<float>& cache = decode_cache[r2sub];
|
|
563
|
-
int dimsub = (1 << cache_level);
|
|
564
578
|
cache.resize(nvi * dimsub);
|
|
565
579
|
std::vector<float> c(dim);
|
|
566
580
|
uint64_t code0 = get_nv_cum(cache_level + 1, r2, r2 - r2sub);
|
|
567
|
-
for (
|
|
581
|
+
for (uint64_t i = 0; i < nvi; i++) {
|
|
568
582
|
decode(i + code0, c.data());
|
|
569
583
|
memcpy(&cache[i * dimsub],
|
|
570
584
|
c.data() + dim - dimsub,
|
|
@@ -670,10 +684,10 @@ void ZnSphereCodecRec::decode(uint64_t code, float* c) const {
|
|
|
670
684
|
}
|
|
671
685
|
|
|
672
686
|
// if not use_rec, instantiate an arbitrary harmless znc_rec
|
|
673
|
-
ZnSphereCodecAlt::ZnSphereCodecAlt(int
|
|
674
|
-
: ZnSphereCodec(
|
|
675
|
-
use_rec((
|
|
676
|
-
znc_rec(use_rec ?
|
|
687
|
+
ZnSphereCodecAlt::ZnSphereCodecAlt(int dim_in, int r2_in)
|
|
688
|
+
: ZnSphereCodec(dim_in, r2_in),
|
|
689
|
+
use_rec((dim_in & (dim_in - 1)) == 0),
|
|
690
|
+
znc_rec(use_rec ? dim_in : 8, use_rec ? r2_in : 14) {}
|
|
677
691
|
|
|
678
692
|
uint64_t ZnSphereCodecAlt::encode(const float* x) const {
|
|
679
693
|
if (!use_rec) {
|
|
@@ -29,7 +29,7 @@ struct ZnSphereSearch {
|
|
|
29
29
|
/// size dim * natom
|
|
30
30
|
std::vector<float> voc;
|
|
31
31
|
|
|
32
|
-
ZnSphereSearch(int dim, int
|
|
32
|
+
ZnSphereSearch(int dim, int r2_in);
|
|
33
33
|
|
|
34
34
|
/// find nearest centroid. x does not need to be normalized
|
|
35
35
|
float search(const float* x, float* c) const;
|
|
@@ -57,7 +57,7 @@ struct EnumeratedVectors {
|
|
|
57
57
|
uint64_t nv;
|
|
58
58
|
int dim;
|
|
59
59
|
|
|
60
|
-
explicit EnumeratedVectors(int
|
|
60
|
+
explicit EnumeratedVectors(int dim_in) : nv(0), dim(dim_in) {}
|
|
61
61
|
|
|
62
62
|
/// encode a vector from a collection
|
|
63
63
|
virtual uint64_t encode(const float* x) const = 0;
|
|
@@ -98,7 +98,7 @@ struct Repeats {
|
|
|
98
98
|
std::vector<Repeat> repeats;
|
|
99
99
|
|
|
100
100
|
// initialize from a template of the atom.
|
|
101
|
-
Repeats(int
|
|
101
|
+
Repeats(int dim_in = 0, const float* c = nullptr);
|
|
102
102
|
|
|
103
103
|
// count number of possible codes for this atom
|
|
104
104
|
uint64_t count() const;
|
|
@@ -124,7 +124,7 @@ struct ZnSphereCodec : ZnSphereSearch, EnumeratedVectors {
|
|
|
124
124
|
uint64_t nv;
|
|
125
125
|
size_t code_size;
|
|
126
126
|
|
|
127
|
-
ZnSphereCodec(int
|
|
127
|
+
ZnSphereCodec(int dim_in, int r2_in);
|
|
128
128
|
|
|
129
129
|
uint64_t search_and_encode(const float* x) const;
|
|
130
130
|
|
|
@@ -146,7 +146,7 @@ struct ZnSphereCodecRec : EnumeratedVectors {
|
|
|
146
146
|
int log2_dim;
|
|
147
147
|
int code_size;
|
|
148
148
|
|
|
149
|
-
ZnSphereCodecRec(int
|
|
149
|
+
ZnSphereCodecRec(int dim_in, int r2_in);
|
|
150
150
|
|
|
151
151
|
uint64_t encode_centroid(const float* c) const;
|
|
152
152
|
|
|
@@ -176,7 +176,7 @@ struct ZnSphereCodecAlt : ZnSphereCodec {
|
|
|
176
176
|
bool use_rec;
|
|
177
177
|
ZnSphereCodecRec znc_rec;
|
|
178
178
|
|
|
179
|
-
ZnSphereCodecAlt(int
|
|
179
|
+
ZnSphereCodecAlt(int dim_in, int r2_in);
|
|
180
180
|
|
|
181
181
|
uint64_t encode(const float* x) const override;
|
|
182
182
|
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
#include <stdio.h>
|
|
9
9
|
|
|
10
|
-
#if defined(__linux__) || defined(__FreeBSD__)
|
|
10
|
+
#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
|
|
11
11
|
|
|
12
12
|
#include <fcntl.h>
|
|
13
13
|
#include <sys/mman.h>
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
|
|
28
28
|
namespace faiss {
|
|
29
29
|
|
|
30
|
-
#if defined(__linux__) || defined(__FreeBSD__)
|
|
30
|
+
#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
|
|
31
31
|
|
|
32
32
|
struct MmappedFileMappingOwner::PImpl {
|
|
33
33
|
void* ptr = nullptr;
|
|
@@ -60,11 +60,11 @@ struct MmappedFileMappingOwner::PImpl {
|
|
|
60
60
|
void* address = mmap(
|
|
61
61
|
nullptr, filesize, PROT_READ, MAP_SHARED, fileno(f.get()), 0);
|
|
62
62
|
FAISS_THROW_IF_NOT_FMT(
|
|
63
|
-
address !=
|
|
63
|
+
address != MAP_FAILED, "could not mmap(): %s", strerror(errno));
|
|
64
64
|
|
|
65
65
|
// btw, fd can be closed here
|
|
66
66
|
|
|
67
|
-
madvise(address, filesize, MADV_RANDOM);
|
|
67
|
+
(void)madvise(address, filesize, MADV_RANDOM);
|
|
68
68
|
|
|
69
69
|
// save it
|
|
70
70
|
ptr = address;
|
|
@@ -83,11 +83,11 @@ struct MmappedFileMappingOwner::PImpl {
|
|
|
83
83
|
void* address =
|
|
84
84
|
mmap(nullptr, filesize, PROT_READ, MAP_SHARED, fileno(f), 0);
|
|
85
85
|
FAISS_THROW_IF_NOT_FMT(
|
|
86
|
-
address !=
|
|
86
|
+
address != MAP_FAILED, "could not mmap(): %s", strerror(errno));
|
|
87
87
|
|
|
88
88
|
// btw, fd can be closed here
|
|
89
89
|
|
|
90
|
-
madvise(address, filesize, MADV_RANDOM);
|
|
90
|
+
(void)madvise(address, filesize, MADV_RANDOM);
|
|
91
91
|
|
|
92
92
|
// save it
|
|
93
93
|
ptr = address;
|
|
@@ -74,10 +74,6 @@ inline int __builtin_clzll(uint64_t x) {
|
|
|
74
74
|
}
|
|
75
75
|
#endif
|
|
76
76
|
|
|
77
|
-
#define __builtin_popcount __popcnt
|
|
78
|
-
#define __builtin_popcountl __popcnt64
|
|
79
|
-
#define __builtin_popcountll __popcnt64
|
|
80
|
-
|
|
81
77
|
#ifndef __clang__
|
|
82
78
|
#define __m128i_u __m128i
|
|
83
79
|
#define __m256i_u __m256i
|
|
@@ -110,9 +106,16 @@ inline int __builtin_clzll(uint64_t x) {
|
|
|
110
106
|
// MSVC uses pragma pack instead of __attribute__((packed))
|
|
111
107
|
// Use FAISS_PACK_STRUCTS_BEGIN/END to wrap packed structure definitions
|
|
112
108
|
#define FAISS_PACKED
|
|
109
|
+
#define FAISS_RESTRICT __restrict
|
|
113
110
|
#define FAISS_PACK_STRUCTS_BEGIN __pragma(pack(push, 1))
|
|
114
111
|
#define FAISS_PACK_STRUCTS_END __pragma(pack(pop))
|
|
115
112
|
|
|
113
|
+
#ifdef SWIG
|
|
114
|
+
#define FAISS_MAYBE_UNUSED
|
|
115
|
+
#else
|
|
116
|
+
#define FAISS_MAYBE_UNUSED [[maybe_unused]]
|
|
117
|
+
#endif
|
|
118
|
+
|
|
116
119
|
#else
|
|
117
120
|
/*******************************************************
|
|
118
121
|
* Linux and OSX
|
|
@@ -126,9 +129,13 @@ inline int __builtin_clzll(uint64_t x) {
|
|
|
126
129
|
#ifdef SWIG
|
|
127
130
|
#define ALIGNED(x)
|
|
128
131
|
#define FAISS_PACKED
|
|
132
|
+
#define FAISS_RESTRICT
|
|
133
|
+
#define FAISS_MAYBE_UNUSED
|
|
129
134
|
#else
|
|
130
135
|
#define ALIGNED(x) __attribute__((aligned(x)))
|
|
131
136
|
#define FAISS_PACKED __attribute__((packed))
|
|
137
|
+
#define FAISS_RESTRICT __restrict
|
|
138
|
+
#define FAISS_MAYBE_UNUSED [[maybe_unused]]
|
|
132
139
|
#endif
|
|
133
140
|
|
|
134
141
|
// On non-Windows, FAISS_PACKED handles packing, so these are no-ops
|