From: =?utf-8?q?Timo_R=C3=B6hling?= <roehling@debian.org>
Date: Wed, 9 Feb 2022 01:28:47 +0100
Subject: Fix implementation for 32 bit size_t
Forwarded: not-needed
---
 faiss/IndexIVF.cpp                     | 2 +-
 faiss/IndexIVFIndependentQuantizer.cpp | 2 +-
 faiss/index_factory.cpp                | 2 +-
 faiss/invlists/OnDiskInvertedLists.cpp | 4 ++--
 faiss/utils/utils.cpp                  | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)

--- a/faiss/IndexIVF.cpp
+++ b/faiss/IndexIVF.cpp
@@ -1168,7 +1168,7 @@
     // optional subsampling
     idx_t max_nt = train_encoder_num_vectors();
     if (max_nt <= 0) {
-        max_nt = (size_t)1 << 35;
+        max_nt = (size_t)1 << 30;
     }
 
     TransformedVectors tv(
--- a/faiss/IndexIVFIndependentQuantizer.cpp
+++ b/faiss/IndexIVFIndependentQuantizer.cpp
@@ -140,7 +140,7 @@
     // optional subsampling
     idx_t max_nt = index_ivf->train_encoder_num_vectors();
     if (max_nt <= 0) {
-        max_nt = (size_t)1 << 35;
+        max_nt = (size_t)1 << 30;
     }
     SubsampledVectors sv(index_ivf->d, &n, max_nt, x);
 
--- a/faiss/invlists/OnDiskInvertedLists.cpp
+++ b/faiss/invlists/OnDiskInvertedLists.cpp
@@ -326,7 +326,7 @@
 
     FAISS_THROW_IF_NOT_FMT(
             err == 0,
-            "truncate %s to %ld: %s",
+            "truncate %s to %zu: %s",
             filename.c_str(),
             totsize,
             strerror(errno));
@@ -527,7 +527,7 @@
         it++;
     }
 
-    size_t inf = ((size_t)1) << 60;
+    size_t inf = size_t(1) << (8 * __SIZEOF_SIZE_T__ - 2);
 
     size_t end_prev = inf;
     if (it != slots.begin()) {
@@ -536,7 +536,7 @@
         end_prev = prev->offset + prev->capacity;
     }
 
-    size_t begin_next = ((size_t)1) << 60;
+    size_t begin_next = inf;
     if (it != slots.end()) {
         begin_next = it->offset;
     }
--- a/faiss/utils/utils.cpp
+++ b/faiss/utils/utils.cpp
@@ -173,7 +173,7 @@
         char buf[256];
         if (!fgets(buf, 256, f))
             break;
-        if (sscanf(buf, "VmRSS: %ld kB", &sz) == 1)
+        if (sscanf(buf, "VmRSS: %zu kB", &sz) == 1)
             break;
     }
     fclose(f);
--- a/tests/test_approx_topk.cpp
+++ b/tests/test_approx_topk.cpp
@@ -161,7 +161,7 @@
     }
 
     if (verbose) {
-        printf("%d, %d, %d, %d, %d, %d: %ld, %ld, %ld, %f, %ld, %ld, %f, %f\n",
+        printf("%d, %d, %d, %d, %d, %d: %zu, %zu, %zu, %f, %zu, %zu, %f, %f\n",
                NBUCKETS,
                N,
                beamSize,
--- a/tests/test_mem_leak.cpp
+++ b/tests/test_mem_leak.cpp
@@ -52,7 +52,7 @@
                     D.data(),
                     I.data());
             if (i % 100 == 0) {
-                printf("[%.2f s] BS %d %d: %ld kB %.2f bytes/it\r",
+                printf("[%.2f s] BS %d %d: %zu kB %.2f bytes/it\r",
                        (getmillisecs() - t0) / 1000,
                        bs,
                        i,
