Enable precomputed table only if L2 quantizer and by_residual is true (#2659)

Summary:
Related issue https://github.com/facebookresearch/faiss/issues/2658

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2659

Reviewed By: algoriddle

Differential Revision: D42431369

Pulled By: mdouze

fbshipit-source-id: 4beeedd86e8090b499a3cd2931f3d9511bc49c51
This commit is contained in:
chasingegg
2023-01-10 07:29:01 -08:00
committed by Facebook GitHub Bot
parent 38bf321885
commit 62c7342db1
3 changed files with 16 additions and 4 deletions
+9 -3
View File
@@ -422,6 +422,7 @@ void initialize_IVFPQ_precomputed_table(
const Index* quantizer,
const ProductQuantizer& pq,
AlignedTable<float>& precomputed_table,
bool by_residual,
bool verbose) {
size_t nlist = quantizer->ntotal;
size_t d = quantizer->d;
@@ -433,10 +434,10 @@ void initialize_IVFPQ_precomputed_table(
}
if (use_precomputed_table == 0) { // then choose the type of table
if (quantizer->metric_type == METRIC_INNER_PRODUCT) {
if (!(quantizer->metric_type == METRIC_L2 && by_residual)) {
if (verbose) {
printf("IndexIVFPQ::precompute_table: precomputed "
"tables not needed for inner product quantizers\n");
"tables needed only for L2 metric and by_residual is enabled\n");
}
precomputed_table.resize(0);
return;
@@ -515,7 +516,12 @@ void initialize_IVFPQ_precomputed_table(
void IndexIVFPQ::precompute_table() {
initialize_IVFPQ_precomputed_table(
use_precomputed_table, quantizer, pq, precomputed_table, verbose);
use_precomputed_table,
quantizer,
pq,
precomputed_table,
by_residual,
verbose);
}
namespace {
+1
View File
@@ -162,6 +162,7 @@ void initialize_IVFPQ_precomputed_table(
const Index* quantizer,
const ProductQuantizer& pq,
AlignedTable<float>& precomputed_table,
bool by_residual,
bool verbose);
/// statistics are robust to internal threading, but not if
+6 -1
View File
@@ -156,7 +156,12 @@ void IndexIVFPQFastScan::train_residual(idx_t n, const float* x_in) {
void IndexIVFPQFastScan::precompute_table() {
initialize_IVFPQ_precomputed_table(
use_precomputed_table, quantizer, pq, precomputed_table, verbose);
use_precomputed_table,
quantizer,
pq,
precomputed_table,
by_residual,
verbose);
}
/*********************************************************