@@ -83,7 +83,7 @@ void hnsw_add_vertices(
8383 }
8484
8585 std::vector<omp_lock_t > locks (ntotal);
86- for (int i = 0 ; i < ntotal; i++) {
86+ for (size_t i = 0 ; i < ntotal; i++) {
8787 omp_init_lock (&locks[i]);
8888 }
8989
@@ -94,23 +94,23 @@ void hnsw_add_vertices(
9494 { // make buckets with vectors of the same level
9595
9696 // build histogram
97- for (int i = 0 ; i < n; i++) {
97+ for (size_t i = 0 ; i < n; i++) {
9898 storage_idx_t pt_id = i + n0;
9999 int pt_level = hnsw.levels [pt_id] - 1 ;
100- while (pt_level >= hist.size ()) {
100+ while (pt_level >= static_cast < int >( hist.size () )) {
101101 hist.push_back (0 );
102102 }
103103 hist[pt_level]++;
104104 }
105105
106106 // accumulate
107107 std::vector<int > offsets (hist.size () + 1 , 0 );
108- for (int i = 0 ; i < hist.size () - 1 ; i++) {
108+ for (size_t i = 0 ; i < hist.size () - 1 ; i++) {
109109 offsets[i + 1 ] = offsets[i] + hist[i];
110110 }
111111
112112 // bucket sort
113- for (int i = 0 ; i < n; i++) {
113+ for (size_t i = 0 ; i < n; i++) {
114114 storage_idx_t pt_id = i + n0;
115115 int pt_level = hnsw.levels [pt_id] - 1 ;
116116 order[offsets[pt_level]++] = pt_id;
@@ -125,7 +125,7 @@ void hnsw_add_vertices(
125125
126126 int i1 = n;
127127
128- for (int pt_level = hist.size () - 1 ;
128+ for (int pt_level = static_cast < int >( hist.size () ) - 1 ;
129129 pt_level >= int (!index_hnsw.init_level0 );
130130 pt_level--) {
131131 int i0 = i1 - hist[pt_level];
@@ -200,7 +200,7 @@ void hnsw_add_vertices(
200200 printf (" Done in %.3f ms\n " , getmillisecs () - t0);
201201 }
202202
203- for (int i = 0 ; i < ntotal; i++) {
203+ for (size_t i = 0 ; i < ntotal; i++) {
204204 omp_destroy_lock (&locks[i]);
205205 }
206206}
@@ -211,11 +211,13 @@ void hnsw_add_vertices(
211211 * IndexHNSW implementation
212212 **************************************************************/
213213
214- IndexHNSW::IndexHNSW (int d , int M, MetricType metric)
215- : Index(d , metric), hnsw(M) {}
214+ IndexHNSW::IndexHNSW (int d_in , int M, MetricType metric)
215+ : Index(d_in , metric), hnsw(M) {}
216216
217- IndexHNSW::IndexHNSW (Index* storage, int M)
218- : Index(storage->d, storage->metric_type), hnsw(M), storage(storage) {
217+ IndexHNSW::IndexHNSW (Index* storage_in, int M)
218+ : Index(storage_in->d, storage_in->metric_type),
219+ hnsw (M),
220+ storage(storage_in) {
219221 metric_arg = storage->metric_arg ;
220222}
221223
@@ -309,7 +311,7 @@ void IndexHNSW::search(
309311
310312 if (is_similarity_metric (this ->metric_type )) {
311313 // we need to revert the negated distances
312- for (size_t i = 0 ; i < k * n; i++) {
314+ for (idx_t i = 0 ; i < k * n; i++) {
313315 distances[i] = -distances[i];
314316 }
315317 }
@@ -351,7 +353,13 @@ void IndexHNSW::add(idx_t n, const float* x) {
351353 storage->add (n, x);
352354 ntotal = storage->ntotal ;
353355
354- hnsw_add_vertices (*this , n0, n, x, verbose, hnsw.levels .size () == ntotal);
356+ hnsw_add_vertices (
357+ *this ,
358+ n0,
359+ n,
360+ x,
361+ verbose,
362+ hnsw.levels .size () == static_cast <size_t >(ntotal));
355363}
356364
357365void IndexHNSW::reset () {
@@ -427,7 +435,7 @@ void IndexHNSW::search_level_0(
427435 FAISS_THROW_IF_NOT (k > 0 );
428436 FAISS_THROW_IF_NOT (nprobe > 0 );
429437
430- storage_idx_t ntotal = hnsw.levels .size ();
438+ storage_idx_t hnsw_ntotal = hnsw.levels .size ();
431439
432440 using RH = HeapBlockResultHandler<HNSW::C>;
433441 RH bres (n, distances, labels, k);
@@ -437,7 +445,7 @@ void IndexHNSW::search_level_0(
437445 std::unique_ptr<DistanceComputer> qdis (
438446 storage_distance_computer (storage));
439447 HNSWStats search_stats;
440- VisitedTable vt (ntotal , hnsw.use_visited_hashset );
448+ VisitedTable vt (hnsw_ntotal , hnsw.use_visited_hashset );
441449 RH::SingleResultHandler res (bres);
442450
443451#pragma omp for
@@ -487,7 +495,7 @@ void IndexHNSW::init_level_0_from_knngraph(
487495
488496 std::priority_queue<NodeDistFarther> initial_list;
489497
490- for (size_t j = 0 ; j < k; j++) {
498+ for (int j = 0 ; j < k; j++) {
491499 int v1 = I[i * k + j];
492500 if (v1 == i) {
493501 continue ;
@@ -519,7 +527,7 @@ void IndexHNSW::init_level_0_from_entry_points(
519527 const storage_idx_t * points,
520528 const storage_idx_t * nearests) {
521529 std::vector<omp_lock_t > locks (ntotal);
522- for (int i = 0 ; i < ntotal; i++) {
530+ for (idx_t i = 0 ; i < ntotal; i++) {
523531 omp_init_lock (&locks[i]);
524532 }
525533
@@ -551,7 +559,7 @@ void IndexHNSW::init_level_0_from_entry_points(
551559 printf (" \n " );
552560 }
553561
554- for (int i = 0 ; i < ntotal; i++) {
562+ for (idx_t i = 0 ; i < ntotal; i++) {
555563 omp_destroy_lock (&locks[i]);
556564 }
557565}
@@ -595,7 +603,7 @@ void IndexHNSW::link_singletons() {
595603
596604 std::vector<bool > seen (ntotal);
597605
598- for (size_t i = 0 ; i < ntotal; i++) {
606+ for (idx_t i = 0 ; i < ntotal; i++) {
599607 size_t begin, end;
600608 hnsw.neighbor_range (i, 0 , &begin, &end);
601609 for (size_t j = begin; j < end; j++) {
@@ -624,7 +632,7 @@ void IndexHNSW::link_singletons() {
624632 n_sing_l1);
625633
626634 std::vector<float > recons (singletons.size () * d);
627- for (int i = 0 ; i < singletons.size (); i++) {
635+ for (size_t i = 0 ; i < singletons.size (); i++) {
628636 FAISS_ASSERT (false ); // not implemented
629637 }
630638}
@@ -649,10 +657,10 @@ IndexHNSWFlat::IndexHNSWFlat() {
649657 is_trained = true ;
650658}
651659
652- IndexHNSWFlat::IndexHNSWFlat (int d , int M, MetricType metric)
660+ IndexHNSWFlat::IndexHNSWFlat (int d_in , int M, MetricType metric)
653661 : IndexHNSW(
654- (metric == METRIC_L2) ? new IndexFlatL2(d )
655- : new IndexFlat(d , metric),
662+ (metric == METRIC_L2) ? new IndexFlatL2(d_in )
663+ : new IndexFlat(d_in , metric),
656664 M) {
657665 own_fields = true ;
658666 is_trained = true ;
@@ -666,14 +674,14 @@ IndexHNSWFlatPanorama::IndexHNSWFlatPanorama()
666674 : IndexHNSWFlat(), cum_sums(), pano(0 , 1 , 1 ), num_panorama_levels(0 ) {}
667675
668676IndexHNSWFlatPanorama::IndexHNSWFlatPanorama (
669- int d ,
677+ int d_in ,
670678 int M,
671- int num_panorama_levels ,
679+ int num_panorama_levels_in ,
672680 MetricType metric)
673- : IndexHNSWFlat(d , M, metric),
681+ : IndexHNSWFlat(d_in , M, metric),
674682 cum_sums (),
675- pano(d * sizeof (float ), num_panorama_levels , 1),
676- num_panorama_levels(num_panorama_levels ) {
683+ pano(d_in * sizeof (float ), num_panorama_levels_in , 1),
684+ num_panorama_levels(num_panorama_levels_in ) {
677685 // For now, we only support L2 distance.
678686 // Supporting dot product and cosine distance is a trivial addition
679687 // left for future work.
@@ -718,12 +726,12 @@ void IndexHNSWFlatPanorama::permute_entries(const idx_t* perm) {
718726IndexHNSWPQ::IndexHNSWPQ () = default;
719727
720728IndexHNSWPQ::IndexHNSWPQ (
721- int d ,
729+ int d_in ,
722730 int pq_m,
723731 int M,
724732 int pq_nbits,
725733 MetricType metric)
726- : IndexHNSW(new IndexPQ(d , pq_m, pq_nbits, metric), M) {
734+ : IndexHNSW(new IndexPQ(d_in , pq_m, pq_nbits, metric), M) {
727735 own_fields = true ;
728736 is_trained = false ;
729737}
@@ -738,11 +746,11 @@ void IndexHNSWPQ::train(idx_t n, const float* x) {
738746 **************************************************************/
739747
740748IndexHNSWSQ::IndexHNSWSQ (
741- int d ,
749+ int d_in ,
742750 ScalarQuantizer::QuantizerType qtype,
743751 int M,
744752 MetricType metric)
745- : IndexHNSW(new IndexScalarQuantizer(d , qtype, metric), M) {
753+ : IndexHNSW(new IndexScalarQuantizer(d_in , qtype, metric), M) {
746754 is_trained = this ->storage ->is_trained ;
747755 own_fields = true ;
748756}
@@ -900,7 +908,7 @@ void IndexHNSW2Level::search(
900908 size_t list_length = index_ivfpq->get_list_size (key);
901909 const idx_t * ids = index_ivfpq->invlists ->get_ids (key);
902910
903- for (int jj = 0 ; jj < list_length; jj++) {
911+ for (size_t jj = 0 ; jj < list_length; jj++) {
904912 vt.set (ids[jj]);
905913 }
906914 }
@@ -976,11 +984,11 @@ IndexHNSWCagra::IndexHNSWCagra() {
976984}
977985
978986IndexHNSWCagra::IndexHNSWCagra (
979- int d ,
987+ int d_in ,
980988 int M,
981989 MetricType metric,
982990 NumericType numeric_type)
983- : IndexHNSW(d , M, metric) {
991+ : IndexHNSW(d_in , M, metric) {
984992 FAISS_THROW_IF_NOT_MSG (
985993 ((metric == METRIC_L2) || (metric == METRIC_INNER_PRODUCT)),
986994 " unsupported metric type for IndexHNSWCagra" );
0 commit comments