Enable -Wstring-conversion in faiss/PACKAGE +1

Summary:
This diff enables compilation warning flags for the directory in question. Further details are in [this workplace post](https://fb.workplace.com/permalink.php?story_fbid=pfbid02XaWNiCVk69r1ghfvDVpujB8Hr9Y61uDvNakxiZFa2jwiPHscVdEQwCBHrmWZSyMRl&id=100051201402394).

This is a low-risk diff. There are **no run-time effects** and the diff has already been observed to compile locally. **If the code compiles, it work; test errors are spurious.**

Differential Revision: D92431717

fbshipit-source-id: b49a9b0870aeffa03334b61b32a02ba4fb71de6b
This commit is contained in:
Richard Barnes
2026-02-11 09:14:45 -08:00
committed by meta-codesync[bot]
parent edc235cb08
commit 948cf35ace
5 changed files with 23 additions and 21 deletions
+8 -8
View File
@@ -39,19 +39,19 @@ float* fvecs_read(const char* fname, size_t* d_out, size_t* n_out) {
}
int d;
fread(&d, 1, sizeof(int), f);
assert((d > 0 && d < 1000000) || !"unreasonable dimension");
assert((d > 0 && d < 1000000) && "unreasonable dimension");
fseek(f, 0, SEEK_SET);
struct stat st;
fstat(fileno(f), &st);
size_t sz = st.st_size;
assert(sz % ((d + 1) * 4) == 0 || !"weird file size");
assert(sz % ((d + 1) * 4) == 0 && "weird file size");
size_t n = sz / ((d + 1) * 4);
*d_out = d;
*n_out = n;
float* x = new float[n * (d + 1)];
size_t nr __attribute__((unused)) = fread(x, sizeof(float), n * (d + 1), f);
assert(nr == n * (d + 1) || !"could not read whole file");
assert(nr == n * (d + 1) && "could not read whole file");
// shift array to remove row headers
for (size_t i = 0; i < n; i++)
@@ -115,7 +115,7 @@ int main() {
size_t nb, d2;
float* xb = fvecs_read("sift1M/sift_base.fvecs", &d2, &nb);
assert(d == d2 || !"dataset does not have same dimension as train set");
assert(d == d2 && "dataset does not have same dimension as train set");
printf("[%.3f s] Indexing database, size %ld*%ld\n",
elapsed() - t0,
@@ -135,7 +135,7 @@ int main() {
size_t d2;
xq = fvecs_read("sift1M/sift_query.fvecs", &d2, &nq);
assert(d == d2 || !"query does not have same dimension as train set");
assert(d == d2 && "query does not have same dimension as train set");
}
size_t k; // nb of results per query in the GT
@@ -149,7 +149,7 @@ int main() {
// load ground-truth and convert int to long
size_t nq2;
int* gt_int = ivecs_read("sift1M/sift_groundtruth.ivecs", &k, &nq2);
assert(nq2 == nq || !"incorrect nb of ground truth entries");
assert(nq2 == nq && "incorrect nb of ground truth entries");
gt = new faiss::idx_t[k * nq];
for (int i = 0; i < k * nq; i++) {
@@ -198,8 +198,8 @@ int main() {
break;
}
}
assert(selected_params.size() >= 0 ||
!"could not find good enough op point");
assert(selected_params.size() >= 0 &&
"could not find good enough op point");
}
{ // Use the found configuration to perform a search
+1 -1
View File
@@ -64,7 +64,7 @@ void ToCPUCloner::merge_index(Index* dst, Index* src, bool successive_ids) {
FAISS_ASSERT(ifl2);
ifl->merge_from(*ifl2, successive_ids ? ifl->ntotal : 0);
} else {
FAISS_ASSERT(!"merging not implemented for this type of class");
FAISS_ASSERT(false && "merging not implemented for this type of class");
}
}
+8 -8
View File
@@ -585,7 +585,7 @@ SVSStorageKind parse_lvq(const std::string& lvq_string) {
if (lvq_string == "LVQ4x8") {
return SVSStorageKind::SVS_LVQ4x8;
}
FAISS_ASSERT(!"not supported SVS LVQ level");
FAISS_ASSERT(false && "not supported SVS LVQ level");
}
SVSStorageKind parse_leanvec(const std::string& leanvec_string) {
@@ -598,7 +598,7 @@ SVSStorageKind parse_leanvec(const std::string& leanvec_string) {
if (leanvec_string == "LeanVec8x8") {
return SVSStorageKind::SVS_LeanVec8x8;
}
FAISS_ASSERT(!"not supported SVS Leanvec level");
FAISS_ASSERT(false && "not supported SVS Leanvec level");
}
Index* parse_svs_datatype(
@@ -616,28 +616,28 @@ Index* parse_svs_datatype(
if (index_type == "Flat") {
return new IndexSVSFlat(d, mt);
}
FAISS_ASSERT(!"Unspported SVS index type");
FAISS_ASSERT(false && "Unspported SVS index type");
}
if (re_match(datatype_string, "FP16", sm)) {
if (index_type == "Vamana") {
return new IndexSVSVamana(
d, std::stoul(arg_string), mt, SVSStorageKind::SVS_FP16);
}
FAISS_ASSERT(!"Unspported SVS index type for Float16");
FAISS_ASSERT(false && "Unspported SVS index type for Float16");
}
if (re_match(datatype_string, "SQI8", sm)) {
if (index_type == "Vamana") {
return new IndexSVSVamana(
d, std::stoul(arg_string), mt, SVSStorageKind::SVS_SQI8);
}
FAISS_ASSERT(!"Unspported SVS index type for SQI8");
FAISS_ASSERT(false && "Unspported SVS index type for SQI8");
}
if (re_match(datatype_string, "(LVQ[0-9]+x[0-9]+)", sm)) {
if (index_type == "Vamana") {
return new IndexSVSVamanaLVQ(
d, std::stoul(arg_string), mt, parse_lvq(sm[0].str()));
}
FAISS_ASSERT(!"Unspported SVS index type for LVQ");
FAISS_ASSERT(false && "Unspported SVS index type for LVQ");
}
if (re_match(datatype_string, "(LeanVec[0-9]+x[0-9]+)(_[0-9]+)?", sm)) {
std::string leanvec_d_string =
@@ -652,7 +652,7 @@ Index* parse_svs_datatype(
leanvec_d,
parse_leanvec(sm[1].str()));
}
FAISS_ASSERT(!"Unspported SVS index type for LeanVec");
FAISS_ASSERT(false && "Unspported SVS index type for LeanVec");
}
return nullptr;
}
@@ -672,7 +672,7 @@ Index* parse_IndexSVS(const std::string& code_string, int d, MetricType mt) {
"Vamana", degree_string, datatype_string, d, mt);
}
if (re_match(code_string, "IVF([0-9]+)(,.+)?", sm)) {
FAISS_ASSERT(!"Unspported SVS index type");
FAISS_ASSERT(false && "Unspported SVS index type");
}
return nullptr;
}
+5 -3
View File
@@ -66,7 +66,7 @@ inline svs_runtime::MetricType to_svs_metric(faiss::MetricType metric) {
case METRIC_L2:
return svs_runtime::MetricType::L2;
default:
FAISS_ASSERT(!"not supported SVS distance");
FAISS_ASSERT(false && "not supported SVS distance");
}
}
@@ -93,7 +93,8 @@ template <typename T, typename U, typename = void>
struct InputBufferConverter {
InputBufferConverter(std::span<const U> data = {}) : buffer(data.size()) {
FAISS_ASSERT(
!"InputBufferConverter: there is no suitable user code for this type conversion");
false &&
"InputBufferConverter: there is no suitable user code for this type conversion");
std::transform(
data.begin(), data.end(), buffer.begin(), [](const U& val) {
return static_cast<T>(val);
@@ -153,7 +154,8 @@ struct OutputBufferConverter {
OutputBufferConverter(std::span<U> data = {})
: data_span(data), buffer(data.size()) {
FAISS_ASSERT(
!"OutputBufferConverter: there is no suitable user code for this type conversion");
false &&
"OutputBufferConverter: there is no suitable user code for this type conversion");
}
~OutputBufferConverter() {
+1 -1
View File
@@ -71,7 +71,7 @@ inline svs_runtime::StorageKind to_svs_storage_kind(SVSStorageKind kind) {
case SVS_LeanVec8x8:
return svs_runtime::StorageKind::LeanVec8x8;
default:
FAISS_ASSERT(!"not supported SVS storage kind");
FAISS_ASSERT(false && "not supported SVS storage kind");
}
}