@@ -64,16 +64,25 @@ struct SIMDResultHandlerToFloat : SIMDResultHandler {
6464 nullptr ; // table of biases to add to each query (for IVF L2 search)
6565 const float * normalizers = nullptr ; // size 2 * nq, to convert
6666
67+ size_t scan_cnt = 0 ; // scanned vector number (except filtered)
68+
6769 SIMDResultHandlerToFloat (size_t nq, size_t ntotal) : nq(nq), ntotal(ntotal) {}
6870
6971 virtual void begin (const float * norms) {
7072 normalizers = norms;
73+ scan_cnt = 0 ;
7174 }
7275
7376 // called at end of search to convert int16 distances to float, before
7477 // normalizers are deallocated
7578 virtual void end () {
7679 normalizers = nullptr ;
80+ scan_cnt = 0 ;
81+ }
82+
83+ // Get the number of scanned vectors
84+ size_t count_scanned_rows () {
85+ return scan_cnt;
7786 }
7887};
7988
@@ -293,6 +302,7 @@ struct SingleResultHandler : ResultHandlerCompare<C, with_id_map> {
293302 auto real_idx = this ->adjust_id (b, j);
294303 lt_mask -= 1 << j;
295304 if (this ->sel ->is_member (real_idx)) {
305+ this ->scan_cnt ++;
296306 T d = d32tab[j];
297307 if (C::cmp (idis[q], d)) {
298308 idis[q] = d;
@@ -310,6 +320,7 @@ struct SingleResultHandler : ResultHandlerCompare<C, with_id_map> {
310320 lt_mask -= 1 << j;
311321 T d = d32tab[j];
312322 if (C::cmp (idis[q], d)) {
323+ this ->scan_cnt ++;
313324 idis[q] = d;
314325 ids[q] = this ->adjust_id (b, j);
315326
@@ -329,6 +340,7 @@ struct SingleResultHandler : ResultHandlerCompare<C, with_id_map> {
329340 dis[q] = b + idis[q] * one_a;
330341 }
331342 }
343+ this ->scan_cnt = 0 ;
332344 }
333345};
334346
@@ -388,6 +400,7 @@ struct HeapHandler : ResultHandlerCompare<C, with_id_map> {
388400 auto real_idx = this ->adjust_id (b, j);
389401 lt_mask -= 1 << j;
390402 if (this ->sel ->is_member (real_idx)) {
403+ this ->scan_cnt ++;
391404 T dis = d32tab[j];
392405 if (C::cmp (heap_dis[0 ], dis)) {
393406 heap_replace_top<C>(k, heap_dis, heap_ids, dis, real_idx);
@@ -404,6 +417,7 @@ struct HeapHandler : ResultHandlerCompare<C, with_id_map> {
404417 lt_mask -= 1 << j;
405418 T dis = d32tab[j];
406419 if (C::cmp (heap_dis[0 ], dis)) {
420+ this ->scan_cnt ++;
407421 int64_t idx = this ->adjust_id (b, j);
408422 heap_replace_top<C>(k, heap_dis, heap_ids, dis, idx);
409423
@@ -431,6 +445,7 @@ struct HeapHandler : ResultHandlerCompare<C, with_id_map> {
431445 heap_ids[j] = heap_ids_in[j];
432446 }
433447 }
448+ this ->scan_cnt = 0 ;
434449 }
435450};
436451
@@ -500,7 +515,6 @@ struct SingleQueryResultCollectHandler : ResultHandlerCompare<C, with_id_map> {
500515 int64_t idx = this ->adjust_id (b, j);
501516 collect.emplace_back (idx, dis);
502517 this ->in_range_num += 1 ;
503-
504518 }
505519 }
506520 }
@@ -582,6 +596,7 @@ struct ReservoirHandler : ResultHandlerCompare<C, with_id_map> {
582596 auto real_idx = this ->adjust_id (b, j);
583597 lt_mask -= 1 << j;
584598 if (this ->sel ->is_member (real_idx)) {
599+ this ->scan_cnt ++;
585600 T dis = d32tab[j];
586601 res.add (dis, real_idx);
587602
@@ -595,6 +610,7 @@ struct ReservoirHandler : ResultHandlerCompare<C, with_id_map> {
595610 int j = __builtin_ctz (lt_mask);
596611 lt_mask -= 1 << j;
597612 T dis = d32tab[j];
613+ this ->scan_cnt ++;
598614 res.add (dis, this ->adjust_id (b, j));
599615
600616 this ->in_range_num += 1 ;
@@ -639,6 +655,7 @@ struct ReservoirHandler : ResultHandlerCompare<C, with_id_map> {
639655 // possibly add empty results
640656 heap_heapify<Cf>(n - res.i , heap_dis + res.i , heap_ids + res.i );
641657 }
658+ this ->scan_cnt = 0 ;
642659 }
643660};
644661
0 commit comments