Skip to content

Commit

Permalink
Fix shadowed variable in faiss/IndexFastScan.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: meyering

Differential Revision: D52582914

fbshipit-source-id: edb3983635de4343c4a0b20096e81852cfa058c6
  • Loading branch information
r-barnes authored and facebook-github-bot committed Jan 16, 2024
1 parent 7dd06dd commit 9a63a3c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions faiss/IndexFastScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ inline size_t roundup(size_t a, size_t b) {

void IndexFastScan::init_fastscan(
int d,
size_t M,
size_t nbits,
size_t M_2,
size_t nbits_2,
MetricType metric,
int bbs) {
FAISS_THROW_IF_NOT(nbits == 4);
FAISS_THROW_IF_NOT(nbits_2 == 4);
FAISS_THROW_IF_NOT(bbs % 32 == 0);
this->d = d;
this->M = M;
this->nbits = nbits;
this->M = M_2;
this->nbits = nbits_2;
this->metric_type = metric;
this->bbs = bbs;
ksub = (1 << nbits);
ksub = (1 << nbits_2);

code_size = (M * nbits + 7) / 8;
code_size = (M_2 * nbits_2 + 7) / 8;
ntotal = ntotal2 = 0;
M2 = roundup(M, 2);
M2 = roundup(M_2, 2);
is_trained = false;
}

Expand Down

0 comments on commit 9a63a3c

Please sign in to comment.