Skip to content

Commit

Permalink
Fix shadowed variable in faiss/impl/residual_quantizer_encode_steps.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: D52959180

fbshipit-source-id: 90f735f65f1306c817d80c99c8a2108aee7c599a
  • Loading branch information
r-barnes authored and facebook-github-bot committed Jan 24, 2024
1 parent 7c4fb6d commit ae25b1b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions faiss/impl/residual_quantizer_encode_steps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ void beam_search_encode_step(
cent_ids.data() + i * beam_size * new_beam_size;

// here we could be a tad more efficient by merging sorted arrays
for (int i = 0; i < new_beam_size; i++) {
new_distances_i[i] = C::neutral();
for (int i_2 = 0; i_2 < new_beam_size; i_2++) {
new_distances_i[i_2] = C::neutral();
}
std::vector<int> perm(new_beam_size, -1);
heap_addn<C>(
Expand Down Expand Up @@ -325,8 +325,8 @@ void beam_search_encode_step(
const float* cent_distances_i =
cent_distances.data() + i * beam_size * K;
// then we have to select the best results
for (int i = 0; i < new_beam_size; i++) {
new_distances_i[i] = C::neutral();
for (int i_2 = 0; i_2 < new_beam_size; i_2++) {
new_distances_i[i_2] = C::neutral();
}
std::vector<int> perm(new_beam_size, -1);

Expand Down Expand Up @@ -558,8 +558,8 @@ void beam_search_encode_step_tab(
const float* cent_distances_i = cent_distances.data();

// then we have to select the best results
for (int i = 0; i < new_beam_size; i++) {
new_distances_i[i] = C::neutral();
for (int i_2 = 0; i_2 < new_beam_size; i_2++) {
new_distances_i[i_2] = C::neutral();
}
std::vector<int> perm(new_beam_size, -1);

Expand Down

0 comments on commit ae25b1b

Please sign in to comment.