Skip to content

Commit 3973017

Browse files
r-barnesfacebook-github-bot
authored andcommitted
Fix shadowed variable in faiss/IndexBinaryIVF.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: palmje Differential Revision: D52582927 fbshipit-source-id: be03fb1354898d0637d287f285ea99d096c39008
1 parent 46320e0 commit 3973017

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

faiss/IndexBinaryIVF.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,16 @@ void IndexBinaryIVF::search(
119119
FAISS_THROW_IF_NOT(k > 0);
120120
FAISS_THROW_IF_NOT(nprobe > 0);
121121

122-
const size_t nprobe = std::min(nlist, this->nprobe);
123-
std::unique_ptr<idx_t[]> idx(new idx_t[n * nprobe]);
124-
std::unique_ptr<int32_t[]> coarse_dis(new int32_t[n * nprobe]);
122+
const size_t nprobe_2 = std::min(nlist, this->nprobe);
123+
std::unique_ptr<idx_t[]> idx(new idx_t[n * nprobe_2]);
124+
std::unique_ptr<int32_t[]> coarse_dis(new int32_t[n * nprobe_2]);
125125

126126
double t0 = getmillisecs();
127-
quantizer->search(n, x, nprobe, coarse_dis.get(), idx.get());
127+
quantizer->search(n, x, nprobe_2, coarse_dis.get(), idx.get());
128128
indexIVF_stats.quantization_time += getmillisecs() - t0;
129129

130130
t0 = getmillisecs();
131-
invlists->prefetch_lists(idx.get(), n * nprobe);
131+
invlists->prefetch_lists(idx.get(), n * nprobe_2);
132132

133133
search_preassigned(
134134
n, x, k, idx.get(), coarse_dis.get(), distances, labels, false);
@@ -169,16 +169,16 @@ void IndexBinaryIVF::search_and_reconstruct(
169169
const SearchParameters* params) const {
170170
FAISS_THROW_IF_NOT_MSG(
171171
!params, "search params not supported for this index");
172-
const size_t nprobe = std::min(nlist, this->nprobe);
172+
const size_t nprobe_2 = std::min(nlist, this->nprobe);
173173
FAISS_THROW_IF_NOT(k > 0);
174-
FAISS_THROW_IF_NOT(nprobe > 0);
174+
FAISS_THROW_IF_NOT(nprobe_2 > 0);
175175

176-
std::unique_ptr<idx_t[]> idx(new idx_t[n * nprobe]);
177-
std::unique_ptr<int32_t[]> coarse_dis(new int32_t[n * nprobe]);
176+
std::unique_ptr<idx_t[]> idx(new idx_t[n * nprobe_2]);
177+
std::unique_ptr<int32_t[]> coarse_dis(new int32_t[n * nprobe_2]);
178178

179-
quantizer->search(n, x, nprobe, coarse_dis.get(), idx.get());
179+
quantizer->search(n, x, nprobe_2, coarse_dis.get(), idx.get());
180180

181-
invlists->prefetch_lists(idx.get(), n * nprobe);
181+
invlists->prefetch_lists(idx.get(), n * nprobe_2);
182182

183183
// search_preassigned() with `store_pairs` enabled to obtain the list_no
184184
// and offset into `codes` for reconstruction
@@ -321,8 +321,8 @@ struct IVFBinaryScannerL2 : BinaryInvertedListScanner {
321321
}
322322

323323
idx_t list_no;
324-
void set_list(idx_t list_no, uint8_t /* coarse_dis */) override {
325-
this->list_no = list_no;
324+
void set_list(idx_t list_no_2, uint8_t /* coarse_dis */) override {
325+
this->list_no = list_no_2;
326326
}
327327

328328
uint32_t distance_to_code(const uint8_t* code) const override {
@@ -812,16 +812,16 @@ void IndexBinaryIVF::range_search(
812812
const SearchParameters* params) const {
813813
FAISS_THROW_IF_NOT_MSG(
814814
!params, "search params not supported for this index");
815-
const size_t nprobe = std::min(nlist, this->nprobe);
816-
std::unique_ptr<idx_t[]> idx(new idx_t[n * nprobe]);
817-
std::unique_ptr<int32_t[]> coarse_dis(new int32_t[n * nprobe]);
815+
const size_t nprobe_2 = std::min(nlist, this->nprobe);
816+
std::unique_ptr<idx_t[]> idx(new idx_t[n * nprobe_2]);
817+
std::unique_ptr<int32_t[]> coarse_dis(new int32_t[n * nprobe_2]);
818818

819819
double t0 = getmillisecs();
820-
quantizer->search(n, x, nprobe, coarse_dis.get(), idx.get());
820+
quantizer->search(n, x, nprobe_2, coarse_dis.get(), idx.get());
821821
indexIVF_stats.quantization_time += getmillisecs() - t0;
822822

823823
t0 = getmillisecs();
824-
invlists->prefetch_lists(idx.get(), n * nprobe);
824+
invlists->prefetch_lists(idx.get(), n * nprobe_2);
825825

826826
range_search_preassigned(n, x, radius, idx.get(), coarse_dis.get(), res);
827827

@@ -835,7 +835,7 @@ void IndexBinaryIVF::range_search_preassigned(
835835
const idx_t* __restrict assign,
836836
const int32_t* __restrict centroid_dis,
837837
RangeSearchResult* __restrict res) const {
838-
const size_t nprobe = std::min(nlist, this->nprobe);
838+
const size_t nprobe_2 = std::min(nlist, this->nprobe);
839839
bool store_pairs = false;
840840
size_t nlistv = 0, ndis = 0;
841841

@@ -851,7 +851,7 @@ void IndexBinaryIVF::range_search_preassigned(
851851
all_pres[omp_get_thread_num()] = &pres;
852852

853853
auto scan_list_func = [&](size_t i, size_t ik, RangeQueryResult& qres) {
854-
idx_t key = assign[i * nprobe + ik]; /* select the list */
854+
idx_t key = assign[i * nprobe_2 + ik]; /* select the list */
855855
if (key < 0)
856856
return;
857857
FAISS_THROW_IF_NOT_FMT(
@@ -868,7 +868,7 @@ void IndexBinaryIVF::range_search_preassigned(
868868
InvertedLists::ScopedCodes scodes(invlists, key);
869869
InvertedLists::ScopedIds ids(invlists, key);
870870

871-
scanner->set_list(key, assign[i * nprobe + ik]);
871+
scanner->set_list(key, assign[i * nprobe_2 + ik]);
872872
nlistv++;
873873
ndis += list_size;
874874
scanner->scan_codes_range(
@@ -881,7 +881,7 @@ void IndexBinaryIVF::range_search_preassigned(
881881

882882
RangeQueryResult& qres = pres.new_result(i);
883883

884-
for (size_t ik = 0; ik < nprobe; ik++) {
884+
for (size_t ik = 0; ik < nprobe_2; ik++) {
885885
scan_list_func(i, ik, qres);
886886
}
887887
}

0 commit comments

Comments
 (0)