Skip to content

Commit ae25b1b

Browse files
r-barnesfacebook-github-bot
authored andcommitted
Fix shadowed variable in faiss/impl/residual_quantizer_encode_steps.cpp
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
1 parent 7c4fb6d commit ae25b1b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

faiss/impl/residual_quantizer_encode_steps.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ void beam_search_encode_step(
292292
cent_ids.data() + i * beam_size * new_beam_size;
293293

294294
// here we could be a tad more efficient by merging sorted arrays
295-
for (int i = 0; i < new_beam_size; i++) {
296-
new_distances_i[i] = C::neutral();
295+
for (int i_2 = 0; i_2 < new_beam_size; i_2++) {
296+
new_distances_i[i_2] = C::neutral();
297297
}
298298
std::vector<int> perm(new_beam_size, -1);
299299
heap_addn<C>(
@@ -325,8 +325,8 @@ void beam_search_encode_step(
325325
const float* cent_distances_i =
326326
cent_distances.data() + i * beam_size * K;
327327
// then we have to select the best results
328-
for (int i = 0; i < new_beam_size; i++) {
329-
new_distances_i[i] = C::neutral();
328+
for (int i_2 = 0; i_2 < new_beam_size; i_2++) {
329+
new_distances_i[i_2] = C::neutral();
330330
}
331331
std::vector<int> perm(new_beam_size, -1);
332332

@@ -558,8 +558,8 @@ void beam_search_encode_step_tab(
558558
const float* cent_distances_i = cent_distances.data();
559559

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

0 commit comments

Comments
 (0)