Skip to content
Closed
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
8 changes: 4 additions & 4 deletions faiss/IndexAdditiveQuantizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,23 +527,23 @@ void ResidualCoarseQuantizer::search(
float* distances,
idx_t* labels,
const SearchParameters* params_in) const {
float beam_factor_2 = this->beam_factor;
float actual_beam_factor = this->beam_factor;
if (params_in) {
auto params =
dynamic_cast<const SearchParametersResidualCoarseQuantizer*>(
params_in);
FAISS_THROW_IF_NOT_MSG(
params,
"need SearchParametersResidualCoarseQuantizer parameters");
beam_factor_2 = params->beam_factor;
actual_beam_factor = params->beam_factor;
}

if (beam_factor_2 < 0) {
if (actual_beam_factor < 0) {
AdditiveCoarseQuantizer::search(n, x, k, distances, labels);
return;
}

int beam_size = int(k * beam_factor_2);
int beam_size = int(k * actual_beam_factor);
if (beam_size > ntotal) {
beam_size = ntotal;
}
Expand Down
44 changes: 29 additions & 15 deletions faiss/IndexIVFFastScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ IndexIVFFastScan::IndexIVFFastScan() {

void IndexIVFFastScan::init_fastscan(
size_t M,
size_t nbits_2,
size_t nbits_init,
size_t nlist,
MetricType /* metric */,
int bbs_2) {
FAISS_THROW_IF_NOT(bbs_2 % 32 == 0);
FAISS_THROW_IF_NOT(nbits_2 == 4);
FAISS_THROW_IF_NOT(nbits_init == 4);

this->M = M;
this->nbits = nbits_2;
this->nbits = nbits_init;
this->bbs = bbs_2;
ksub = (1 << nbits_2);
ksub = (1 << nbits_init);
M2 = roundup(M, 2);
code_size = M2 / 2;

Expand Down Expand Up @@ -1028,11 +1028,11 @@ void IndexIVFFastScan::search_implem_12(

// prepare the result handlers

int qbs2_2 = this->qbs2 ? this->qbs2 : 11;
int actual_qbs2 = this->qbs2 ? this->qbs2 : 11;

std::vector<uint16_t> tmp_bias;
if (biases.get()) {
tmp_bias.resize(qbs2_2);
tmp_bias.resize(actual_qbs2);
handler.dbias = tmp_bias.data();
}

Expand All @@ -1045,7 +1045,7 @@ void IndexIVFFastScan::search_implem_12(
int list_no = qcs[i0].list_no;
size_t i1 = i0 + 1;

while (i1 < qcs.size() && i1 < i0 + qbs2_2) {
while (i1 < qcs.size() && i1 < i0 + actual_qbs2) {
if (qcs[i1].list_no != list_no) {
break;
}
Expand All @@ -1065,7 +1065,7 @@ void IndexIVFFastScan::search_implem_12(
std::vector<int> q_map(nc), lut_entries(nc);
AlignedTable<uint8_t> LUT(nc * dim12);
memset(LUT.get(), -1, nc * dim12);
int qbs_2 = pq4_preferred_qbs(nc);
int qbs_for_list = pq4_preferred_qbs(nc);

for (size_t i = i0; i < i1; i++) {
const QC& qc = qcs[i];
Expand All @@ -1077,7 +1077,11 @@ void IndexIVFFastScan::search_implem_12(
}
}
pq4_pack_LUT_qbs_q_map(
qbs_2, M2, dis_tables.get(), lut_entries.data(), LUT.get());
qbs_for_list,
M2,
dis_tables.get(),
lut_entries.data(),
LUT.get());

// access the inverted list

Expand All @@ -1093,7 +1097,13 @@ void IndexIVFFastScan::search_implem_12(
handler.id_map = ids.get();

pq4_accumulate_loop_qbs(
qbs_2, list_size, M2, codes.get(), LUT.get(), handler, scaler);
qbs_for_list,
list_size,
M2,
codes.get(),
LUT.get(),
handler,
scaler);
// prepare for next loop
i0 = i1;
}
Expand Down Expand Up @@ -1231,11 +1241,11 @@ void IndexIVFFastScan::search_implem_14(
is_max, impl, n, k, local_dis.data(), local_idx.data(), sel));
handler->begin(normalizers.get());

int qbs2_2 = this->qbs2 ? this->qbs2 : 11;
int actual_qbs2 = this->qbs2 ? this->qbs2 : 11;

std::vector<uint16_t> tmp_bias;
if (biases.get()) {
tmp_bias.resize(qbs2_2);
tmp_bias.resize(actual_qbs2);
handler->dbias = tmp_bias.data();
}

Expand All @@ -1255,7 +1265,7 @@ void IndexIVFFastScan::search_implem_14(
std::vector<int> q_map(nc), lut_entries(nc);
AlignedTable<uint8_t> LUT(nc * dim12);
memset(LUT.get(), -1, nc * dim12);
int qbs_2 = pq4_preferred_qbs(nc);
int qbs_for_list = pq4_preferred_qbs(nc);

for (size_t i = i0; i < i1; i++) {
const QC& qc = qcs[i];
Expand All @@ -1268,7 +1278,11 @@ void IndexIVFFastScan::search_implem_14(
}
}
pq4_pack_LUT_qbs_q_map(
qbs_2, M2, dis_tables.get(), lut_entries.data(), LUT.get());
qbs_for_list,
M2,
dis_tables.get(),
lut_entries.data(),
LUT.get());

// access the inverted list

Expand All @@ -1284,7 +1298,7 @@ void IndexIVFFastScan::search_implem_14(
handler->id_map = ids.get();

pq4_accumulate_loop_qbs(
qbs_2,
qbs_for_list,
list_size,
M2,
codes.get(),
Expand Down
4 changes: 2 additions & 2 deletions faiss/impl/NSG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ void NSG::search_on_graph(
retset[k].flag = false;
int n = retset[k].id;

size_t nneigh_2 = graph.get_neighbors(n, neighbors.data());
for (int m = 0; m < nneigh_2; m++) {
size_t nneigh_for_n = graph.get_neighbors(n, neighbors.data());
for (int m = 0; m < nneigh_for_n; m++) {
int id = neighbors[m];
if (id > ntotal || vt.get(id)) {
continue;
Expand Down