Skip to content

Commit

Permalink
Fix shadowed variable in faiss/IndexAdditiveQuantizerFastScan.cpp
Browse files Browse the repository at this point in the history
Summary:
Our upcoming compiler upgrade will require us not to have shadowed variables. Such variables have a _high_ bug rate and reduce readability, so we would like to avoid them even if the compiler was not forcing us to do so.

This codemod attempts to fix an instance of a shadowed variable. Please review with care: if it's failed the result will be a silent bug.

**What's a shadowed variable?**

Shadowed variables are variables in an inner scope with the same name as another variable in an outer scope. Having the same name for both variables might be semantically correct, but it can make the code confusing to read! It can also hide subtle bugs.

This diff fixes such an issue by renaming the variable.

 - If you approve of this diff, please use the "Accept & Ship" button :-)

Reviewed By: algoriddle

Differential Revision: D52959038

fbshipit-source-id: 2b688a08710ff60aea0fea9d8be34f3c1f524f85
  • Loading branch information
r-barnes authored and facebook-github-bot committed Jan 24, 2024
1 parent ae25b1b commit a7b76a7
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions faiss/IndexAdditiveQuantizerFastScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,30 @@ IndexAdditiveQuantizerFastScan::IndexAdditiveQuantizerFastScan(
}

void IndexAdditiveQuantizerFastScan::init(
AdditiveQuantizer* aq,
AdditiveQuantizer* aq_2,
MetricType metric,
int bbs) {
FAISS_THROW_IF_NOT(aq != nullptr);
FAISS_THROW_IF_NOT(!aq->nbits.empty());
FAISS_THROW_IF_NOT(aq->nbits[0] == 4);
FAISS_THROW_IF_NOT(aq_2 != nullptr);
FAISS_THROW_IF_NOT(!aq_2->nbits.empty());
FAISS_THROW_IF_NOT(aq_2->nbits[0] == 4);
if (metric == METRIC_INNER_PRODUCT) {
FAISS_THROW_IF_NOT_MSG(
aq->search_type == AdditiveQuantizer::ST_LUT_nonorm,
aq_2->search_type == AdditiveQuantizer::ST_LUT_nonorm,
"Search type must be ST_LUT_nonorm for IP metric");
} else {
FAISS_THROW_IF_NOT_MSG(
aq->search_type == AdditiveQuantizer::ST_norm_lsq2x4 ||
aq->search_type == AdditiveQuantizer::ST_norm_rq2x4,
aq_2->search_type == AdditiveQuantizer::ST_norm_lsq2x4 ||
aq_2->search_type == AdditiveQuantizer::ST_norm_rq2x4,
"Search type must be lsq2x4 or rq2x4 for L2 metric");
}

this->aq = aq;
this->aq = aq_2;
if (metric == METRIC_L2) {
M = aq->M + 2; // 2x4 bits AQ
M = aq_2->M + 2; // 2x4 bits AQ
} else {
M = aq->M;
M = aq_2->M;
}
init_fastscan(aq->d, M, 4, metric, bbs);
init_fastscan(aq_2->d, M, 4, metric, bbs);

max_train_points = 1024 * ksub * M;
}
Expand Down

0 comments on commit a7b76a7

Please sign in to comment.