Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions faiss/AutoTune.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(a.size()) - 1;
while (i0 + 1 < i1) {
int imed = (i0 + i1 + 1) / 2;
if (a[imed].perf < perf) {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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<int>(n_comb - 1);
rand_perm(&perm[2], n_comb - 2, 1234);
for (size_t i = 2; i < perm.size(); i++) {
perm[i]++;
Expand Down
20 changes: 20 additions & 0 deletions faiss/AutoTune.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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;
};

/**
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions faiss/Clustering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(nx));
}
} else {
// use subsampling with a default std rng
Expand Down Expand Up @@ -262,7 +262,7 @@ int split_clusters(
}
}

return nsplit;
return static_cast<int>(nsplit);
}

} // namespace
Expand Down Expand Up @@ -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<int>(k), assign.get()),
nsplit};
iteration_stats.push_back(stats);

Expand Down Expand Up @@ -649,7 +649,7 @@ float kmeans_clustering(
size_t k,
const float* x,
float* centroids) {
Clustering clus(d, k);
Clustering clus(static_cast<int>(d), static_cast<int>(k));
clus.verbose = d * n * k > (size_t(1) << 30);
// display logs if > 1Gflop per iteration
IndexFlatL2 index(d);
Expand Down Expand Up @@ -700,7 +700,7 @@ void ProgressiveDimClustering::train(
ProgressiveDimIndexFactory& factory) {
int d_prev = 0;

PCAMatrix pca(d, d);
PCAMatrix pca(static_cast<int>(d), static_cast<int>(d));

std::vector<float> xbuf;
if (apply_pca) {
Expand All @@ -725,7 +725,7 @@ void ProgressiveDimClustering::train(
}
std::unique_ptr<Index> clustering_index(factory(di));

Clustering clus(di, k, *this);
Clustering clus(di, static_cast<int>(k), *this);
if (d_prev > 0) {
// copy warm-start centroids (padded with 0s)
clus.centroids.resize(k * di);
Expand Down
24 changes: 24 additions & 0 deletions faiss/Clustering.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions faiss/IVFlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ IndexIVFResidualQuantizer* ivf_residual_from_quantizer(
std::vector<size_t> nbits(nlevel);
std::copy(rq.nbits.begin(), rq.nbits.begin() + nlevel, nbits.begin());
std::unique_ptr<ResidualCoarseQuantizer> rcq(
new ResidualCoarseQuantizer(rq.d, nbits));
new ResidualCoarseQuantizer(static_cast<int>(rq.d), nbits));

// set the coarse quantizer from the 2 first quantizers
rcq->rq.initialize_from(rq);
Expand All @@ -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;
Expand Down Expand Up @@ -528,22 +529,24 @@ void ivf_residual_add_from_flat_codes(
for (idx_t i = 0; i < static_cast<idx_t>(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<int>(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<int>(rq.nbits[j]);
wr.write(rd.read(nbit), nbit);
}
// we need to recompute the norm
// decode first, does not use the norm component, so that's
// ok
index->rq.decode(tmp_code.data(), tmp.data(), 1);
float norm = fvec_norm_L2sqr<SL>(tmp.data(), rq.d);
wr.write(rq.encode_norm(norm), rq.norm_bits);
wr.write(
rq.encode_norm(norm),
static_cast<int>(rq.norm_bits));

// add code to the inverted list
invlists.add_entry(list_no, i, tmp_code.data());
Expand Down
2 changes: 1 addition & 1 deletion faiss/Index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(-1);
}

void Index::reconstruct(idx_t, float*) const {
Expand Down
13 changes: 12 additions & 1 deletion faiss/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -115,14 +121,19 @@ 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<int>(d_in)),
ntotal(0),
verbose(false),
is_trained(true),
metric_type(metric),
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
*
Expand Down
9 changes: 5 additions & 4 deletions faiss/Index2Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ struct DistanceXPQ4 : Distance2Level {
dynamic_cast<IndexFlat*>(storage.q1.quantizer);

FAISS_ASSERT(quantizer);
M = storage.pq.M;
M = static_cast<int>(storage.pq.M);
pq_l1_tab = quantizer->get_xb();
}

Expand Down Expand Up @@ -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<int>(storage.pq.M / 2);
mi_nbits = static_cast<int>(mi->pq.nbits);
pq_l1_tab = mi->pq.centroids.data();
}

Expand Down Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion faiss/Index2Layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
11 changes: 8 additions & 3 deletions faiss/IndexAdditiveQuantizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(iaq.d) * 2),
aq(*iaq.aq),
vd(vd_),
d(iaq.d) {}
Expand Down Expand Up @@ -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<size_t>(iaq.d) * 2),
aq(*iaq.aq),
d(iaq.d) {}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<int>(ntotal);
}
size_t memory_per_point = rq.memory_per_point(beam_size);

Expand Down
10 changes: 10 additions & 0 deletions faiss/IndexAdditiveQuantizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion faiss/IndexAdditiveQuantizerFastScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(aq_init->d), M, 4, metric, bbs_);

max_train_points = 1024 * ksub * M;
}
Expand Down
Loading
Loading