@@ -34,18 +34,20 @@ IndexIVFAdditiveQuantizerFastScan::IndexIVFAdditiveQuantizerFastScan(
3434 size_t d,
3535 size_t nlist,
3636 MetricType metric,
37- int bbs)
38- : IndexIVFFastScan(quantizer, d, nlist, 0 , metric) {
37+ int bbs,
38+ bool own_invlists)
39+ : IndexIVFFastScan(quantizer, d, nlist, 0 , metric, own_invlists) {
3940 if (aq != nullptr ) {
40- init (aq, nlist, metric, bbs);
41+ init (aq, nlist, metric, bbs, own_invlists );
4142 }
4243}
4344
4445void IndexIVFAdditiveQuantizerFastScan::init (
4546 AdditiveQuantizer* aq,
4647 size_t nlist,
4748 MetricType metric,
48- int bbs) {
49+ int bbs,
50+ bool own_invlists) {
4951 FAISS_THROW_IF_NOT (aq != nullptr );
5052 FAISS_THROW_IF_NOT (!aq->nbits .empty ());
5153 FAISS_THROW_IF_NOT (aq->nbits [0 ] == 4 );
@@ -66,7 +68,7 @@ void IndexIVFAdditiveQuantizerFastScan::init(
6668 } else {
6769 M = aq->M ;
6870 }
69- init_fastscan (aq, M, 4 , nlist, metric, bbs);
71+ init_fastscan (aq, M, 4 , nlist, metric, bbs, own_invlists );
7072
7173 max_train_points = 1024 * ksub * M;
7274 by_residual = true ;
@@ -80,17 +82,20 @@ IndexIVFAdditiveQuantizerFastScan::IndexIVFAdditiveQuantizerFastScan(
8082 orig.d,
8183 orig.nlist,
8284 0 ,
83- orig.metric_type),
85+ orig.metric_type,
86+ orig.own_invlists),
8487 aq (orig.aq) {
8588 FAISS_THROW_IF_NOT (
8689 metric_type == METRIC_INNER_PRODUCT || !orig.by_residual );
8790
88- init (aq, nlist, metric_type, bbs);
91+ init (aq, nlist, metric_type, bbs, own_invlists );
8992
9093 is_trained = orig.is_trained ;
9194 ntotal = orig.ntotal ;
9295 nprobe = orig.nprobe ;
93-
96+ if (!orig.own_invlists ) {
97+ return ; // skip packing codes below
98+ }
9499 for (size_t i = 0 ; i < nlist; i++) {
95100 size_t nb = orig.invlists ->list_size (i);
96101 size_t nb2 = roundup (nb, bbs);
@@ -448,17 +453,19 @@ IndexIVFLocalSearchQuantizerFastScan::IndexIVFLocalSearchQuantizerFastScan(
448453 size_t nbits,
449454 MetricType metric,
450455 Search_type_t search_type,
451- int bbs)
456+ int bbs,
457+ bool own_invlists)
452458 : IndexIVFAdditiveQuantizerFastScan(
453459 quantizer,
454460 nullptr ,
455461 d,
456462 nlist,
457463 metric,
458- bbs),
464+ bbs,
465+ own_invlists),
459466 lsq(d, M, nbits, search_type) {
460467 FAISS_THROW_IF_NOT (nbits == 4 );
461- init (&lsq, nlist, metric, bbs);
468+ init (&lsq, nlist, metric, bbs, own_invlists );
462469}
463470
464471IndexIVFLocalSearchQuantizerFastScan::IndexIVFLocalSearchQuantizerFastScan () {
@@ -474,17 +481,19 @@ IndexIVFResidualQuantizerFastScan::IndexIVFResidualQuantizerFastScan(
474481 size_t nbits,
475482 MetricType metric,
476483 Search_type_t search_type,
477- int bbs)
484+ int bbs,
485+ bool own_invlists)
478486 : IndexIVFAdditiveQuantizerFastScan(
479487 quantizer,
480488 nullptr ,
481489 d,
482490 nlist,
483491 metric,
484- bbs),
492+ bbs,
493+ own_invlists),
485494 rq(d, M, nbits, search_type) {
486495 FAISS_THROW_IF_NOT (nbits == 4 );
487- init (&rq, nlist, metric, bbs);
496+ init (&rq, nlist, metric, bbs, own_invlists );
488497}
489498
490499IndexIVFResidualQuantizerFastScan::IndexIVFResidualQuantizerFastScan () {
@@ -502,17 +511,19 @@ IndexIVFProductLocalSearchQuantizerFastScan::
502511 size_t nbits,
503512 MetricType metric,
504513 Search_type_t search_type,
505- int bbs)
514+ int bbs,
515+ bool own_invlists)
506516 : IndexIVFAdditiveQuantizerFastScan(
507517 quantizer,
508518 nullptr ,
509519 d,
510520 nlist,
511521 metric,
512- bbs),
522+ bbs,
523+ own_invlists),
513524 plsq(d, nsplits, Msub, nbits, search_type) {
514525 FAISS_THROW_IF_NOT (nbits == 4 );
515- init (&plsq, nlist, metric, bbs);
526+ init (&plsq, nlist, metric, bbs, own_invlists );
516527}
517528
518529IndexIVFProductLocalSearchQuantizerFastScan::
@@ -531,17 +542,19 @@ IndexIVFProductResidualQuantizerFastScan::
531542 size_t nbits,
532543 MetricType metric,
533544 Search_type_t search_type,
534- int bbs)
545+ int bbs,
546+ bool own_invlists)
535547 : IndexIVFAdditiveQuantizerFastScan(
536548 quantizer,
537549 nullptr ,
538550 d,
539551 nlist,
540552 metric,
541- bbs),
553+ bbs,
554+ own_invlists),
542555 prq(d, nsplits, Msub, nbits, search_type) {
543556 FAISS_THROW_IF_NOT (nbits == 4 );
544- init (&prq, nlist, metric, bbs);
557+ init (&prq, nlist, metric, bbs, own_invlists );
545558}
546559
547560IndexIVFProductResidualQuantizerFastScan::
0 commit comments