Skip to content

Commit

Permalink
Fix shadowed variable in faiss/IndexNSG.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: dmm-fb

Differential Revision: D52959118

fbshipit-source-id: f3b44eb294ae534ebebfcb7d2da4cd70e259eaa3
  • Loading branch information
r-barnes authored and facebook-github-bot committed Jan 23, 2024
1 parent bffedda commit 0716bde
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions faiss/IndexNSG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void IndexNSG::search(
}
}

void IndexNSG::build(idx_t n, const float* x, idx_t* knn_graph, int GK) {
void IndexNSG::build(idx_t n, const float* x, idx_t* knn_graph, int GK_2) {
FAISS_THROW_IF_NOT_MSG(
storage,
"Please use IndexNSGFlat (or variants) instead of IndexNSG directly");
Expand All @@ -115,9 +115,9 @@ void IndexNSG::build(idx_t n, const float* x, idx_t* knn_graph, int GK) {
ntotal = storage->ntotal;

// check the knn graph
check_knn_graph(knn_graph, n, GK);
check_knn_graph(knn_graph, n, GK_2);

const nsg::Graph<idx_t> knng(knn_graph, n, GK);
const nsg::Graph<idx_t> knng(knn_graph, n, GK_2);
nsg.build(storage, n, knng, verbose);
is_built = true;
}
Expand Down

0 comments on commit 0716bde

Please sign in to comment.