Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/5249
Before this change, Top1BlockResultHandler::begin_multiple initialized
dis_tab[i] to C::neutral() but left ids_tab[i] uninitialized for every
query slot. This was inconsistent with two related code paths in the same
class:
1. SingleResultHandler::begin() (the per-query API) explicitly sets
min_idx = -1 before accumulating results.
2. HeapBlockResultHandler::begin_multiple() calls heap_heapify<C>()
which sets ids_tab[i*k + j] = -1 for all k result slots.
The inconsistency means that any caller invoking begin_multiple +
end_multiple without an intervening add_results — for example, when
the database is empty and there are no results to report — reads
uninitialized memory from ids_tab instead of the expected -1 sentinel.
Fix: add ids_tab[i] = -1 inside the begin_multiple loop, making the
block API consistent with the single-query API and with the Heap handler.
This is a strictly additive, zero-risk change: in the normal path where
add_results is called and covers all queries, the -1 is overwritten
with the actual winner index before end_multiple returns.
Test: TestTop1BlockResultHandler/BeginMultipleInitializesIds — calls
begin_multiple(0, nq) followed by end_multiple() with no add_results,
then verifies every ids_tab[i] == -1 and dis_tab[i] == C::neutral().
Reviewed By: junjieqi
Differential Revision: D106359898
fbshipit-source-id: f864016703aa98b0c3ff6226968bb61f361a45f7