From 9a63a3c28da16e7559356c1ee7dde0f1e7cd146d Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Tue, 16 Jan 2024 07:45:48 -0800 Subject: [PATCH] Fix shadowed variable in faiss/IndexFastScan.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: meyering Differential Revision: D52582914 fbshipit-source-id: edb3983635de4343c4a0b20096e81852cfa058c6 --- faiss/IndexFastScan.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/faiss/IndexFastScan.cpp b/faiss/IndexFastScan.cpp index ca02af4168..2dfb2f55fd 100644 --- a/faiss/IndexFastScan.cpp +++ b/faiss/IndexFastScan.cpp @@ -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; }