diff --git a/faiss/AutoTune.cpp b/faiss/AutoTune.cpp index 33044776b9..216d88c051 100644 --- a/faiss/AutoTune.cpp +++ b/faiss/AutoTune.cpp @@ -174,7 +174,7 @@ double OperatingPoints::t_for_perf(double perf) const { if (perf > a.back().perf) { return 1e50; } - int i0 = -1, i1 = a.size() - 1; + int i0 = -1, i1 = static_cast(a.size()) - 1; while (i0 + 1 < i1) { int imed = (i0 + i1 + 1) / 2; if (a[imed].perf < perf) { @@ -279,7 +279,8 @@ size_t ParameterSpace::n_combinations() const { /// get string representation of the combination std::string ParameterSpace::combination_name(size_t cno) const { - char buf[1000], *wp = buf; + char buf[1000]; + char* wp = buf; *wp = 0; for (size_t i = 0; i < parameter_ranges.size(); i++) { FAISS_THROW_IF_NOT_MSG( @@ -786,7 +787,7 @@ void ParameterSpace::explore( // make sure the slowest and fastest experiment are run perm[0] = 0; if (n_comb > 1) { - perm[1] = n_comb - 1; + perm[1] = static_cast(n_comb - 1); rand_perm(&perm[2], n_comb - 2, 1234); for (size_t i = 2; i < perm.size(); i++) { perm[i]++; diff --git a/faiss/AutoTune.h b/faiss/AutoTune.h index 4551de2564..d094c06ecf 100644 --- a/faiss/AutoTune.h +++ b/faiss/AutoTune.h @@ -51,6 +51,11 @@ struct AutoTuneCriterion { virtual double evaluate(const float* D, const idx_t* I) const = 0; virtual ~AutoTuneCriterion() {} + // rule of five defaults + AutoTuneCriterion(const AutoTuneCriterion&) = default; + AutoTuneCriterion& operator=(const AutoTuneCriterion&) = default; + AutoTuneCriterion(AutoTuneCriterion&&) = default; + AutoTuneCriterion& operator=(AutoTuneCriterion&&) = default; }; struct OneRecallAtRCriterion : AutoTuneCriterion { @@ -61,6 +66,11 @@ struct OneRecallAtRCriterion : AutoTuneCriterion { double evaluate(const float* D, const idx_t* I) const override; ~OneRecallAtRCriterion() override {} + // rule of five defaults + OneRecallAtRCriterion(const OneRecallAtRCriterion&) = default; + OneRecallAtRCriterion& operator=(const OneRecallAtRCriterion&) = default; + OneRecallAtRCriterion(OneRecallAtRCriterion&&) = default; + OneRecallAtRCriterion& operator=(OneRecallAtRCriterion&&) = default; }; struct IntersectionCriterion : AutoTuneCriterion { @@ -71,6 +81,11 @@ struct IntersectionCriterion : AutoTuneCriterion { double evaluate(const float* D, const idx_t* I) const override; ~IntersectionCriterion() override {} + // rule of five defaults + IntersectionCriterion(const IntersectionCriterion&) = default; + IntersectionCriterion& operator=(const IntersectionCriterion&) = default; + IntersectionCriterion(IntersectionCriterion&&) = default; + IntersectionCriterion& operator=(IntersectionCriterion&&) = default; }; /** @@ -218,6 +233,11 @@ struct ParameterSpace { OperatingPoints* ops) const; virtual ~ParameterSpace() {} + // rule of five defaults + ParameterSpace(const ParameterSpace&) = default; + ParameterSpace& operator=(const ParameterSpace&) = default; + ParameterSpace(ParameterSpace&&) = default; + ParameterSpace& operator=(ParameterSpace&&) = default; }; } // namespace faiss diff --git a/faiss/Clustering.cpp b/faiss/Clustering.cpp index 8d55585390..b2ac0ce826 100644 --- a/faiss/Clustering.cpp +++ b/faiss/Clustering.cpp @@ -92,7 +92,7 @@ idx_t subsample_training_set( const idx_t new_nx = clus.k * clus.max_points_per_centroid; perm.resize(new_nx); for (idx_t i = 0; i < new_nx; i++) { - perm[i] = rng.rand_int(nx); + perm[i] = rng.rand_int(static_cast(nx)); } } else { // use subsampling with a default std rng @@ -262,7 +262,7 @@ int split_clusters( } } - return nsplit; + return static_cast(nsplit); } } // namespace @@ -538,7 +538,7 @@ void Clustering::train_encoded( obj, (getmillisecs() - t0) / 1000.0, t_search_tot / 1000, - imbalance_factor(nx, k, assign.get()), + imbalance_factor(nx, static_cast(k), assign.get()), nsplit}; iteration_stats.push_back(stats); @@ -649,7 +649,7 @@ float kmeans_clustering( size_t k, const float* x, float* centroids) { - Clustering clus(d, k); + Clustering clus(static_cast(d), static_cast(k)); clus.verbose = d * n * k > (size_t(1) << 30); // display logs if > 1Gflop per iteration IndexFlatL2 index(d); @@ -700,7 +700,7 @@ void ProgressiveDimClustering::train( ProgressiveDimIndexFactory& factory) { int d_prev = 0; - PCAMatrix pca(d, d); + PCAMatrix pca(static_cast(d), static_cast(d)); std::vector xbuf; if (apply_pca) { @@ -725,7 +725,7 @@ void ProgressiveDimClustering::train( } std::unique_ptr clustering_index(factory(di)); - Clustering clus(di, k, *this); + Clustering clus(di, static_cast(k), *this); if (d_prev > 0) { // copy warm-start centroids (padded with 0s) clus.centroids.resize(k * di); diff --git a/faiss/Clustering.h b/faiss/Clustering.h index acb501bce8..f71441d376 100644 --- a/faiss/Clustering.h +++ b/faiss/Clustering.h @@ -145,6 +145,11 @@ struct Clustering : ClusteringParameters { void post_process_centroids(); virtual ~Clustering() {} + // rule of five defaults + Clustering(const Clustering&) = default; + Clustering& operator=(const Clustering&) = default; + Clustering(Clustering&&) = default; + Clustering& operator=(Clustering&&) = default; }; /** Exact 1D clustering algorithm @@ -159,6 +164,11 @@ struct Clustering1D : Clustering { void train_exact(idx_t n, const float* x); virtual ~Clustering1D() {} + // rule of five defaults + Clustering1D(const Clustering1D&) = default; + Clustering1D& operator=(const Clustering1D&) = default; + Clustering1D(Clustering1D&&) = default; + Clustering1D& operator=(Clustering1D&&) = default; }; struct ProgressiveDimClusteringParameters : ClusteringParameters { @@ -174,6 +184,14 @@ struct ProgressiveDimIndexFactory { virtual Index* operator()(int dim); virtual ~ProgressiveDimIndexFactory() {} + // rule of five defaults + ProgressiveDimIndexFactory() = default; + ProgressiveDimIndexFactory(const ProgressiveDimIndexFactory&) = default; + ProgressiveDimIndexFactory& operator=(const ProgressiveDimIndexFactory&) = + default; + ProgressiveDimIndexFactory(ProgressiveDimIndexFactory&&) = default; + ProgressiveDimIndexFactory& operator=(ProgressiveDimIndexFactory&&) = + default; }; /** K-means clustering with progressive dimensions used @@ -208,6 +226,12 @@ struct ProgressiveDimClustering : ProgressiveDimClusteringParameters { void train(idx_t n, const float* x, ProgressiveDimIndexFactory& factory); virtual ~ProgressiveDimClustering() {} + // rule of five defaults + ProgressiveDimClustering(const ProgressiveDimClustering&) = default; + ProgressiveDimClustering& operator=(const ProgressiveDimClustering&) = + default; + ProgressiveDimClustering(ProgressiveDimClustering&&) = default; + ProgressiveDimClustering& operator=(ProgressiveDimClustering&&) = default; }; /** simplified interface diff --git a/faiss/IVFlib.cpp b/faiss/IVFlib.cpp index 10766faf79..ecc1f23ff3 100644 --- a/faiss/IVFlib.cpp +++ b/faiss/IVFlib.cpp @@ -465,7 +465,7 @@ IndexIVFResidualQuantizer* ivf_residual_from_quantizer( std::vector nbits(nlevel); std::copy(rq.nbits.begin(), rq.nbits.begin() + nlevel, nbits.begin()); std::unique_ptr rcq( - new ResidualCoarseQuantizer(rq.d, nbits)); + new ResidualCoarseQuantizer(static_cast(rq.d), nbits)); // set the coarse quantizer from the 2 first quantizers rcq->rq.initialize_from(rq); @@ -492,7 +492,8 @@ IndexIVFResidualQuantizer* ivf_residual_from_quantizer( faiss::METRIC_L2, rq.search_type)); index->own_fields = true; - rcq.release(); + // Ownership transferred to index via own_fields = true + (void)rcq.release(); index->by_residual = true; index->rq.initialize_from(rq, nlevel); index->is_trained = true; @@ -528,14 +529,14 @@ void ivf_residual_add_from_flat_codes( for (idx_t i = 0; i < static_cast(nb); i++) { const uint8_t* code = &raw_codes[i * code_size]; BitstringReader rd(code, code_size); - idx_t list_no = rd.read(rcq->rq.tot_bits); + idx_t list_no = rd.read(static_cast(rcq->rq.tot_bits)); if (list_no % nt == rank) { // each thread takes care of 1/nt of the invlists // copy AQ indexes one by one BitstringWriter wr(tmp_code.data(), tmp_code.size()); for (size_t j = 0; j < rq.M; j++) { - int nbit = rq.nbits[j]; + int nbit = static_cast(rq.nbits[j]); wr.write(rd.read(nbit), nbit); } // we need to recompute the norm @@ -543,7 +544,9 @@ void ivf_residual_add_from_flat_codes( // ok index->rq.decode(tmp_code.data(), tmp.data(), 1); float norm = fvec_norm_L2sqr(tmp.data(), rq.d); - wr.write(rq.encode_norm(norm), rq.norm_bits); + wr.write( + rq.encode_norm(norm), + static_cast(rq.norm_bits)); // add code to the inverted list invlists.add_entry(list_no, i, tmp_code.data()); diff --git a/faiss/Index.cpp b/faiss/Index.cpp index 327cef890b..a9a8413b0d 100644 --- a/faiss/Index.cpp +++ b/faiss/Index.cpp @@ -55,7 +55,7 @@ void Index::add_with_ids( size_t Index::remove_ids(const IDSelector& /*sel*/) { FAISS_THROW_MSG("remove_ids not implemented for this type of index"); - return -1; + return static_cast(-1); } void Index::reconstruct(idx_t, float*) const { diff --git a/faiss/Index.h b/faiss/Index.h index 457cbabe6e..b30e0d2e48 100644 --- a/faiss/Index.h +++ b/faiss/Index.h @@ -90,6 +90,12 @@ struct SearchParameters { IDSelector* sel = nullptr; /// make sure we can dynamic_cast this virtual ~SearchParameters() {} + // rule of five defaults + SearchParameters() = default; + SearchParameters(const SearchParameters&) = default; + SearchParameters& operator=(const SearchParameters&) = default; + SearchParameters(SearchParameters&&) = default; + SearchParameters& operator=(SearchParameters&&) = default; }; /** Abstract structure for an index, supports adding vectors and searching @@ -115,7 +121,7 @@ struct Index { float metric_arg; ///< argument of the metric type explicit Index(idx_t d_in = 0, MetricType metric = METRIC_L2) - : d(d_in), + : d(static_cast(d_in)), ntotal(0), verbose(false), is_trained(true), @@ -123,6 +129,11 @@ struct Index { metric_arg(0) {} virtual ~Index(); + // rule of five defaults + Index(const Index&) = default; + Index& operator=(const Index&) = default; + Index(Index&&) = default; + Index& operator=(Index&&) = default; /** Perform training on a representative set of vectors * diff --git a/faiss/Index2Layer.cpp b/faiss/Index2Layer.cpp index 33d855f7f0..d0d6c118b8 100644 --- a/faiss/Index2Layer.cpp +++ b/faiss/Index2Layer.cpp @@ -168,7 +168,7 @@ struct DistanceXPQ4 : Distance2Level { dynamic_cast(storage.q1.quantizer); FAISS_ASSERT(quantizer); - M = storage.pq.M; + M = static_cast(storage.pq.M); pq_l1_tab = quantizer->get_xb(); } @@ -207,8 +207,8 @@ struct Distance2xXPQ4 : Distance2Level { FAISS_ASSERT(mi); FAISS_ASSERT(storage.pq.M % 2 == 0); - M_2 = storage.pq.M / 2; - mi_nbits = mi->pq.nbits; + M_2 = static_cast(storage.pq.M / 2); + mi_nbits = static_cast(mi->pq.nbits); pq_l1_tab = mi->pq.centroids.data(); } @@ -266,7 +266,8 @@ DistanceComputer* Index2Layer::get_distance_computer() const { /* The standalone codec interface */ // block size used in Index2Layer::sa_encode -int index2layer_sa_encode_bs = 32768; +int index2layer_sa_encode_bs = + 32768; // NOLINT(facebook-avoid-non-const-global-variables) void Index2Layer::sa_encode(idx_t n, const float* x, uint8_t* bytes) const { FAISS_THROW_IF_NOT(is_trained); diff --git a/faiss/Index2Layer.h b/faiss/Index2Layer.h index 9a20ba08f4..dd6c142828 100644 --- a/faiss/Index2Layer.h +++ b/faiss/Index2Layer.h @@ -48,6 +48,11 @@ struct Index2Layer : IndexFlatCodes { Index2Layer(); ~Index2Layer() override; + // rule of five defaults + Index2Layer(const Index2Layer&) = default; + Index2Layer& operator=(const Index2Layer&) = default; + Index2Layer(Index2Layer&&) = default; + Index2Layer& operator=(Index2Layer&&) = default; void train(idx_t n, const float* x) override; @@ -71,6 +76,7 @@ struct Index2Layer : IndexFlatCodes { }; // block size used in Index2Layer::sa_encode -FAISS_API extern int index2layer_sa_encode_bs; +FAISS_API extern int + index2layer_sa_encode_bs; // NOLINT(facebook-avoid-non-const-global-variables) } // namespace faiss diff --git a/faiss/IndexAdditiveQuantizer.cpp b/faiss/IndexAdditiveQuantizer.cpp index 14d717c0cb..020fe79d1b 100644 --- a/faiss/IndexAdditiveQuantizer.cpp +++ b/faiss/IndexAdditiveQuantizer.cpp @@ -47,7 +47,7 @@ struct AQDistanceComputerDecompress : FlatCodesDistanceComputer { const IndexAdditiveQuantizer& iaq, VectorDistance vd_) : FlatCodesDistanceComputer(iaq.codes.data(), iaq.code_size), - tmp(iaq.d * 2), + tmp(static_cast(iaq.d) * 2), aq(*iaq.aq), vd(vd_), d(iaq.d) {} @@ -79,7 +79,7 @@ struct AQDistanceComputerLUT : FlatCodesDistanceComputer { explicit AQDistanceComputerLUT(const IndexAdditiveQuantizer& iaq) : FlatCodesDistanceComputer(iaq.codes.data(), iaq.code_size), - LUT(iaq.aq->total_codebook_size + iaq.d * 2), + LUT(iaq.aq->total_codebook_size + static_cast(iaq.d) * 2), aq(*iaq.aq), d(iaq.d) {} @@ -219,6 +219,9 @@ FlatCodesDistanceComputer* IndexAdditiveQuantizer:: false, AdditiveQuantizer::ST_norm_cqint8>(*this); #undef DISPATCH + case AdditiveQuantizer::ST_decompress: + case AdditiveQuantizer::ST_norm_from_LUT: + case AdditiveQuantizer::ST_count: default: FAISS_THROW_FMT( "search type %d not supported", aq->search_type); @@ -276,6 +279,8 @@ void IndexAdditiveQuantizer::search( *this, x, rh); break; #undef DISPATCH + case AdditiveQuantizer::ST_decompress: + case AdditiveQuantizer::ST_count: default: FAISS_THROW_FMT( "search type %d not supported", aq->search_type); @@ -543,7 +548,7 @@ void ResidualCoarseQuantizer::search( int beam_size = int(k * actual_beam_factor); if (beam_size > ntotal) { - beam_size = ntotal; + beam_size = static_cast(ntotal); } size_t memory_per_point = rq.memory_per_point(beam_size); diff --git a/faiss/IndexAdditiveQuantizer.h b/faiss/IndexAdditiveQuantizer.h index 04954e7b7d..c8c795de36 100644 --- a/faiss/IndexAdditiveQuantizer.h +++ b/faiss/IndexAdditiveQuantizer.h @@ -191,6 +191,16 @@ struct AdditiveCoarseQuantizer : Index { struct SearchParametersResidualCoarseQuantizer : SearchParameters { float beam_factor = 4.0f; ~SearchParametersResidualCoarseQuantizer() {} + // rule of five defaults + SearchParametersResidualCoarseQuantizer() = default; + SearchParametersResidualCoarseQuantizer( + const SearchParametersResidualCoarseQuantizer&) = default; + SearchParametersResidualCoarseQuantizer& operator=( + const SearchParametersResidualCoarseQuantizer&) = default; + SearchParametersResidualCoarseQuantizer( + SearchParametersResidualCoarseQuantizer&&) = default; + SearchParametersResidualCoarseQuantizer& operator=( + SearchParametersResidualCoarseQuantizer&&) = default; }; /** The ResidualCoarseQuantizer is a bit specialized compared to the diff --git a/faiss/IndexAdditiveQuantizerFastScan.cpp b/faiss/IndexAdditiveQuantizerFastScan.cpp index 9e4f67ba2f..4ed9f6441d 100644 --- a/faiss/IndexAdditiveQuantizerFastScan.cpp +++ b/faiss/IndexAdditiveQuantizerFastScan.cpp @@ -56,7 +56,7 @@ void IndexAdditiveQuantizerFastScan::init( } else { M = aq_init->M; } - init_fastscan(aq_init->d, M, 4, metric, bbs_); + init_fastscan(static_cast(aq_init->d), M, 4, metric, bbs_); max_train_points = 1024 * ksub * M; } diff --git a/faiss/IndexAdditiveQuantizerFastScan.h b/faiss/IndexAdditiveQuantizerFastScan.h index d1fda0b2d8..d530441bda 100644 --- a/faiss/IndexAdditiveQuantizerFastScan.h +++ b/faiss/IndexAdditiveQuantizerFastScan.h @@ -50,6 +50,14 @@ struct IndexAdditiveQuantizerFastScan : IndexFastScan { IndexAdditiveQuantizerFastScan(); ~IndexAdditiveQuantizerFastScan() override; + // rule of five defaults + IndexAdditiveQuantizerFastScan(const IndexAdditiveQuantizerFastScan&) = + default; + IndexAdditiveQuantizerFastScan& operator=( + const IndexAdditiveQuantizerFastScan&) = default; + IndexAdditiveQuantizerFastScan(IndexAdditiveQuantizerFastScan&&) = default; + IndexAdditiveQuantizerFastScan& operator=( + IndexAdditiveQuantizerFastScan&&) = default; /// build from an existing IndexAQ explicit IndexAdditiveQuantizerFastScan( diff --git a/faiss/IndexBinary.cpp b/faiss/IndexBinary.cpp index 45a28b8eaa..9962e94104 100644 --- a/faiss/IndexBinary.cpp +++ b/faiss/IndexBinary.cpp @@ -17,7 +17,9 @@ namespace faiss { IndexBinary::IndexBinary(idx_t d_, MetricType metric) - : d(d_), code_size(d_ / 8), metric_type(metric) { + : d(static_cast(d_)), + code_size(static_cast(d_ / 8)), + metric_type(metric) { FAISS_THROW_IF_NOT(d_ % 8 == 0); } diff --git a/faiss/IndexBinary.h b/faiss/IndexBinary.h index 2ce8117624..eee2286520 100644 --- a/faiss/IndexBinary.h +++ b/faiss/IndexBinary.h @@ -45,6 +45,11 @@ struct IndexBinary { explicit IndexBinary(idx_t d = 0, MetricType metric = METRIC_L2); virtual ~IndexBinary(); + // rule of five defaults + IndexBinary(const IndexBinary&) = default; + IndexBinary& operator=(const IndexBinary&) = default; + IndexBinary(IndexBinary&&) = default; + IndexBinary& operator=(IndexBinary&&) = default; /** Perform training on a representative set of vectors. * diff --git a/faiss/IndexBinaryFromFloat.h b/faiss/IndexBinaryFromFloat.h index 4636357b8a..af47a80666 100644 --- a/faiss/IndexBinaryFromFloat.h +++ b/faiss/IndexBinaryFromFloat.h @@ -33,6 +33,11 @@ struct IndexBinaryFromFloat : IndexBinary { explicit IndexBinaryFromFloat(Index* index); ~IndexBinaryFromFloat() override; + // rule of five defaults + IndexBinaryFromFloat(const IndexBinaryFromFloat&) = default; + IndexBinaryFromFloat& operator=(const IndexBinaryFromFloat&) = default; + IndexBinaryFromFloat(IndexBinaryFromFloat&&) = default; + IndexBinaryFromFloat& operator=(IndexBinaryFromFloat&&) = default; void add(idx_t n, const uint8_t* x) override; diff --git a/faiss/IndexBinaryHNSW.cpp b/faiss/IndexBinaryHNSW.cpp index 890834074b..030d6e29b4 100644 --- a/faiss/IndexBinaryHNSW.cpp +++ b/faiss/IndexBinaryHNSW.cpp @@ -74,7 +74,8 @@ void hnsw_add_vertices( // build histogram for (size_t i = 0; i < n; i++) { - HNSW::storage_idx_t pt_id = i + n0; + HNSW::storage_idx_t pt_id = + static_cast(i + n0); int pt_level = hnsw.levels[pt_id] - 1; while (pt_level >= static_cast(hist.size())) { hist.push_back(0); @@ -90,7 +91,8 @@ void hnsw_add_vertices( // bucket sort for (size_t i = 0; i < n; i++) { - HNSW::storage_idx_t pt_id = i + n0; + HNSW::storage_idx_t pt_id = + static_cast(i + n0); int pt_level = hnsw.levels[pt_id] - 1; order[offsets[pt_level]++] = pt_id; } @@ -99,7 +101,7 @@ void hnsw_add_vertices( { // perform add RandomGenerator rng2(789); - size_t i1 = n; + size_t i1 = static_cast(n); for (int pt_level = static_cast(hist.size()) - 1; pt_level >= int(!index_hnsw.init_level0); @@ -392,7 +394,7 @@ void IndexBinaryHNSWCagra::search( float distance = (*dis)(idx); if (distance < nearest_d[i]) { - nearest[i] = idx; + nearest[i] = static_cast(idx); nearest_d[i] = distance; } } diff --git a/faiss/IndexBinaryHNSW.h b/faiss/IndexBinaryHNSW.h index 9bca05a314..a52505b76c 100644 --- a/faiss/IndexBinaryHNSW.h +++ b/faiss/IndexBinaryHNSW.h @@ -45,6 +45,11 @@ struct IndexBinaryHNSW : IndexBinary { explicit IndexBinaryHNSW(IndexBinary* storage, int M = 32); ~IndexBinaryHNSW() override; + // rule of five defaults + IndexBinaryHNSW(const IndexBinaryHNSW&) = default; + IndexBinaryHNSW& operator=(const IndexBinaryHNSW&) = default; + IndexBinaryHNSW(IndexBinaryHNSW&&) = default; + IndexBinaryHNSW& operator=(IndexBinaryHNSW&&) = default; DistanceComputer* get_distance_computer() const; diff --git a/faiss/IndexBinaryHash.cpp b/faiss/IndexBinaryHash.cpp index dbd19586c5..fef56322e1 100644 --- a/faiss/IndexBinaryHash.cpp +++ b/faiss/IndexBinaryHash.cpp @@ -280,7 +280,8 @@ void IndexBinaryHashStats::reset() { memset((void*)this, 0, sizeof(*this)); } -IndexBinaryHashStats indexBinaryHash_stats; +IndexBinaryHashStats + indexBinaryHash_stats; // NOLINT(facebook-avoid-non-const-global-variables) /******************************************************* * IndexBinaryMultiHash implementation @@ -346,7 +347,7 @@ static void verify_shortlist( struct Run_verify_shortlist { using T = void; template - void f(Types... args) { + void f(Types... args) { // NOLINT(performance-unnecessary-value-param) verify_shortlist(args...); } }; diff --git a/faiss/IndexBinaryHash.h b/faiss/IndexBinaryHash.h index 32a8c4cad7..e203c3cb69 100644 --- a/faiss/IndexBinaryHash.h +++ b/faiss/IndexBinaryHash.h @@ -77,7 +77,8 @@ struct IndexBinaryHashStats { void reset(); }; -FAISS_API extern IndexBinaryHashStats indexBinaryHash_stats; +FAISS_API extern IndexBinaryHashStats + indexBinaryHash_stats; // NOLINT(facebook-avoid-non-const-global-variables) /** just uses the b first bits as a hash value */ struct IndexBinaryMultiHash : IndexBinary { @@ -100,6 +101,11 @@ struct IndexBinaryMultiHash : IndexBinary { IndexBinaryMultiHash(); ~IndexBinaryMultiHash() override; + // rule of five defaults + IndexBinaryMultiHash(const IndexBinaryMultiHash&) = default; + IndexBinaryMultiHash& operator=(const IndexBinaryMultiHash&) = default; + IndexBinaryMultiHash(IndexBinaryMultiHash&&) = default; + IndexBinaryMultiHash& operator=(IndexBinaryMultiHash&&) = default; void reset() override; diff --git a/faiss/IndexBinaryIVF.cpp b/faiss/IndexBinaryIVF.cpp index 6de40b41ab..93c304b1da 100644 --- a/faiss/IndexBinaryIVF.cpp +++ b/faiss/IndexBinaryIVF.cpp @@ -151,7 +151,7 @@ void IndexBinaryIVF::search( indexIVF_stats.quantization_time += getmillisecs() - t0; t0 = getmillisecs(); - invlists->prefetch_lists(idx.get(), n * nprobe_); + invlists->prefetch_lists(idx.get(), static_cast(n * nprobe_)); search_preassigned( n, @@ -209,7 +209,7 @@ void IndexBinaryIVF::search_and_reconstruct( quantizer->search(n, x, nprobe_2, coarse_dis.get(), idx.get()); - invlists->prefetch_lists(idx.get(), n * nprobe_2); + invlists->prefetch_lists(idx.get(), static_cast(n * nprobe_2)); // search_preassigned() with `store_pairs` enabled to obtain the list_no // and offset into `codes` for reconstruction @@ -277,7 +277,7 @@ void IndexBinaryIVF::train(idx_t n, const uint8_t* x) { printf("Training quantizer on %" PRId64 " vectors in %dD\n", n, d); } - Clustering clus(d, nlist, cp); + Clustering clus(d, static_cast(nlist), cp); quantizer->reset(); IndexFlatL2 index_tmp(d); @@ -526,6 +526,7 @@ void search_knn_hamming_count( idx_t max_codes = params ? params->max_codes : ivf->max_codes; std::vector> cs; + cs.reserve(nx); for (size_t i = 0; i < nx; ++i) { cs.push_back( HCounterState( @@ -705,9 +706,10 @@ void search_knn_hamming_per_invlist( int32_t* keys = new int32_t[n * nprobe]; std::unique_ptr delete_keys(keys); for (size_t i = 0; i < n * static_cast(nprobe); i++) { - keys[i] = keys_in[i]; + keys[i] = static_cast(keys_in[i]); } - matrix_bucket_sort_inplace(n, nprobe, keys, ivf->nlist, lims.data(), 0); + matrix_bucket_sort_inplace( + n, nprobe, keys, static_cast(ivf->nlist), lims.data(), 0); using C = CMax; heap_heapify(n * k, distances, labels); @@ -754,7 +756,12 @@ void search_knn_hamming_per_invlist( } else { for (; i + BS <= nq; i += BS) { BlockSearchVariableK bc( - code_size, k, x, keys + l0 + i, distances, labels); + code_size, + static_cast(k), + x, + keys + l0 + i, + distances, + labels); for (idx_t j = 0; j < nb; j++) { bc.add_bcode(bcodes + j * code_size, ids[j]); } @@ -764,7 +771,8 @@ void search_knn_hamming_per_invlist( // leftovers for (; i < nq; i++) { idx_t qno = keys[l0 + i]; - HammingComputer hc(x + qno * code_size, code_size); + HammingComputer hc( + x + qno * code_size, static_cast(code_size)); idx_t* __restrict idxi = labels + qno * k; int32_t* __restrict simi = distances + qno * k; int32_t simi0 = simi[0]; @@ -868,7 +876,7 @@ void IndexBinaryIVF::range_search( indexIVF_stats.quantization_time += getmillisecs() - t0; t0 = getmillisecs(); - invlists->prefetch_lists(idx.get(), n * nprobe_2); + invlists->prefetch_lists(idx.get(), static_cast(n * nprobe_2)); range_search_preassigned(n, x, radius, idx.get(), coarse_dis.get(), res); diff --git a/faiss/IndexBinaryIVF.h b/faiss/IndexBinaryIVF.h index afe180a1fa..cfcdb66649 100644 --- a/faiss/IndexBinaryIVF.h +++ b/faiss/IndexBinaryIVF.h @@ -77,6 +77,11 @@ struct IndexBinaryIVF : IndexBinary { IndexBinaryIVF(); ~IndexBinaryIVF() override; + // rule of five defaults + IndexBinaryIVF(const IndexBinaryIVF&) = default; + IndexBinaryIVF& operator=(const IndexBinaryIVF&) = default; + IndexBinaryIVF(IndexBinaryIVF&&) = default; + IndexBinaryIVF& operator=(IndexBinaryIVF&&) = default; void reset() override; @@ -257,6 +262,13 @@ struct BinaryInvertedListScanner { RangeQueryResult& result) const = 0; virtual ~BinaryInvertedListScanner() {} + // rule of five defaults + BinaryInvertedListScanner() = default; + BinaryInvertedListScanner(const BinaryInvertedListScanner&) = default; + BinaryInvertedListScanner& operator=(const BinaryInvertedListScanner&) = + default; + BinaryInvertedListScanner(BinaryInvertedListScanner&&) = default; + BinaryInvertedListScanner& operator=(BinaryInvertedListScanner&&) = default; }; } // namespace faiss diff --git a/faiss/IndexFastScan.cpp b/faiss/IndexFastScan.cpp index 1dc93f05fe..c3c99005a1 100644 --- a/faiss/IndexFastScan.cpp +++ b/faiss/IndexFastScan.cpp @@ -187,14 +187,14 @@ void estimators_from_tables_generic( int nscale = context.pq2x4_scale ? 2 : 0; for (size_t m = 0; m < index.M - nscale; m++) { - uint64_t c = bsr.read(index.nbits); + uint64_t c = bsr.read(static_cast(index.nbits)); dis += dt[c]; dt += index.ksub; } if (nscale) { for (size_t m = 0; m < nscale; m++) { - uint64_t c = bsr.read(index.nbits); + uint64_t c = bsr.read(static_cast(index.nbits)); dis += dt[c] * context.pq2x4_scale; dt += index.ksub; } @@ -487,8 +487,8 @@ void IndexFastScan::search_implem_12( qbs_ = pq4_preferred_qbs(static_cast(n)); } - int LUT_nq = - pq4_pack_LUT_qbs(qbs_, M2, quantized_dis_tables.get(), LUT.get()); + int LUT_nq = pq4_pack_LUT_qbs( + qbs_, static_cast(M2), quantized_dis_tables.get(), LUT.get()); FAISS_THROW_IF_NOT(LUT_nq == n); auto scanner = make_knn_scanner( @@ -504,7 +504,7 @@ void IndexFastScan::search_implem_12( qbs_, ntotal2, - M2, + static_cast(M2), codes.get(), LUT.get(), context.pq2x4_scale, @@ -515,7 +515,8 @@ void IndexFastScan::search_implem_12( } } -FastScanStats FastScan_stats; +FastScanStats + FastScan_stats; // NOLINT(facebook-avoid-non-const-global-variables) template void IndexFastScan::search_implem_14( @@ -570,7 +571,11 @@ void IndexFastScan::search_implem_14( } AlignedTable LUT(n * dim12); - pq4_pack_LUT(n, M2, quantized_dis_tables.get(), LUT.get()); + pq4_pack_LUT( + static_cast(n), + static_cast(M2), + quantized_dis_tables.get(), + LUT.get()); auto scanner = make_knn_scanner( C::is_max, n, k, ntotal, distances, labels, nullptr, impl, context); @@ -582,10 +587,10 @@ void IndexFastScan::search_implem_14( // accessible through the SIMDResultHandlerToFloat* interface. if (!(skip & (2 | 4))) { scanner->accumulate_loop( - n, + static_cast(n), ntotal2, bbs, - M2, + static_cast(M2), codes.get(), LUT.get(), context.pq2x4_scale, diff --git a/faiss/IndexFastScan.h b/faiss/IndexFastScan.h index 8f73e43224..4e684f05e5 100644 --- a/faiss/IndexFastScan.h +++ b/faiss/IndexFastScan.h @@ -256,10 +256,11 @@ struct FastScanStats { reset(); } void reset() { - memset(this, 0, sizeof(*this)); + t0 = t1 = t2 = t3 = 0; } }; -FAISS_API extern FastScanStats FastScan_stats; +FAISS_API extern FastScanStats + FastScan_stats; // NOLINT(facebook-avoid-non-const-global-variables) } // namespace faiss diff --git a/faiss/IndexFlat.cpp b/faiss/IndexFlat.cpp index 5aa78b9a24..bf240d0cc6 100644 --- a/faiss/IndexFlat.cpp +++ b/faiss/IndexFlat.cpp @@ -68,7 +68,7 @@ void IndexFlat::range_search( FAISS_THROW_IF_NOT_MSG(result, "RangeSearchResult object must not be null"); IDSelector* sel = params ? params->sel : nullptr; - switch (metric_type) { + switch (metric_type) { // NOLINT(clang-diagnostic-switch-enum) case METRIC_INNER_PRODUCT: range_search_inner_product( x, get_xb(), d, n, ntotal, radius, result, sel); @@ -88,7 +88,7 @@ void IndexFlat::compute_distance_subset( float* distances, const idx_t* labels) const { FAISS_THROW_IF_NOT(k > 0); - switch (metric_type) { + switch (metric_type) { // NOLINT(clang-diagnostic-switch-enum) case METRIC_INNER_PRODUCT: fvec_inner_products_by_idx(distances, x, get_xb(), labels, d, n, k); break; diff --git a/faiss/IndexHNSW.cpp b/faiss/IndexHNSW.cpp index 3d4cf5d4f3..bc0b08bf87 100644 --- a/faiss/IndexHNSW.cpp +++ b/faiss/IndexHNSW.cpp @@ -36,7 +36,7 @@ namespace faiss { using storage_idx_t = HNSW::storage_idx_t; using NodeDistFarther = HNSW::NodeDistFarther; -HNSWStats hnsw_stats; +HNSWStats hnsw_stats; // NOLINT(facebook-avoid-non-const-global-variables) /************************************************************** * add / search blocks of descriptors @@ -94,7 +94,7 @@ void hnsw_add_vertices( // build histogram for (size_t i = 0; i < n; i++) { - storage_idx_t pt_id = i + n0; + storage_idx_t pt_id = static_cast(i + n0); int pt_level = hnsw.levels[pt_id] - 1; while (pt_level >= static_cast(hist.size())) { hist.push_back(0); @@ -110,7 +110,7 @@ void hnsw_add_vertices( // bucket sort for (size_t i = 0; i < n; i++) { - storage_idx_t pt_id = i + n0; + storage_idx_t pt_id = static_cast(i + n0); int pt_level = hnsw.levels[pt_id] - 1; order[offsets[pt_level]++] = pt_id; } @@ -122,7 +122,7 @@ void hnsw_add_vertices( { // perform add RandomGenerator rng2(789); - size_t i1 = n; + size_t i1 = static_cast(n); for (int pt_level = static_cast(hist.size()) - 1; pt_level >= int(!index_hnsw.init_level0); @@ -437,7 +437,7 @@ void IndexHNSW::search_level_0( FAISS_THROW_IF_NOT(k > 0); FAISS_THROW_IF_NOT(nprobe > 0); - storage_idx_t hnsw_ntotal = hnsw.levels.size(); + size_t hnsw_ntotal = hnsw.levels.size(); using RH = HeapBlockResultHandler; RH bres(n, distances, labels, k); @@ -498,7 +498,7 @@ void IndexHNSW::init_level_0_from_knngraph( std::priority_queue initial_list; for (int j = 0; j < k; j++) { - int v1 = I[i * k + j]; + int v1 = static_cast(I[i * k + j]); if (v1 == i) { continue; } @@ -866,7 +866,7 @@ void IndexHNSW2Level::search( const IndexIVFPQ* index_ivfpq = dynamic_cast(storage); - int nprobe = index_ivfpq->nprobe; + size_t nprobe = index_ivfpq->nprobe; std::unique_ptr coarse_assign(new idx_t[n * nprobe]); std::unique_ptr coarse_dis(new float[n * nprobe]); @@ -902,7 +902,7 @@ void IndexHNSW2Level::search( // mark all inverted list elements as visited - for (int j = 0; j < nprobe; j++) { + for (size_t j = 0; j < nprobe; j++) { idx_t key = coarse_assign[j + i * nprobe]; if (key < 0) { break; @@ -921,7 +921,8 @@ void IndexHNSW2Level::search( if (idxi[j] < 0) { break; } - candidates.push(idxi[j], simi[j]); + candidates.push( + static_cast(idxi[j]), simi[j]); } // reorder from sorted to heap @@ -931,14 +932,14 @@ void IndexHNSW2Level::search( search_from_candidates_2( hnsw, *dis, - k, + static_cast(k), idxi, simi, candidates, vt, search_stats, 0, - k); + static_cast(k)); n1 += search_stats.n1; n2 += search_stats.n2; ndis += search_stats.ndis; @@ -1061,7 +1062,7 @@ void IndexHNSWCagra::search( auto idx = distrib(gen); auto distance = (*dis)(idx); if (distance < nearest_d[i]) { - nearest[i] = idx; + nearest[i] = static_cast(idx); nearest_d[i] = distance; } } diff --git a/faiss/IndexHNSW.h b/faiss/IndexHNSW.h index c1eb9f268d..d99217ca45 100644 --- a/faiss/IndexHNSW.h +++ b/faiss/IndexHNSW.h @@ -56,6 +56,11 @@ struct IndexHNSW : Index { explicit IndexHNSW(Index* storage, int M = 32); ~IndexHNSW() override; + // rule of five defaults + IndexHNSW(const IndexHNSW&) = default; + IndexHNSW& operator=(const IndexHNSW&) = default; + IndexHNSW(IndexHNSW&&) = default; + IndexHNSW& operator=(IndexHNSW&&) = default; void add(idx_t n, const float* x) override; diff --git a/faiss/IndexIDMap.h b/faiss/IndexIDMap.h index 1e9897d8d4..5838a772b4 100644 --- a/faiss/IndexIDMap.h +++ b/faiss/IndexIDMap.h @@ -79,6 +79,12 @@ struct IndexIDMapTemplate : IndexT { void add_sa_codes(idx_t n, const uint8_t* x, const idx_t* xids) override; ~IndexIDMapTemplate() override; + // rule of five defaults + IndexIDMapTemplate(const IndexIDMapTemplate&) = default; + IndexIDMapTemplate& operator=(const IndexIDMapTemplate&) = default; + IndexIDMapTemplate(IndexIDMapTemplate&&) = default; + IndexIDMapTemplate& operator=(IndexIDMapTemplate&&) = default; + IndexIDMapTemplate() { own_fields = false; index = nullptr; @@ -120,6 +126,12 @@ struct IndexIDMap2Template : IndexIDMapTemplate { void merge_from(IndexT& otherIndex, idx_t add_id = 0) override; ~IndexIDMap2Template() override {} + // rule of five defaults + IndexIDMap2Template(const IndexIDMap2Template&) = default; + IndexIDMap2Template& operator=(const IndexIDMap2Template&) = default; + IndexIDMap2Template(IndexIDMap2Template&&) = default; + IndexIDMap2Template& operator=(IndexIDMap2Template&&) = default; + IndexIDMap2Template() {} }; diff --git a/faiss/IndexIVF.cpp b/faiss/IndexIVF.cpp index 3d1d251e89..2cd8ac24d7 100644 --- a/faiss/IndexIVF.cpp +++ b/faiss/IndexIVF.cpp @@ -17,7 +17,6 @@ #include #include -#include #include #include @@ -78,7 +77,7 @@ void Level1Quantizer::train_q1( printf("Training level-1 quantizer on %zd vectors in %zdD\n", n, d); } - Clustering clus(d, nlist, cp); + Clustering clus(static_cast(d), static_cast(nlist), cp); quantizer->reset(); if (clustering_index) { clus.train(n, x, *clustering_index); @@ -100,7 +99,7 @@ void Level1Quantizer::train_q1( metric_type == METRIC_L2 || (metric_type == METRIC_INNER_PRODUCT && cp.spherical)); - Clustering clus(d, nlist, cp); + Clustering clus(static_cast(d), static_cast(nlist), cp); if (!clustering_index) { IndexFlatL2 assigner(d); clus.train(n, x, assigner); @@ -339,7 +338,8 @@ void IndexIVF::search( params ? params->quantizer_params : nullptr); double t1 = getmillisecs(); - invlists->prefetch_lists(idx.get(), sub_n * cur_nprobe); + invlists->prefetch_lists( + idx.get(), static_cast(sub_n * cur_nprobe)); search_preassigned( sub_n, @@ -769,7 +769,7 @@ void IndexIVF::range_search( indexIVF_stats.quantization_time += getmillisecs() - t0; t0 = getmillisecs(); - invlists->prefetch_lists(keys.get(), nx * cur_nprobe); + invlists->prefetch_lists(keys.get(), static_cast(nx * cur_nprobe)); range_search_preassigned( nx, @@ -984,7 +984,7 @@ void IndexIVF::search1( indexIVF_stats.quantization_time += getmillisecs() - t0; t0 = getmillisecs(); - invlists->prefetch_lists(keys.get(), nx * cur_nprobe); + invlists->prefetch_lists(keys.get(), static_cast(nx * cur_nprobe)); std::unique_ptr scanner( get_InvertedListScanner(false, nullptr, params)); @@ -1101,7 +1101,7 @@ void IndexIVF::search_and_reconstruct( quantizer->search(n, x, cur_nprobe, coarse_dis.get(), idx.get()); - invlists->prefetch_lists(idx.get(), n * cur_nprobe); + invlists->prefetch_lists(idx.get(), static_cast(n * cur_nprobe)); // search_preassigned() with `store_pairs` enabled to obtain the list_no // and offset into `codes` for reconstruction @@ -1123,8 +1123,8 @@ void IndexIVF::search_and_reconstruct( // Fill with NaNs memset(reconstructed, -1, sizeof(*reconstructed) * d); } else { - int list_no = lo_listno(key); - int offset = lo_offset(key); + size_t list_no = lo_listno(key); + size_t offset = lo_offset(key); // Update label to the actual id labels[ij] = invlists->get_single_id(list_no, offset); @@ -1157,7 +1157,7 @@ void IndexIVF::search_and_return_codes( quantizer->search(n, x, cur_nprobe, coarse_dis.get(), idx.get()); - invlists->prefetch_lists(idx.get(), n * cur_nprobe); + invlists->prefetch_lists(idx.get(), static_cast(n * cur_nprobe)); // search_preassigned() with `store_pairs` enabled to obtain the list_no // and offset into `codes` for reconstruction @@ -1186,8 +1186,8 @@ void IndexIVF::search_and_return_codes( // Fill with 0xff memset(code1, -1, code_size_1); } else { - int list_no = lo_listno(key); - int offset = lo_offset(key); + size_t list_no = lo_listno(key); + size_t offset = lo_offset(key); const uint8_t* cc = invlists->get_single_code(list_no, offset); labels[ij] = invlists->get_single_id(list_no, offset); @@ -1296,7 +1296,8 @@ void IndexIVF::train_encoder( } } -bool check_compatible_for_merge_expensive_check = true; +bool check_compatible_for_merge_expensive_check = + true; // NOLINT(facebook-avoid-non-const-global-variables) void IndexIVF::check_compatible_for_merge(const Index& otherIndex) const { // minimal sanity checks @@ -1385,7 +1386,8 @@ void IndexIVFStats::add(const IndexIVFStats& other) { search_time += other.search_time; } -IndexIVFStats indexIVF_stats; +IndexIVFStats + indexIVF_stats; // NOLINT(facebook-avoid-non-const-global-variables) /************************************************************************* * InvertedListScanner diff --git a/faiss/IndexIVF.h b/faiss/IndexIVF.h index d3a4bb891b..944d22d679 100644 --- a/faiss/IndexIVF.h +++ b/faiss/IndexIVF.h @@ -63,6 +63,11 @@ struct Level1Quantizer { Level1Quantizer(); ~Level1Quantizer(); + // rule of five defaults + Level1Quantizer(const Level1Quantizer&) = default; + Level1Quantizer& operator=(const Level1Quantizer&) = default; + Level1Quantizer(Level1Quantizer&&) = default; + Level1Quantizer& operator=(Level1Quantizer&&) = default; }; struct SearchParametersIVF : SearchParameters { @@ -73,6 +78,12 @@ struct SearchParametersIVF : SearchParameters { void* inverted_list_context = nullptr; virtual ~SearchParametersIVF() {} + // rule of five defaults + SearchParametersIVF() = default; + SearchParametersIVF(const SearchParametersIVF&) = default; + SearchParametersIVF& operator=(const SearchParametersIVF&) = default; + SearchParametersIVF(SearchParametersIVF&&) = default; + SearchParametersIVF& operator=(SearchParametersIVF&&) = default; }; // the new convention puts the index type after SearchParameters @@ -150,6 +161,11 @@ struct IndexIVFInterface : Level1Quantizer { IndexIVFStats* stats = nullptr) const = 0; virtual ~IndexIVFInterface() {} + // rule of five defaults + IndexIVFInterface(const IndexIVFInterface&) = default; + IndexIVFInterface& operator=(const IndexIVFInterface&) = default; + IndexIVFInterface(IndexIVFInterface&&) = default; + IndexIVFInterface& operator=(IndexIVFInterface&&) = default; }; /** Index based on a inverted file (IVF) @@ -435,6 +451,11 @@ struct IndexIVF : Index, IndexIVFInterface { idx_t a2) const; ~IndexIVF() override; + // rule of five defaults + IndexIVF(const IndexIVF&) = default; + IndexIVF& operator=(const IndexIVF&) = default; + IndexIVF(IndexIVF&&) = default; + IndexIVF& operator=(IndexIVF&&) = default; size_t get_list_size(size_t list_no) const { return invlists->list_size(list_no); @@ -556,10 +577,16 @@ struct InvertedListScanner { ResultHandler& handler) const; virtual ~InvertedListScanner() {} + // rule of five defaults + InvertedListScanner(const InvertedListScanner&) = default; + InvertedListScanner& operator=(const InvertedListScanner&) = default; + InvertedListScanner(InvertedListScanner&&) = default; + InvertedListScanner& operator=(InvertedListScanner&&) = default; }; // whether to check that coarse quantizers are the same -FAISS_API extern bool check_compatible_for_merge_expensive_check; +FAISS_API extern bool + check_compatible_for_merge_expensive_check; // NOLINT(facebook-avoid-non-const-global-variables) struct IndexIVFStats { size_t nq; // nb of queries run @@ -577,7 +604,8 @@ struct IndexIVFStats { }; // global var that collects them all -FAISS_API extern IndexIVFStats indexIVF_stats; +FAISS_API extern IndexIVFStats + indexIVF_stats; // NOLINT(facebook-avoid-non-const-global-variables) } // namespace faiss diff --git a/faiss/IndexIVFAdditiveQuantizer.cpp b/faiss/IndexIVFAdditiveQuantizer.cpp index 24b63cf3c3..1f685efe81 100644 --- a/faiss/IndexIVFAdditiveQuantizer.cpp +++ b/faiss/IndexIVFAdditiveQuantizer.cpp @@ -312,6 +312,7 @@ InvertedListScanner* IndexIVFAdditiveQuantizer::get_InvertedListScanner( case AdditiveQuantizer::ST_norm_rq2x4: A(ST_norm_cqint8) #undef A + case AdditiveQuantizer::ST_count: default: FAISS_THROW_FMT( "search type %d not supported", aq->search_type); diff --git a/faiss/IndexIVFAdditiveQuantizer.h b/faiss/IndexIVFAdditiveQuantizer.h index dea7300afc..4665565451 100644 --- a/faiss/IndexIVFAdditiveQuantizer.h +++ b/faiss/IndexIVFAdditiveQuantizer.h @@ -68,6 +68,12 @@ struct IndexIVFAdditiveQuantizer : IndexIVF { const override; ~IndexIVFAdditiveQuantizer() override; + // rule of five defaults + IndexIVFAdditiveQuantizer(const IndexIVFAdditiveQuantizer&) = default; + IndexIVFAdditiveQuantizer& operator=(const IndexIVFAdditiveQuantizer&) = + default; + IndexIVFAdditiveQuantizer(IndexIVFAdditiveQuantizer&&) = default; + IndexIVFAdditiveQuantizer& operator=(IndexIVFAdditiveQuantizer&&) = default; }; /** IndexIVF based on a residual quantizer. Stored vectors are @@ -105,6 +111,12 @@ struct IndexIVFResidualQuantizer : IndexIVFAdditiveQuantizer { IndexIVFResidualQuantizer(); virtual ~IndexIVFResidualQuantizer(); + // rule of five defaults + IndexIVFResidualQuantizer(const IndexIVFResidualQuantizer&) = default; + IndexIVFResidualQuantizer& operator=(const IndexIVFResidualQuantizer&) = + default; + IndexIVFResidualQuantizer(IndexIVFResidualQuantizer&&) = default; + IndexIVFResidualQuantizer& operator=(IndexIVFResidualQuantizer&&) = default; }; /** IndexIVF based on a residual quantizer. Stored vectors are @@ -133,6 +145,13 @@ struct IndexIVFLocalSearchQuantizer : IndexIVFAdditiveQuantizer { IndexIVFLocalSearchQuantizer(); virtual ~IndexIVFLocalSearchQuantizer(); + // rule of five defaults + IndexIVFLocalSearchQuantizer(const IndexIVFLocalSearchQuantizer&) = default; + IndexIVFLocalSearchQuantizer& operator=( + const IndexIVFLocalSearchQuantizer&) = default; + IndexIVFLocalSearchQuantizer(IndexIVFLocalSearchQuantizer&&) = default; + IndexIVFLocalSearchQuantizer& operator=(IndexIVFLocalSearchQuantizer&&) = + default; }; /** IndexIVF based on a product residual quantizer. Stored vectors are @@ -163,6 +182,15 @@ struct IndexIVFProductResidualQuantizer : IndexIVFAdditiveQuantizer { IndexIVFProductResidualQuantizer(); virtual ~IndexIVFProductResidualQuantizer(); + // rule of five defaults + IndexIVFProductResidualQuantizer(const IndexIVFProductResidualQuantizer&) = + default; + IndexIVFProductResidualQuantizer& operator=( + const IndexIVFProductResidualQuantizer&) = default; + IndexIVFProductResidualQuantizer(IndexIVFProductResidualQuantizer&&) = + default; + IndexIVFProductResidualQuantizer& operator=( + IndexIVFProductResidualQuantizer&&) = default; }; /** IndexIVF based on a product local search quantizer. Stored vectors are @@ -193,6 +221,15 @@ struct IndexIVFProductLocalSearchQuantizer : IndexIVFAdditiveQuantizer { IndexIVFProductLocalSearchQuantizer(); virtual ~IndexIVFProductLocalSearchQuantizer(); + // rule of five defaults + IndexIVFProductLocalSearchQuantizer( + const IndexIVFProductLocalSearchQuantizer&) = default; + IndexIVFProductLocalSearchQuantizer& operator=( + const IndexIVFProductLocalSearchQuantizer&) = default; + IndexIVFProductLocalSearchQuantizer(IndexIVFProductLocalSearchQuantizer&&) = + default; + IndexIVFProductLocalSearchQuantizer& operator=( + IndexIVFProductLocalSearchQuantizer&&) = default; }; } // namespace faiss diff --git a/faiss/IndexIVFAdditiveQuantizerFastScan.h b/faiss/IndexIVFAdditiveQuantizerFastScan.h index eeb699b8a6..52dadb8030 100644 --- a/faiss/IndexIVFAdditiveQuantizerFastScan.h +++ b/faiss/IndexIVFAdditiveQuantizerFastScan.h @@ -64,6 +64,15 @@ struct IndexIVFAdditiveQuantizerFastScan : IndexIVFFastScan { IndexIVFAdditiveQuantizerFastScan(); ~IndexIVFAdditiveQuantizerFastScan() override; + // rule of five defaults + IndexIVFAdditiveQuantizerFastScan( + const IndexIVFAdditiveQuantizerFastScan&) = default; + IndexIVFAdditiveQuantizerFastScan& operator=( + const IndexIVFAdditiveQuantizerFastScan&) = default; + IndexIVFAdditiveQuantizerFastScan(IndexIVFAdditiveQuantizerFastScan&&) = + default; + IndexIVFAdditiveQuantizerFastScan& operator=( + IndexIVFAdditiveQuantizerFastScan&&) = default; // built from an IndexIVFAQ explicit IndexIVFAdditiveQuantizerFastScan( diff --git a/faiss/IndexIVFFastScan.cpp b/faiss/IndexIVFFastScan.cpp index 2962328c04..4a4663920b 100644 --- a/faiss/IndexIVFFastScan.cpp +++ b/faiss/IndexIVFFastScan.cpp @@ -254,14 +254,14 @@ void estimators_from_tables_generic( const dis_t* __restrict dt = dis_table; for (size_t m = 0; m < index.M - nscale; m++) { - uint64_t c = bsr.read(index.nbits); + uint64_t c = bsr.read(static_cast(index.nbits)); dis += dt[c]; dt += index.ksub; } if (nscale) { for (size_t m = 0; m < nscale; m++) { - uint64_t c = bsr.read(index.nbits); + uint64_t c = bsr.read(static_cast(index.nbits)); dis += dt[c] * context.pq2x4_scale; dt += index.ksub; } @@ -462,7 +462,7 @@ int compute_search_nslice( size_t cur_nprobe) { int nslice; if (n <= static_cast(omp_get_max_threads())) { - nslice = n; + nslice = static_cast(n); } else if (index->lookup_table_is_3d()) { // make sure we don't make too big LUT tables size_t lut_size_per_query = index->M * index->ksub * cur_nprobe * @@ -471,8 +471,8 @@ int compute_search_nslice( size_t max_lut_size = precomputed_table_max_bytes; // how many queries we can handle within mem budget size_t nq_ok = std::max(max_lut_size / lut_size_per_query, size_t(1)); - nslice = roundup( - std::max(size_t(n / nq_ok), size_t(1)), omp_get_max_threads()); + nslice = static_cast(roundup( + std::max(size_t(n / nq_ok), size_t(1)), omp_get_max_threads())); } else { // LUTs unlikely to be a limiting factor nslice = omp_get_max_threads(); @@ -552,7 +552,7 @@ void IndexIVFFastScan::search_dispatch_implem( // sliced over threads (then it is more efficient to have each thread do // its own coarse quantization) cq.quantize(quantizer, n, x, quantizer_params); - invlists->prefetch_lists(cq.ids, n * cq.nprobe); + invlists->prefetch_lists(cq.ids, static_cast(n * cq.nprobe)); } if (impl == 1) { @@ -717,7 +717,7 @@ void IndexIVFFastScan::range_search_dispatch_implem( if (!multiple_threads && !cq.done()) { cq.quantize(quantizer, n, x, quantizer_params); - invlists->prefetch_lists(cq.ids, n * cq.nprobe); + invlists->prefetch_lists(cq.ids, static_cast(n * cq.nprobe)); } size_t ndis = 0, nlist_visited = 0; @@ -990,7 +990,7 @@ void IndexIVFFastScan::search_implem_10( for (idx_t i = 0; i < n; i++) { const uint8_t* LUT = nullptr; - qmap1[0] = i; + qmap1[0] = static_cast(i); if (single_LUT) { LUT = dis_tables.get() + i * dim12; @@ -1028,7 +1028,7 @@ void IndexIVFFastScan::search_implem_10( 1, roundup(ls, bbs), bbs, - M2, + static_cast(M2), codes.get(), LUT, context.pq2x4_scale, @@ -1094,7 +1094,7 @@ void IndexIVFFastScan::search_implem_12( // prepare the result handlers - int actual_qbs2 = this->qbs2 ? this->qbs2 : 11; + int actual_qbs2 = static_cast(this->qbs2 ? this->qbs2 : 11); std::vector tmp_bias; if (biases.get()) { @@ -1131,7 +1131,7 @@ void IndexIVFFastScan::search_implem_12( nlist_visited++; // re-organize LUTs and biases into the right order - int nc = i1 - i0; + int nc = static_cast(i1 - i0); std::vector q_map(nc), lut_entries(nc); AlignedTable LUT(nc * dim12); @@ -1141,7 +1141,7 @@ void IndexIVFFastScan::search_implem_12( for (size_t i = i0; i < i1; i++) { const QC& qc = qcs[i]; q_map[i - i0] = qc.qno; - int ij = qc.qno * cur_nprobe + qc.rank; + int ij = static_cast(qc.qno * cur_nprobe + qc.rank); lut_entries[i - i0] = single_LUT ? qc.qno : ij; if (biases.get()) { tmp_bias[i - i0] = biases[ij]; @@ -1149,7 +1149,7 @@ void IndexIVFFastScan::search_implem_12( } pq4_pack_LUT_qbs_q_map( qbs_for_list, - M2, + static_cast(M2), dis_tables.get(), lut_entries.data(), LUT.get()); @@ -1180,7 +1180,7 @@ void IndexIVFFastScan::search_implem_12( scanner.accumulate_loop_qbs( qbs_for_list, list_size, - M2, + static_cast(M2), codes.get(), LUT.get(), context.pq2x4_scale, @@ -1328,7 +1328,7 @@ void IndexIVFFastScan::search_implem_14( SIMDResultHandlerToFloat* handler_ptr = scanner->handler(); handler_ptr->begin(normalizers.get()); - int actual_qbs2 = this->qbs2 ? this->qbs2 : 11; + int actual_qbs2 = static_cast(this->qbs2 ? this->qbs2 : 11); std::vector tmp_bias; if (biases.get()) { @@ -1353,7 +1353,7 @@ void IndexIVFFastScan::search_implem_14( int list_no = qcs[i0].list_no; // re-organize LUTs and biases into the right order - int nc = i1 - i0; + int nc = static_cast(i1 - i0); std::vector q_map(nc), lut_entries(nc); AlignedTable LUT(nc * dim12); @@ -1364,7 +1364,7 @@ void IndexIVFFastScan::search_implem_14( const QC& qc = qcs[i]; q_map[i - i0] = qc.qno; q_set.insert(qc.qno); - int ij = qc.qno * cur_nprobe + qc.rank; + int ij = static_cast(qc.qno * cur_nprobe + qc.rank); lut_entries[i - i0] = single_LUT ? qc.qno : ij; if (biases.get()) { tmp_bias[i - i0] = biases[ij]; @@ -1372,7 +1372,7 @@ void IndexIVFFastScan::search_implem_14( } pq4_pack_LUT_qbs_q_map( qbs_for_list, - M2, + static_cast(M2), dis_tables.get(), lut_entries.data(), LUT.get()); @@ -1403,7 +1403,7 @@ void IndexIVFFastScan::search_implem_14( scanner->accumulate_loop_qbs( qbs_for_list, list_size, - M2, + static_cast(M2), codes.get(), LUT.get(), context.pq2x4_scale, @@ -1465,7 +1465,7 @@ void IndexIVFFastScan::reconstruct_from_offset( for (size_t m = 0; m < M; m++) { uint8_t c = pq4_get_packed_element(list_codes.get(), bbs, M2, offset, m); - bsw.write(c, nbits); + bsw.write(c, static_cast(nbits)); } sa_decode(1, code.data(), recons); @@ -1488,7 +1488,7 @@ void IndexIVFFastScan::reconstruct_orig_invlists() { for (size_t m = 0; m < M; m++) { uint8_t c = pq4_get_packed_element(codes.get(), bbs, M2, offset, m); - bsw.write(c, nbits); + bsw.write(c, static_cast(nbits)); } // get id @@ -1529,6 +1529,7 @@ void IndexIVFFastScan::postprocess_packed_codes( size_t /*n_added*/, const uint8_t* /*flat_codes*/) {} -IVFFastScanStats IVFFastScan_stats; +IVFFastScanStats + IVFFastScan_stats; // NOLINT(facebook-avoid-non-const-global-variables) } // namespace faiss diff --git a/faiss/IndexIVFFastScan.h b/faiss/IndexIVFFastScan.h index fa76628521..78caa96363 100644 --- a/faiss/IndexIVFFastScan.h +++ b/faiss/IndexIVFFastScan.h @@ -104,6 +104,11 @@ struct IndexIVFFastScan : IndexIVF { void init_code_packer(); ~IndexIVFFastScan() override; + // rule of five defaults + IndexIVFFastScan(const IndexIVFFastScan&) = default; + IndexIVFFastScan& operator=(const IndexIVFFastScan&) = default; + IndexIVFFastScan(IndexIVFFastScan&&) = default; + IndexIVFFastScan& operator=(IndexIVFFastScan&&) = default; /// orig's inverted lists (for debugging) InvertedLists* orig_invlists = nullptr; @@ -424,10 +429,21 @@ struct IVFFastScanStats { reset(); } void reset() { - memset(this, 0, sizeof(*this)); + for (auto& t : times) + t = 0; + t_compute_distance_tables = 0; + t_round = 0; + t_copy_pack = 0; + t_scan = 0; + t_to_flat = 0; + for (auto& t : reservoir_times) + t = 0; + t_aq_encode = 0; + t_aq_norm_encode = 0; } }; -FAISS_API extern IVFFastScanStats IVFFastScan_stats; +FAISS_API extern IVFFastScanStats + IVFFastScan_stats; // NOLINT(facebook-avoid-non-const-global-variables) } // namespace faiss diff --git a/faiss/IndexIVFIndependentQuantizer.cpp b/faiss/IndexIVFIndependentQuantizer.cpp index 1b781af47f..ccfd22ce99 100644 --- a/faiss/IndexIVFIndependentQuantizer.cpp +++ b/faiss/IndexIVFIndependentQuantizer.cpp @@ -91,7 +91,7 @@ void IndexIVFIndependentQuantizer::search( idx_t* labels, const SearchParameters* params) const { FAISS_THROW_IF_NOT_MSG(!params, "search parameters not supported"); - int nprobe = index_ivf->nprobe; + size_t nprobe = index_ivf->nprobe; std::vector D(n * nprobe); std::vector I(n * nprobe); quantizer->search(n, x, nprobe, D.data(), I.data()); diff --git a/faiss/IndexIVFIndependentQuantizer.h b/faiss/IndexIVFIndependentQuantizer.h index ff3c63b8f7..8a0f9f0844 100644 --- a/faiss/IndexIVFIndependentQuantizer.h +++ b/faiss/IndexIVFIndependentQuantizer.h @@ -51,6 +51,13 @@ struct IndexIVFIndependentQuantizer : Index { void reset() override; ~IndexIVFIndependentQuantizer() override; + // rule of five defaults + IndexIVFIndependentQuantizer(const IndexIVFIndependentQuantizer&) = default; + IndexIVFIndependentQuantizer& operator=( + const IndexIVFIndependentQuantizer&) = default; + IndexIVFIndependentQuantizer(IndexIVFIndependentQuantizer&&) = default; + IndexIVFIndependentQuantizer& operator=(IndexIVFIndependentQuantizer&&) = + default; }; } // namespace faiss diff --git a/faiss/IndexIVFPQ.cpp b/faiss/IndexIVFPQ.cpp index 35268f9282..eda0594975 100644 --- a/faiss/IndexIVFPQ.cpp +++ b/faiss/IndexIVFPQ.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include // NOLINT(facebook-hte-InlineHeader) #include namespace faiss { @@ -222,7 +222,8 @@ void IndexIVFPQ::sa_decode(idx_t n, const uint8_t* codes, float* x) const { } // block size used in IndexIVFPQ::add_core_o -int index_ivfpq_add_core_o_bs = 32768; +int index_ivfpq_add_core_o_bs = + 32768; // NOLINT(facebook-avoid-non-const-global-variables) void IndexIVFPQ::add_core_o( idx_t n, @@ -349,7 +350,8 @@ void IndexIVFPQ::reconstruct_from_offset( } /// 2G by default, accommodates tables up to PQ32 w/ 65536 centroids -size_t precomputed_table_max_bytes = ((size_t)1) << 31; +size_t precomputed_table_max_bytes = ((size_t)1) + << 31; // NOLINT(facebook-avoid-non-const-global-variables) /** Precomputed tables for residuals * @@ -691,7 +693,7 @@ struct QueryTables { dynamic_cast(ivfpq.quantizer); FAISS_THROW_IF_NOT(miq); const ProductQuantizer& cpq = miq->pq; - int Mf = pq.M / cpq.M; + size_t Mf = pq.M / cpq.M; const float* qtab = sim_table_2; // query-specific table float* ltab = sim_table; // (output) list-specific table @@ -699,7 +701,7 @@ struct QueryTables { long k = key; for (size_t cm = 0; cm < cpq.M; cm++) { // compute PQ index - int ki = k & ((uint64_t(1) << cpq.nbits) - 1); + size_t ki = k & ((uint64_t(1) << cpq.nbits) - 1); k >>= cpq.nbits; // get corresponding table @@ -745,18 +747,18 @@ struct QueryTables { dynamic_cast(ivfpq.quantizer); FAISS_THROW_IF_NOT(miq); const ProductQuantizer& cpq = miq->pq; - int Mf = pq.M / cpq.M; + size_t Mf = pq.M / cpq.M; long k = key; - int m0 = 0; + size_t m0 = 0; for (size_t cm = 0; cm < cpq.M; cm++) { - int ki = k & ((uint64_t(1) << cpq.nbits) - 1); + size_t ki = k & ((uint64_t(1) << cpq.nbits) - 1); k >>= cpq.nbits; const float* pc = ivfpq.precomputed_table.data() + (ki * pq.M + cm * Mf) * pq.ksub; - for (int m = m0; m < m0 + Mf; m++) { + for (size_t m = m0; m < m0 + Mf; m++) { sim_table_ptrs[m] = pc; pc += pq.ksub; } @@ -1055,7 +1057,7 @@ struct IVFPQScannerT : QueryTables { int ht = ivfpq.polysemous_ht; size_t n_hamming_pass = 0; - int code_size = pq.code_size; + int code_size = static_cast(pq.code_size); size_t saved_j[8]; int counter = 0; @@ -1308,10 +1310,14 @@ InvertedListScanner* IndexIVFPQ::get_InvertedListScanner( }); } -IndexIVFPQStats indexIVFPQ_stats; +IndexIVFPQStats + indexIVFPQ_stats; // NOLINT(facebook-avoid-non-const-global-variables) void IndexIVFPQStats::reset() { - memset(this, 0, sizeof(*this)); + nrefine = 0; + n_hamming_pass = 0; + search_cycles = 0; + refine_cycles = 0; } IndexIVFPQ::IndexIVFPQ() { diff --git a/faiss/IndexIVFPQ.h b/faiss/IndexIVFPQ.h index e0c83d8ba4..31365e5aa6 100644 --- a/faiss/IndexIVFPQ.h +++ b/faiss/IndexIVFPQ.h @@ -24,9 +24,15 @@ struct IVFPQSearchParameters : IVFSearchParameters { int polysemous_ht; ///< Hamming thresh for polysemous filtering IVFPQSearchParameters() : scan_table_threshold(0), polysemous_ht(0) {} ~IVFPQSearchParameters() {} + // rule of five defaults + IVFPQSearchParameters(const IVFPQSearchParameters&) = default; + IVFPQSearchParameters& operator=(const IVFPQSearchParameters&) = default; + IVFPQSearchParameters(IVFPQSearchParameters&&) = default; + IVFPQSearchParameters& operator=(IVFPQSearchParameters&&) = default; }; -FAISS_API extern size_t precomputed_table_max_bytes; +FAISS_API extern size_t + precomputed_table_max_bytes; // NOLINT(facebook-avoid-non-const-global-variables) /** Inverted file with Product Quantizer encoding. Each residual * vector is encoded as a product quantizer code. @@ -151,7 +157,8 @@ struct IndexIVFPQ : IndexIVF { }; // block size used in IndexIVFPQ::add_core_o -FAISS_API extern int index_ivfpq_add_core_o_bs; +FAISS_API extern int + index_ivfpq_add_core_o_bs; // NOLINT(facebook-avoid-non-const-global-variables) /** Pre-compute distance tables for IVFPQ with by-residual and METRIC_L2 * @@ -191,7 +198,8 @@ struct IndexIVFPQStats { }; // global var that collects them all -FAISS_API extern IndexIVFPQStats indexIVFPQ_stats; +FAISS_API extern IndexIVFPQStats + indexIVFPQ_stats; // NOLINT(facebook-avoid-non-const-global-variables) } // namespace faiss diff --git a/faiss/IndexIVFPQR.cpp b/faiss/IndexIVFPQR.cpp index e0fc34dd05..ba9e78a94b 100644 --- a/faiss/IndexIVFPQR.cpp +++ b/faiss/IndexIVFPQR.cpp @@ -173,8 +173,8 @@ void IndexIVFPQR::search_preassigned( continue; } - int list_no = lo_listno(sl); - int ofs = lo_offset(sl); + int list_no = static_cast(lo_listno(sl)); + int ofs = static_cast(lo_offset(sl)); FAISS_THROW_IF_NOT( list_no >= 0 && static_cast(list_no) < nlist); diff --git a/faiss/IndexIVFRaBitQ.cpp b/faiss/IndexIVFRaBitQ.cpp index d651f66c6c..08fd71a654 100644 --- a/faiss/IndexIVFRaBitQ.cpp +++ b/faiss/IndexIVFRaBitQ.cpp @@ -332,6 +332,8 @@ void IndexIVFRaBitQ::sa_decode(idx_t n, const uint8_t* codes, float* x) const { } } +namespace { + struct IVFRaBitDistanceComputer : DistanceComputer { const float* q = nullptr; const IndexIVFRaBitQ* parent = nullptr; @@ -379,6 +381,8 @@ float IVFRaBitDistanceComputer::symmetric_dis(idx_t /*i*/, idx_t /*j*/) { FAISS_THROW_MSG("Not implemented"); } +} // anonymous namespace + DistanceComputer* IndexIVFRaBitQ::get_distance_computer() const { IVFRaBitDistanceComputer* dc = new IVFRaBitDistanceComputer; dc->parent = this; diff --git a/faiss/IndexIVFSpectralHash.cpp b/faiss/IndexIVFSpectralHash.cpp index 523ef8afb3..6a396934c5 100644 --- a/faiss/IndexIVFSpectralHash.cpp +++ b/faiss/IndexIVFSpectralHash.cpp @@ -231,7 +231,7 @@ struct IVFScanner : InvertedListScanner { q(nbit), zero(nbit), qcode(index_in->code_size), - hc(qcode.data(), index_in->code_size) { + hc(qcode.data(), static_cast(index_in->code_size)) { this->store_pairs = store_pairs_in; this->code_size = index->code_size; this->keep_max = is_similarity_metric(index->metric_type); diff --git a/faiss/IndexIVFSpectralHash.h b/faiss/IndexIVFSpectralHash.h index fd1deb124d..be5e5445fe 100644 --- a/faiss/IndexIVFSpectralHash.h +++ b/faiss/IndexIVFSpectralHash.h @@ -84,6 +84,11 @@ struct IndexIVFSpectralHash : IndexIVF { void replace_vt(IndexPreTransform* index, bool own = false); ~IndexIVFSpectralHash() override; + // rule of five defaults + IndexIVFSpectralHash(const IndexIVFSpectralHash&) = default; + IndexIVFSpectralHash& operator=(const IndexIVFSpectralHash&) = default; + IndexIVFSpectralHash(IndexIVFSpectralHash&&) = default; + IndexIVFSpectralHash& operator=(IndexIVFSpectralHash&&) = default; }; } // namespace faiss diff --git a/faiss/IndexLSH.h b/faiss/IndexLSH.h index cc3bbcc8fe..897c0fd240 100644 --- a/faiss/IndexLSH.h +++ b/faiss/IndexLSH.h @@ -57,6 +57,11 @@ struct IndexLSH : IndexFlatCodes { void transfer_thresholds(LinearTransform* vt); ~IndexLSH() override {} + // rule of five defaults + IndexLSH(const IndexLSH&) = default; + IndexLSH& operator=(const IndexLSH&) = default; + IndexLSH(IndexLSH&&) = default; + IndexLSH& operator=(IndexLSH&&) = default; IndexLSH(); diff --git a/faiss/IndexLattice.cpp b/faiss/IndexLattice.cpp index 56f6ce6278..0768a1a153 100644 --- a/faiss/IndexLattice.cpp +++ b/faiss/IndexLattice.cpp @@ -19,7 +19,7 @@ IndexLattice::IndexLattice(idx_t d_in, int nsq_in, int scale_nbit_in, int r2) : IndexFlatCodes(0, d_in, METRIC_L2), nsq(nsq_in), dsq(d_in / nsq_in), - zn_sphere_codec(dsq, r2), + zn_sphere_codec(static_cast(dsq), r2), scale_nbit(scale_nbit_in) { FAISS_THROW_IF_NOT(d_in % nsq_in == 0); diff --git a/faiss/IndexNNDescent.cpp b/faiss/IndexNNDescent.cpp index 38d10be824..b005188970 100644 --- a/faiss/IndexNNDescent.cpp +++ b/faiss/IndexNNDescent.cpp @@ -20,7 +20,6 @@ #include #include #include -#include extern "C" { @@ -132,7 +131,7 @@ void IndexNNDescent::search( float* simi = distances + i * k; dis->set_query(x + i * d); - nndescent.search(*dis, k, idxi, simi, vt); + nndescent.search(*dis, static_cast(k), idxi, simi, vt); } } InterruptCallback::check(); @@ -163,7 +162,7 @@ void IndexNNDescent::add(idx_t n, const float* x) { ntotal = storage->ntotal; std::unique_ptr dis(storage_distance_computer(storage)); - nndescent.build(*dis, ntotal, verbose); + nndescent.build(*dis, static_cast(ntotal), verbose); } void IndexNNDescent::reset() { diff --git a/faiss/IndexNNDescent.h b/faiss/IndexNNDescent.h index beed90551b..d6e74a6f94 100644 --- a/faiss/IndexNNDescent.h +++ b/faiss/IndexNNDescent.h @@ -40,6 +40,11 @@ struct IndexNNDescent : Index { explicit IndexNNDescent(Index* storage, int K = 32); ~IndexNNDescent() override; + // rule of five defaults + IndexNNDescent(const IndexNNDescent&) = default; + IndexNNDescent& operator=(const IndexNNDescent&) = default; + IndexNNDescent(IndexNNDescent&&) = default; + IndexNNDescent& operator=(IndexNNDescent&&) = default; void add(idx_t n, const float* x) override; diff --git a/faiss/IndexNSG.cpp b/faiss/IndexNSG.cpp index f0c85f9ba9..7dd4f6621c 100644 --- a/faiss/IndexNSG.cpp +++ b/faiss/IndexNSG.cpp @@ -17,7 +17,6 @@ #include #include #include -#include namespace faiss { @@ -87,7 +86,7 @@ void IndexNSG::search( float* simi = distances + i * k; dis->set_query(x + i * d); - nsg.search(*dis, k, idxi, simi, vt); + nsg.search(*dis, static_cast(k), idxi, simi, vt); vt.advance(); } @@ -116,7 +115,7 @@ void IndexNSG::build(idx_t n, const float* x, idx_t* knn_graph, int gk) { // check the knn graph check_knn_graph(knn_graph, n, gk); - const nsg::Graph knng(knn_graph, n, gk); + const nsg::Graph knng(knn_graph, static_cast(n), gk); nsg.build(storage, n, knng, verbose); is_built = true; } @@ -224,7 +223,7 @@ void IndexNSG::add(idx_t n, const float* x) { printf(" nsg building\n"); } - const nsg::Graph knn_graph(knng.data(), n, GK); + const nsg::Graph knn_graph(knng.data(), static_cast(n), GK); nsg.build(storage, n, knn_graph, verbose); is_built = true; } diff --git a/faiss/IndexNSG.h b/faiss/IndexNSG.h index e54a223e0b..978482adb5 100644 --- a/faiss/IndexNSG.h +++ b/faiss/IndexNSG.h @@ -50,6 +50,11 @@ struct IndexNSG : Index { explicit IndexNSG(Index* storage, int R = 32); ~IndexNSG() override; + // rule of five defaults + IndexNSG(const IndexNSG&) = default; + IndexNSG& operator=(const IndexNSG&) = default; + IndexNSG(IndexNSG&&) = default; + IndexNSG& operator=(IndexNSG&&) = default; void build(idx_t n, const float* x, idx_t* knn_graph, int GK); diff --git a/faiss/IndexNeuralNetCodec.cpp b/faiss/IndexNeuralNetCodec.cpp index 3b1d84ebc9..710dcb1dcd 100644 --- a/faiss/IndexNeuralNetCodec.cpp +++ b/faiss/IndexNeuralNetCodec.cpp @@ -34,13 +34,25 @@ void IndexNeuralNetCodec::sa_encode(idx_t n, const float* x, uint8_t* bytes) const { nn::Tensor2D x_tensor(n, d, x); nn::Int32Tensor2D codes_tensor = net->encode(x_tensor); - pack_bitstrings(n, M, nbits, codes_tensor.data(), bytes, code_size); + pack_bitstrings( + n, + M, + static_cast(nbits), + codes_tensor.data(), + bytes, + code_size); } void IndexNeuralNetCodec::sa_decode(idx_t n, const uint8_t* bytes, float* x) const { nn::Int32Tensor2D codes_tensor(n, M); - unpack_bitstrings(n, M, nbits, bytes, code_size, codes_tensor.data()); + unpack_bitstrings( + n, + M, + static_cast(nbits), + bytes, + code_size, + codes_tensor.data()); nn::Tensor2D x_tensor = net->decode(codes_tensor); memcpy(x, x_tensor.data(), d * n * sizeof(float)); } diff --git a/faiss/IndexNeuralNetCodec.h b/faiss/IndexNeuralNetCodec.h index 520b87a6fd..d9ef3aecdf 100644 --- a/faiss/IndexNeuralNetCodec.h +++ b/faiss/IndexNeuralNetCodec.h @@ -30,6 +30,11 @@ struct IndexNeuralNetCodec : IndexFlatCodes { void sa_decode(idx_t n, const uint8_t* codes, float* x) const override; ~IndexNeuralNetCodec() override {} + // rule of five defaults + IndexNeuralNetCodec(const IndexNeuralNetCodec&) = default; + IndexNeuralNetCodec& operator=(const IndexNeuralNetCodec&) = default; + IndexNeuralNetCodec(IndexNeuralNetCodec&&) = default; + IndexNeuralNetCodec& operator=(IndexNeuralNetCodec&&) = default; }; struct IndexQINCo : IndexNeuralNetCodec { @@ -44,6 +49,11 @@ struct IndexQINCo : IndexNeuralNetCodec { MetricType metric = METRIC_L2); ~IndexQINCo() {} + // rule of five defaults + IndexQINCo(const IndexQINCo&) = default; + IndexQINCo& operator=(const IndexQINCo&) = default; + IndexQINCo(IndexQINCo&&) = default; + IndexQINCo& operator=(IndexQINCo&&) = default; }; } // namespace faiss diff --git a/faiss/IndexPQ.cpp b/faiss/IndexPQ.cpp index 521807eb1f..ce6b832dee 100644 --- a/faiss/IndexPQ.cpp +++ b/faiss/IndexPQ.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include // NOLINT(facebook-hte-InlineHeader) #include namespace faiss { @@ -32,7 +32,7 @@ IndexPQ::IndexPQ(int d_in, size_t M, size_t nbits, MetricType metric) : IndexFlatCodes(0, d_in, metric), pq(d_in, M, nbits) { is_trained = false; do_polysemous_training = false; - polysemous_ht = nbits * M + 1; + polysemous_ht = static_cast(nbits * M) + 1; search_type = ST_PQ; encode_signs = false; code_size = pq.code_size; @@ -42,7 +42,7 @@ IndexPQ::IndexPQ() { metric_type = METRIC_L2; is_trained = false; do_polysemous_training = false; - polysemous_ht = pq.nbits * pq.M + 1; + polysemous_ht = static_cast(pq.nbits * pq.M) + 1; search_type = ST_PQ; encode_signs = false; } @@ -277,7 +277,7 @@ void IndexPQStats::reset() { nq = ncode = n_hamming_pass = 0; } -IndexPQStats indexPQ_stats; +IndexPQStats indexPQ_stats; // NOLINT(facebook-avoid-non-const-global-variables) namespace { @@ -299,7 +299,7 @@ size_t polysemous_inner_loop( size_t n_pass_i = 0; - HammingComputer hc(q_code, code_size); + HammingComputer hc(q_code, static_cast(code_size)); for (int64_t bi = 0; bi < static_cast(ntotal); bi++) { int hd = hc.hamming(b_code); @@ -345,7 +345,7 @@ void IndexPQ::search_core_polysemous( FAISS_THROW_IF_NOT(pq.nbits == 8); if (param_polysemous_ht == 0) { - param_polysemous_ht = pq.nbits * pq.M + 1; + param_polysemous_ht = static_cast(pq.nbits * pq.M) + 1; } // PQ distance tables @@ -383,7 +383,7 @@ void IndexPQ::search_core_polysemous( if (!generalized_hamming) { Run_polysemous_inner_loop r; n_pass += dispatch_HammingComputer( - pq.code_size, + static_cast(pq.code_size), r, this, dis_table_qi, @@ -487,7 +487,7 @@ void IndexPQ::hamming_distance_histogram( nb = ntotal; b_codes = codes.data(); } - int nbits = pq.M * pq.nbits; + int nbits = static_cast(pq.M * pq.nbits); memset(hist, 0, sizeof(*hist) * (nbits + 1)); size_t bs = 256; @@ -906,7 +906,8 @@ void MultiIndexQuantizer::train(idx_t n, const float* x) { } // block size used in MultiIndexQuantizer::search -int multi_index_quantizer_search_bs = 32768; +int multi_index_quantizer_search_bs = + 32768; // NOLINT(facebook-avoid-non-const-global-variables) void MultiIndexQuantizer::search( idx_t n, @@ -947,7 +948,7 @@ void MultiIndexQuantizer::search( // simple version that just finds the min in each table #pragma omp parallel for - for (int i = 0; i < n; i++) { + for (idx_t i = 0; i < n; i++) { const float* dis_table = dis_tables.get() + i * pq.ksub * pq.M; float dis = 0; idx_t label = 0; @@ -975,9 +976,12 @@ void MultiIndexQuantizer::search( #pragma omp parallel if (n > 1) { MinSumK, false> msk( - k, pq.M, pq.nbits, pq.ksub); + static_cast(k), + static_cast(pq.M), + static_cast(pq.nbits), + static_cast(pq.ksub)); #pragma omp for - for (int i = 0; i < n; i++) { + for (idx_t i = 0; i < n; i++) { msk.run(dis_tables.get() + i * pq.ksub * pq.M, pq.ksub, distances + i * k, @@ -1067,7 +1071,7 @@ void MultiIndexQuantizer2::search( return; } - int k2 = std::min(K, int64_t(pq.ksub)); + int k2 = static_cast(std::min(K, int64_t(pq.ksub))); FAISS_THROW_IF_NOT(k2); int64_t M = pq.M; @@ -1113,7 +1117,10 @@ void MultiIndexQuantizer2::search( #pragma omp parallel if (n > 1) { MinSumK, false> msk( - K, pq.M, pq.nbits, k2); + static_cast(K), + static_cast(pq.M), + static_cast(pq.nbits), + k2); #pragma omp for for (idx_t i = 0; i < n; i++) { idx_t* li = labels + i * K; @@ -1129,7 +1136,7 @@ void MultiIndexQuantizer2::search( const idx_t* idmap = idmap0; int64_t vin = li[k]; int64_t vout = 0; - int bs = 0; + size_t bs = 0; for (int64_t m = 0; m < M; m++) { int64_t s = vin & mask1; vin >>= pq.nbits; diff --git a/faiss/IndexPQ.h b/faiss/IndexPQ.h index 75603efc70..5328ba5993 100644 --- a/faiss/IndexPQ.h +++ b/faiss/IndexPQ.h @@ -130,7 +130,8 @@ struct IndexPQStats { void reset(); }; -FAISS_API extern IndexPQStats indexPQ_stats; +FAISS_API extern IndexPQStats + indexPQ_stats; // NOLINT(facebook-avoid-non-const-global-variables) /** Quantizer where centroids are virtual: they are the Cartesian * product of sub-centroids. */ @@ -163,7 +164,8 @@ struct MultiIndexQuantizer : Index { }; // block size used in MultiIndexQuantizer::search -FAISS_API extern int multi_index_quantizer_search_bs; +FAISS_API extern int + multi_index_quantizer_search_bs; // NOLINT(facebook-avoid-non-const-global-variables) /** MultiIndexQuantizer where the PQ assignment is performed by sub-indexes */ diff --git a/faiss/IndexPreTransform.cpp b/faiss/IndexPreTransform.cpp index 8e22de0873..6cef7e6c87 100644 --- a/faiss/IndexPreTransform.cpp +++ b/faiss/IndexPreTransform.cpp @@ -62,9 +62,9 @@ IndexPreTransform::~IndexPreTransform() { void IndexPreTransform::train(idx_t n, const float* x) { int last_untrained = 0; if (!index->is_trained) { - last_untrained = chain.size(); + last_untrained = static_cast(chain.size()); } else { - for (int i = chain.size() - 1; i >= 0; i--) { + for (int i = static_cast(chain.size()) - 1; i >= 0; i--) { if (!chain[i]->is_trained) { last_untrained = i; break; @@ -129,7 +129,9 @@ const float* IndexPreTransform::apply_chain(idx_t n, const float* x) const { del2.swap(del); prev_x = xt; } - del.release(); + // Intentionally release ownership: caller takes ownership of the returned + // buffer + (void)del.release(); return prev_x; } @@ -138,7 +140,7 @@ void IndexPreTransform::reverse_chain(idx_t n, const float* xt, float* x) const float* next_x = xt; std::unique_ptr del; - for (int i = chain.size() - 1; i >= 0; i--) { + for (int i = static_cast(chain.size()) - 1; i >= 0; i--) { float* prev_x = (i == 0) ? x : new float[n * chain[i]->d_in]; std::unique_ptr del2((prev_x == x) ? nullptr : prev_x); chain[i]->reverse_transform(n, next_x, prev_x); diff --git a/faiss/IndexPreTransform.h b/faiss/IndexPreTransform.h index 996b6495ea..3ac06751f8 100644 --- a/faiss/IndexPreTransform.h +++ b/faiss/IndexPreTransform.h @@ -106,6 +106,11 @@ struct IndexPreTransform : Index { void check_compatible_for_merge(const Index& otherIndex) const override; ~IndexPreTransform() override; + // rule of five defaults + IndexPreTransform(const IndexPreTransform&) = default; + IndexPreTransform& operator=(const IndexPreTransform&) = default; + IndexPreTransform(IndexPreTransform&&) = default; + IndexPreTransform& operator=(IndexPreTransform&&) = default; }; } // namespace faiss diff --git a/faiss/IndexRefine.h b/faiss/IndexRefine.h index f0dbad23c0..0b68294e8a 100644 --- a/faiss/IndexRefine.h +++ b/faiss/IndexRefine.h @@ -75,6 +75,11 @@ struct IndexRefine : Index { void sa_decode(idx_t n, const uint8_t* bytes, float* x) const override; ~IndexRefine() override; + // rule of five defaults + IndexRefine(const IndexRefine&) = default; + IndexRefine& operator=(const IndexRefine&) = default; + IndexRefine(IndexRefine&&) = default; + IndexRefine& operator=(IndexRefine&&) = default; }; /** Version where the refinement index is an IndexFlat. It has one additional diff --git a/faiss/IndexRowwiseMinMax.cpp b/faiss/IndexRowwiseMinMax.cpp index 9694c5f995..1f01bb1074 100644 --- a/faiss/IndexRowwiseMinMax.cpp +++ b/faiss/IndexRowwiseMinMax.cpp @@ -333,8 +333,10 @@ void train_impl(IndexRowwiseMinMaxBase* const index, idx_t n, const float* x) { } // namespace // block size for performing sa_encode and sa_decode -int rowwise_minmax_sa_encode_bs = 16384; -int rowwise_minmax_sa_decode_bs = 16384; +int rowwise_minmax_sa_encode_bs = + 16384; // NOLINT(facebook-avoid-non-const-global-variables) +int rowwise_minmax_sa_decode_bs = + 16384; // NOLINT(facebook-avoid-non-const-global-variables) /********************************************************* * IndexRowwiseMinMaxBase implementation diff --git a/faiss/IndexRowwiseMinMax.h b/faiss/IndexRowwiseMinMax.h index e626ac81d2..717f3f17b5 100644 --- a/faiss/IndexRowwiseMinMax.h +++ b/faiss/IndexRowwiseMinMax.h @@ -49,6 +49,11 @@ struct IndexRowwiseMinMaxBase : Index { IndexRowwiseMinMaxBase(); ~IndexRowwiseMinMaxBase() override; + // rule of five defaults + IndexRowwiseMinMaxBase(const IndexRowwiseMinMaxBase&) = default; + IndexRowwiseMinMaxBase& operator=(const IndexRowwiseMinMaxBase&) = default; + IndexRowwiseMinMaxBase(IndexRowwiseMinMaxBase&&) = default; + IndexRowwiseMinMaxBase& operator=(IndexRowwiseMinMaxBase&&) = default; void add(idx_t n, const float* x) override; void search( @@ -93,7 +98,9 @@ struct IndexRowwiseMinMax : IndexRowwiseMinMaxBase { }; /// block size for performing sa_encode and sa_decode -FAISS_API extern int rowwise_minmax_sa_encode_bs; -FAISS_API extern int rowwise_minmax_sa_decode_bs; +FAISS_API extern int + rowwise_minmax_sa_encode_bs; // NOLINT(facebook-avoid-non-const-global-variables) +FAISS_API extern int + rowwise_minmax_sa_decode_bs; // NOLINT(facebook-avoid-non-const-global-variables) } // namespace faiss diff --git a/faiss/IndexShards.cpp b/faiss/IndexShards.cpp index 661b814568..4815b9d64e 100644 --- a/faiss/IndexShards.cpp +++ b/faiss/IndexShards.cpp @@ -203,7 +203,7 @@ void IndexShardsTemplate::search( const SearchParameters* params) const { FAISS_THROW_IF_NOT(k > 0); - int64_t nshard = this->count(); + int nshard = this->count(); std::vector all_distances(nshard * k * n); std::vector all_labels(nshard * k * n); diff --git a/faiss/IndexShardsIVF.cpp b/faiss/IndexShardsIVF.cpp index fb7e384e14..651b24c4b5 100644 --- a/faiss/IndexShardsIVF.cpp +++ b/faiss/IndexShardsIVF.cpp @@ -183,7 +183,7 @@ void IndexShardsIVF::search( quantizer->search(n, x, nprobe, Dq.data(), Iq.data()); - int64_t nshard = this->count(); + int nshard = this->count(); std::vector all_distances(nshard * k * n); std::vector all_labels(nshard * k * n); diff --git a/faiss/MatrixStats.cpp b/faiss/MatrixStats.cpp index fc3be51e42..e54d9603a2 100644 --- a/faiss/MatrixStats.cpp +++ b/faiss/MatrixStats.cpp @@ -52,7 +52,7 @@ void MatrixStats::PerDimStats::compute_mean_std() { if (var < 0) { var = 0; } - stddev = sqrt(var); + stddev = std::sqrt(var); } void MatrixStats::do_comment(const char* fmt, ...) { @@ -163,8 +163,8 @@ MatrixStats::MatrixStats(size_t n_in, size_t d_in, const float* x) } { // norm stats - min_norm2 = sqrt(min_norm2); - max_norm2 = sqrt(max_norm2); + min_norm2 = std::sqrt(min_norm2); + max_norm2 = std::sqrt(max_norm2); do_comment( "range of L2 norms=[%g, %g] (%zd null vectors)\n", min_norm2, diff --git a/faiss/MetaIndexes.cpp b/faiss/MetaIndexes.cpp index 20b16e113f..eb11a175e4 100644 --- a/faiss/MetaIndexes.cpp +++ b/faiss/MetaIndexes.cpp @@ -217,7 +217,8 @@ void IndexRandom::search( perm[j] = j; } for (int j = 0; j < k; j++) { - std::swap(perm[j], perm[rng.rand_int(ntotal)]); + std::swap( + perm[j], perm[rng.rand_int(static_cast(ntotal))]); I[j] = perm[j]; } } diff --git a/faiss/MetaIndexes.h b/faiss/MetaIndexes.h index cca6d32dc5..51bd111a75 100644 --- a/faiss/MetaIndexes.h +++ b/faiss/MetaIndexes.h @@ -47,6 +47,11 @@ struct IndexSplitVectors : Index { void reset() override; ~IndexSplitVectors() override; + // rule of five defaults + IndexSplitVectors(const IndexSplitVectors&) = default; + IndexSplitVectors& operator=(const IndexSplitVectors&) = default; + IndexSplitVectors(IndexSplitVectors&&) = default; + IndexSplitVectors& operator=(IndexSplitVectors&&) = default; }; /** index that returns random results. @@ -76,6 +81,11 @@ struct IndexRandom : Index { void reset() override; ~IndexRandom() override; + // rule of five defaults + IndexRandom(const IndexRandom&) = default; + IndexRandom& operator=(const IndexRandom&) = default; + IndexRandom(IndexRandom&&) = default; + IndexRandom& operator=(IndexRandom&&) = default; }; } // namespace faiss diff --git a/faiss/VectorTransform.cpp b/faiss/VectorTransform.cpp index e420384fcd..65adde59fe 100644 --- a/faiss/VectorTransform.cpp +++ b/faiss/VectorTransform.cpp @@ -191,7 +191,7 @@ void LinearTransform::apply_noalloc(idx_t n, const float* x, float* xt) const { "Transformation matrix not initialized"); float one = 1; - FINTEGER nbiti = d_out, ni = n, di = d_in; + FINTEGER nbiti = d_out, ni = static_cast(n), di = d_in; sgemm_("Transposed", "Not transposed", &nbiti, @@ -222,7 +222,7 @@ void LinearTransform::transform_transpose(idx_t n, const float* y, float* x) } { - FINTEGER dii = d_in, doi = d_out, ni = n; + FINTEGER dii = d_in, doi = d_out, ni = static_cast(n); float one = 1.0, zero = 0.0; sgemm_("Not", "Not", @@ -521,7 +521,7 @@ namespace { void eig(size_t d_in, double* cov, double* eigenvalues, int verbose) { { // compute eigenvalues and vectors - FINTEGER info = 0, lwork = -1, di = d_in; + FINTEGER info = 0, lwork = -1, di = static_cast(d_in); double workq; dsyev_("Vectors as well", @@ -533,7 +533,7 @@ void eig(size_t d_in, double* cov, double* eigenvalues, int verbose) { &workq, &lwork, &info); - lwork = FINTEGER(workq); + lwork = static_cast(workq); double* work = new double[lwork]; dsyev_("Vectors as well", @@ -628,7 +628,7 @@ void PCAMatrix::train(idx_t n, const float* x_in) { } } { - FINTEGER di = d_in, ni = n; + FINTEGER di = d_in, ni = static_cast(n); float one = 1.0; ssyrk_("Up", "Non transposed", @@ -682,7 +682,7 @@ void PCAMatrix::train(idx_t n, const float* x_in) { // compute Gram matrix std::vector gram(n * n); { - FINTEGER di = d_in, ni = n; + FINTEGER di = d_in, ni = static_cast(n); float one = 1.0, zero = 0.0; ssyrk_("Up", "Transposed", @@ -731,7 +731,7 @@ void PCAMatrix::train(idx_t n, const float* x_in) { } { // compute PCAMat = x' * v - FINTEGER di = d_in, ni = n; + FINTEGER di = d_in, ni = static_cast(n); float one = 1.0; sgemm_("Non", @@ -908,7 +908,7 @@ void ITQMatrix::train(idx_t n, const float* xf) { init_rotation.data(), d * d * sizeof(rotation[0])); } else { - RandomRotationMatrix rrot(d, d); + RandomRotationMatrix rrot(static_cast(d), static_cast(d)); rrot.init(seed); for (size_t i = 0; i < d * d; i++) { rotation[i] = rrot.A[i]; @@ -925,9 +925,11 @@ void ITQMatrix::train(idx_t n, const float* xf) { std::vector u(d * d), vt(d * d), singvals(d); for (int i = 0; i < max_iter; i++) { - print_if_verbose("rotation", rotation, d, d); + print_if_verbose( + "rotation", rotation, static_cast(d), static_cast(d)); { // rotated_data = np.dot(training_data, rotation) - FINTEGER di = d, ni = n; + FINTEGER di = static_cast(d), + ni = static_cast(n); double one = 1, zero = 0; dgemm_("N", "N", @@ -943,14 +945,19 @@ void ITQMatrix::train(idx_t n, const float* xf) { rotated_x.data(), &di); } - print_if_verbose("rotated_x", rotated_x, n, d); + print_if_verbose( + "rotated_x", + rotated_x, + static_cast(n), + static_cast(d)); // binarize for (size_t j = 0; j < n * d; j++) { rotated_x[j] = rotated_x[j] < 0 ? -1 : 1; } // covariance matrix { // rotated_data = np.dot(training_data, rotation) - FINTEGER di = d, ni = n; + FINTEGER di = static_cast(d), + ni = static_cast(n); double one = 1, zero = 0; dgemm_("N", "T", @@ -966,10 +973,11 @@ void ITQMatrix::train(idx_t n, const float* xf) { cov_mat.data(), &di); } - print_if_verbose("cov_mat", cov_mat, d, d); + print_if_verbose( + "cov_mat", cov_mat, static_cast(d), static_cast(d)); // SVD { - FINTEGER di = d; + FINTEGER di = static_cast(d); FINTEGER lwork = -1, info; double lwork1; @@ -991,7 +999,7 @@ void ITQMatrix::train(idx_t n, const float* xf) { FAISS_THROW_IF_NOT_MSG( info == 0, "LAPACK dgesvd workspace query failed"); - lwork = size_t(lwork1); + lwork = static_cast(lwork1); std::vector work(lwork); dgesvd_("A", "A", @@ -1009,11 +1017,11 @@ void ITQMatrix::train(idx_t n, const float* xf) { &info); FAISS_THROW_IF_NOT_FMT(info == 0, "sgesvd returned info=%d", info); } - print_if_verbose("u", u, d, d); - print_if_verbose("vt", vt, d, d); + print_if_verbose("u", u, static_cast(d), static_cast(d)); + print_if_verbose("vt", vt, static_cast(d), static_cast(d)); // update rotation { - FINTEGER di = d; + FINTEGER di = static_cast(d); double one = 1, zero = 0; dgemm_("N", "T", @@ -1029,7 +1037,11 @@ void ITQMatrix::train(idx_t n, const float* xf) { rotation.data(), &di); } - print_if_verbose("final rot", rotation, d, d); + print_if_verbose( + "final rot", + rotation, + static_cast(d), + static_cast(d)); } A.resize(d * d); for (size_t i = 0; i < d; i++) { @@ -1252,7 +1264,9 @@ void OPQMatrix::train(idx_t n, const float* x_in) { double t0 = getmillisecs(); for (int iter = 0; iter < niter; iter++) { { // torch.mm(xtrain, rotation:t()) - FINTEGER di = d, d2i = d2, ni = n; + FINTEGER di = static_cast(d), + d2i = static_cast(d2), + ni = static_cast(n); float zero = 0, one = 1; sgemm_("Transposed", "Not transposed", @@ -1299,7 +1313,9 @@ void OPQMatrix::train(idx_t n, const float* x_in) { { float *u = tmp.data(), *vt = &tmp[d * d]; float* sing_val = &tmp[2 * d * d]; - FINTEGER di = d, d2i = d2, ni = n; + FINTEGER di = static_cast(d), + d2i = static_cast(d2), + ni = static_cast(n); float one = 1, zero = 0; if (verbose) { @@ -1338,7 +1354,7 @@ void OPQMatrix::train(idx_t n, const float* x_in) { &lwork, &info); - lwork = int(worksz); + lwork = static_cast(worksz); std::vector work(lwork); // u and vt swapped sgesvd_("All", diff --git a/faiss/VectorTransform.h b/faiss/VectorTransform.h index 6288f16f95..19b6583097 100644 --- a/faiss/VectorTransform.h +++ b/faiss/VectorTransform.h @@ -63,6 +63,11 @@ struct VectorTransform { virtual void check_identical(const VectorTransform& other) const = 0; virtual ~VectorTransform() {} + // rule of five defaults + VectorTransform(const VectorTransform&) = default; + VectorTransform& operator=(const VectorTransform&) = default; + VectorTransform(VectorTransform&&) = default; + VectorTransform& operator=(VectorTransform&&) = default; }; /** Generic linear transformation, with bias term applied on output @@ -109,6 +114,11 @@ struct LinearTransform : VectorTransform { void check_identical(const VectorTransform& other) const override; ~LinearTransform() override {} + // rule of five defaults + LinearTransform(const LinearTransform&) = default; + LinearTransform& operator=(const LinearTransform&) = default; + LinearTransform(LinearTransform&&) = default; + LinearTransform& operator=(LinearTransform&&) = default; }; /// Randomly rotate a set of vectors diff --git a/faiss/build.cpp b/faiss/build.cpp index c14dc6d052..35c0981b53 100644 --- a/faiss/build.cpp +++ b/faiss/build.cpp @@ -10,14 +10,14 @@ namespace faiss { bool has_omp() { - int omp = 1; + int omp_available = 1; // Detect whether OpenMP is enabled by using the 'max' reduction to render // the below assignment a no-op. This works: // 1) without starting any threads // 2) irrespective of the current thread limit -#pragma omp parallel reduction(max : omp) num_threads(1) - omp = 0; - return omp != 0; +#pragma omp parallel reduction(max : omp_available) num_threads(1) + omp_available = 0; + return omp_available != 0; } } // namespace faiss diff --git a/faiss/clone_index.h b/faiss/clone_index.h index a3ae0e41a1..2727e385e8 100644 --- a/faiss/clone_index.h +++ b/faiss/clone_index.h @@ -30,6 +30,12 @@ struct Cloner { virtual Index* clone_Index(const Index*); virtual IndexIVF* clone_IndexIVF(const IndexIVF*); virtual ~Cloner() {} + // rule of five defaults + Cloner() = default; + Cloner(const Cloner&) = default; + Cloner& operator=(const Cloner&) = default; + Cloner(Cloner&&) = default; + Cloner& operator=(Cloner&&) = default; }; Quantizer* clone_Quantizer(const Quantizer* quant); diff --git a/faiss/impl/index_read.cpp b/faiss/impl/index_read.cpp index c19c58b51f..8e37654107 100644 --- a/faiss/impl/index_read.cpp +++ b/faiss/impl/index_read.cpp @@ -474,7 +474,8 @@ static void read_ArrayInvertedLists_sizes( } } -bool index_read_warn_on_null_invlists = true; +bool index_read_warn_on_null_invlists = + true; // NOLINT(facebook-avoid-non-const-global-variables) std::unique_ptr read_InvertedLists_up( IOReader* f, diff --git a/faiss/index_factory.cpp b/faiss/index_factory.cpp index 1e0eb5b780..58ce1694a0 100644 --- a/faiss/index_factory.cpp +++ b/faiss/index_factory.cpp @@ -13,7 +13,7 @@ #include -#include +#include // NOLINT(facebook-hte-BadInclude-regex): used for index_factory parsing, re2 not suitable here #include #include @@ -69,7 +69,8 @@ namespace faiss { * index_factory ***************************************************************/ -int index_factory_verbose = 0; +int index_factory_verbose = + 0; // NOLINT(facebook-avoid-non-const-global-variables) namespace { @@ -147,6 +148,7 @@ int mres_to_int(const std::ssub_match& mr, int deflt = -1, int begin = 0) { } std::map sq_types = { + // NOLINT(facebook-avoid-non-const-global-variables) {"SQ8", ScalarQuantizer::QT_8bit}, {"SQ4", ScalarQuantizer::QT_4bit}, {"SQ6", ScalarQuantizer::QT_6bit}, @@ -160,6 +162,7 @@ const std::string sq_pattern = "(SQ0|SQ4|SQ8|SQ6|SQfp16|SQbf16|SQ8_direct_signed|SQ8_direct)"; std::map aq_search_type = { + // NOLINT(facebook-avoid-non-const-global-variables) {"_Nfloat", AdditiveQuantizer::ST_norm_float}, {"_Nnone", AdditiveQuantizer::ST_LUT_nonorm}, {"_Nqint8", AdditiveQuantizer::ST_norm_qint8}, @@ -183,7 +186,7 @@ AdditiveQuantizer::Search_type_t aq_parse_search_type( return metric == METRIC_L2 ? AdditiveQuantizer::ST_decompress : AdditiveQuantizer::ST_LUT_nonorm; } - int pos = stok.rfind('_'); + size_t pos = stok.rfind('_'); return aq_search_type[stok.substr(pos)]; } @@ -330,7 +333,7 @@ IndexIVF* parse_IndexIVF( MetricType mt, bool own_il) { std::smatch sm; - auto match = [&sm, &code_string](const std::string pattern) { + auto match = [&sm, &code_string](const std::string& pattern) { return re_match(code_string, pattern, sm); }; auto get_q = [&quantizer] { return quantizer.release(); }; @@ -491,7 +494,7 @@ IndexIVF* parse_IndexIVF( */ IndexHNSW* parse_IndexHNSW( - const std::string code_string, + const std::string& code_string, int d, MetricType mt, int hnsw_M) { @@ -548,7 +551,7 @@ IndexHNSW* parse_IndexHNSW( */ IndexNSG* parse_IndexNSG( - const std::string code_string, + const std::string& code_string, int d, MetricType mt, int nsg_R) { @@ -944,7 +947,8 @@ std::unique_ptr index_factory_sub( IndexPreTransform* index_pt = new IndexPreTransform(sub_index.get()); std::unique_ptr ret(index_pt); index_pt->own_fields = true; - sub_index.release(); + // Ownership transferred to index_pt via own_fields = true + (void)sub_index.release(); while (vts.size() > 0) { if (verbose) { printf("prepend trans %d -> %d\n", diff --git a/faiss/index_factory.h b/faiss/index_factory.h index 5dd8c19ad2..68ce40e019 100644 --- a/faiss/index_factory.h +++ b/faiss/index_factory.h @@ -23,7 +23,8 @@ Index* index_factory( bool own_invlists = true); /// set to > 0 to get more logs from index_factory -FAISS_API extern int index_factory_verbose; +FAISS_API extern int + index_factory_verbose; // NOLINT(facebook-avoid-non-const-global-variables) IndexBinary* index_binary_factory( int d, diff --git a/faiss/index_io.h b/faiss/index_io.h index 6e95c04bbc..cb87c1973d 100644 --- a/faiss/index_io.h +++ b/faiss/index_io.h @@ -70,7 +70,8 @@ const int IO_FLAG_MMAP = IO_FLAG_SKIP_IVF_DATA | 0x646f0000; // after OnDiskInvertedLists get properly updated. const int IO_FLAG_MMAP_IFC = 1 << 9; -FAISS_API extern bool index_read_warn_on_null_invlists; +FAISS_API extern bool + index_read_warn_on_null_invlists; // NOLINT(facebook-avoid-non-const-global-variables) Index* read_index(const char* fname, int io_flags = 0); Index* read_index(FILE* f, int io_flags = 0);