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
4 changes: 2 additions & 2 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 @@ -786,7 +786,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
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
10 changes: 6 additions & 4 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 Down Expand Up @@ -528,22 +528,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.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,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<int>(d_in)),
ntotal(0),
verbose(false),
is_trained(true),
Expand Down
6 changes: 3 additions & 3 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
2 changes: 1 addition & 1 deletion faiss/IndexAdditiveQuantizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,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
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
4 changes: 3 additions & 1 deletion faiss/IndexBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(d_)),
code_size(static_cast<int>(d_ / 8)),
metric_type(metric) {
FAISS_THROW_IF_NOT(d_ % 8 == 0);
}

Expand Down
10 changes: 6 additions & 4 deletions faiss/IndexBinaryHNSW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<HNSW::storage_idx_t>(i + n0);
int pt_level = hnsw.levels[pt_id] - 1;
while (pt_level >= static_cast<int>(hist.size())) {
hist.push_back(0);
Expand All @@ -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<HNSW::storage_idx_t>(i + n0);
int pt_level = hnsw.levels[pt_id] - 1;
order[offsets[pt_level]++] = pt_id;
}
Expand All @@ -99,7 +101,7 @@ void hnsw_add_vertices(
{ // perform add
RandomGenerator rng2(789);

size_t i1 = n;
size_t i1 = static_cast<int>(n);

for (int pt_level = static_cast<int>(hist.size()) - 1;
pt_level >= int(!index_hnsw.init_level0);
Expand Down Expand Up @@ -392,7 +394,7 @@ void IndexBinaryHNSWCagra::search(
float distance = (*dis)(idx);

if (distance < nearest_d[i]) {
nearest[i] = idx;
nearest[i] = static_cast<storage_idx_t>(idx);
nearest_d[i] = distance;
}
}
Expand Down
23 changes: 15 additions & 8 deletions faiss/IndexBinaryIVF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(n * nprobe_));

search_preassigned(
n,
Expand Down Expand Up @@ -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<int>(n * nprobe_2));

// search_preassigned() with `store_pairs` enabled to obtain the list_no
// and offset into `codes` for reconstruction
Expand Down Expand Up @@ -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<int>(nlist), cp);
quantizer->reset();

IndexFlatL2 index_tmp(d);
Expand Down Expand Up @@ -705,9 +705,10 @@ void search_knn_hamming_per_invlist(
int32_t* keys = new int32_t[n * nprobe];
std::unique_ptr<int32_t[]> delete_keys(keys);
for (size_t i = 0; i < n * static_cast<size_t>(nprobe); i++) {
keys[i] = keys_in[i];
keys[i] = static_cast<int32_t>(keys_in[i]);
}
matrix_bucket_sort_inplace(n, nprobe, keys, ivf->nlist, lims.data(), 0);
matrix_bucket_sort_inplace(
n, nprobe, keys, static_cast<int32_t>(ivf->nlist), lims.data(), 0);

using C = CMax<int32_t, idx_t>;
heap_heapify<C>(n * k, distances, labels);
Expand Down Expand Up @@ -754,7 +755,12 @@ void search_knn_hamming_per_invlist(
} else {
for (; i + BS <= nq; i += BS) {
BlockSearchVariableK<HammingComputer, BS> bc(
code_size, k, x, keys + l0 + i, distances, labels);
code_size,
static_cast<int>(k),
x,
keys + l0 + i,
distances,
labels);
for (idx_t j = 0; j < nb; j++) {
bc.add_bcode(bcodes + j * code_size, ids[j]);
}
Expand All @@ -764,7 +770,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<int>(code_size));
idx_t* __restrict idxi = labels + qno * k;
int32_t* __restrict simi = distances + qno * k;
int32_t simi0 = simi[0];
Expand Down Expand Up @@ -868,7 +875,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<int>(n * nprobe_2));

range_search_preassigned(n, x, radius, idx.get(), coarse_dis.get(), res);

Expand Down
20 changes: 12 additions & 8 deletions faiss/IndexFastScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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<int>(index.nbits));
dis += dt[c] * context.pq2x4_scale;
dt += index.ksub;
}
Expand Down Expand Up @@ -487,8 +487,8 @@ void IndexFastScan::search_implem_12(
qbs_ = pq4_preferred_qbs(static_cast<int>(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<int>(M2), quantized_dis_tables.get(), LUT.get());
FAISS_THROW_IF_NOT(LUT_nq == n);

auto scanner = make_knn_scanner(
Expand All @@ -504,7 +504,7 @@ void IndexFastScan::search_implem_12(
qbs_,

ntotal2,
M2,
static_cast<int>(M2),
codes.get(),
LUT.get(),
context.pq2x4_scale,
Expand Down Expand Up @@ -570,7 +570,11 @@ void IndexFastScan::search_implem_14(
}

AlignedTable<uint8_t> LUT(n * dim12);
pq4_pack_LUT(n, M2, quantized_dis_tables.get(), LUT.get());
pq4_pack_LUT(
static_cast<int>(n),
static_cast<int>(M2),
quantized_dis_tables.get(),
LUT.get());

auto scanner = make_knn_scanner(
C::is_max, n, k, ntotal, distances, labels, nullptr, impl, context);
Expand All @@ -582,10 +586,10 @@ void IndexFastScan::search_implem_14(
// accessible through the SIMDResultHandlerToFloat* interface.
if (!(skip & (2 | 4))) {
scanner->accumulate_loop(
n,
static_cast<int>(n),
ntotal2,
bbs,
M2,
static_cast<int>(M2),
codes.get(),
LUT.get(),
context.pq2x4_scale,
Expand Down
Loading
Loading