From 25296bad4f726aacff414a1f467f8a5f6eb0e306 Mon Sep 17 00:00:00 2001 From: Alibek Zhakubayev Date: Tue, 7 Apr 2026 15:41:37 -0700 Subject: [PATCH] Fix type mismatch bug and remove dead code in IndexRowwiseMinMax::sa_decode_impl (#5051) Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/5051 In `sa_decode_impl()`, a local variable `std::vector minmax(...)` was: 1. Using the wrong type: It hardcoded `StorageMinMaxFP16` instead of the template parameter `StorageMinMaxT`. When this function is instantiated with `StorageMinMaxFP32` (via `IndexRowwiseMinMax::sa_decode`), this would create a vector of the wrong type. 2. Dead code: The vector was allocated but never actually used in the function body. The decoding logic reads `StorageMinMaxT` values directly from the input byte buffer, making this allocation unnecessary. This change removes the unused variable, eliminating both the type mismatch and the unnecessary memory allocation. The allocation was O(min(chunk_size, n)) per decode call, so removing it also provides a minor performance benefit. Note: The corresponding `sa_encode_impl` function does NOT have this issue (it correctly uses a local `minmax` that IS used), and the `train_inplace_impl` / `train_impl` functions also correctly use their `minmax` vectors. Only `sa_decode_impl` had this issue. Reviewed By: mnorris11 Differential Revision: D99851973 fbshipit-source-id: a288a4cd355ccc7d9e13d1f7d61bc54fc524675c --- faiss/IndexRowwiseMinMax.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/faiss/IndexRowwiseMinMax.cpp b/faiss/IndexRowwiseMinMax.cpp index 9c7de1424..afc243f6f 100644 --- a/faiss/IndexRowwiseMinMax.cpp +++ b/faiss/IndexRowwiseMinMax.cpp @@ -166,11 +166,6 @@ void sa_decode_impl( ? chunk_size : static_cast(n_input)) * old_code_size); - std::vector minmax( - (chunk_size < static_cast(n_input) - ? chunk_size - : static_cast(n_input))); - // all the elements to process size_t n_left = n_input;