Skip to content

Commit f030398

Browse files
gtwang01facebook-github-bot
authored andcommitted
Address compile errors and warnings (#4238)
Summary: Nightly has been broken and PRs have been blocked: https://github.com/facebookresearch/faiss/actions/runs/13798181461/job/38595760879?pr=4055 There are compiler errors in Autotune.cpp and warnings in some other files that this diff seeks to address. Differential Revision: D71135388
1 parent 15491a1 commit f030398

4 files changed

Lines changed: 14 additions & 17 deletions

File tree

faiss/AutoTune.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include <cinttypes>
1717
#include <cmath>
18-
#include <typeinfo>
1918

2019
#include <faiss/impl/FaissAssert.h>
2120
#include <faiss/utils/random.h>
@@ -313,9 +312,6 @@ bool ParameterSpace::combination_ge(size_t c1, size_t c2) const {
313312
return true;
314313
}
315314

316-
#define DC(classname) \
317-
[[maybe_unused]] const classname* ix = dynamic_cast<const classname*>(index)
318-
319315
static void init_pq_ParameterRange(
320316
const ProductQuantizer& pq,
321317
ParameterRange& pr) {
@@ -339,6 +335,10 @@ ParameterRange& ParameterSpace::add_range(const std::string& name) {
339335
return parameter_ranges.back();
340336
}
341337

338+
// Do not use this macro if ix will be unused
339+
#define DC(classname) \
340+
const classname* ix = dynamic_cast<const classname*>(index)
341+
342342
/// initialize with reasonable parameters for this type of index
343343
void ParameterSpace::initialize(const Index* index) {
344344
if (DC(IndexPreTransform)) {
@@ -394,7 +394,7 @@ void ParameterSpace::initialize(const Index* index) {
394394
std::numeric_limits<double>::infinity());
395395
}
396396
}
397-
if (DC(IndexIVFPQR)) {
397+
if (dynamic_cast<const IndexIVFPQR*>(index)) {
398398
ParameterRange& pr = add_range("k_factor");
399399
for (int i = 0; i <= 6; i++) {
400400
pr.values.push_back(1 << i);
@@ -410,9 +410,6 @@ void ParameterSpace::initialize(const Index* index) {
410410

411411
#undef DC
412412

413-
// non-const version
414-
#define DC(classname) classname* ix = dynamic_cast<classname*>(index)
415-
416413
/// set a combination of parameters on an index
417414
void ParameterSpace::set_index_parameters(Index* index, size_t cno) const {
418415
for (int i = 0; i < parameter_ranges.size(); i++) {
@@ -442,6 +439,10 @@ void ParameterSpace::set_index_parameters(
442439
}
443440
}
444441

442+
// non-const version
443+
// Do not use this macro if ix will be unused
444+
#define DC(classname) classname* ix = dynamic_cast<classname*>(index)
445+
445446
void ParameterSpace::set_index_parameter(
446447
Index* index,
447448
const std::string& name,
@@ -574,6 +575,8 @@ void ParameterSpace::set_index_parameter(
574575
name.c_str());
575576
}
576577

578+
#undef DC
579+
577580
void ParameterSpace::display() const {
578581
printf("ParameterSpace, %zd parameters, %zd combinations:\n",
579582
parameter_ranges.size(),

faiss/IndexHNSW.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
#include <faiss/IndexHNSW.h>
99

1010
#include <omp.h>
11-
#include <cassert>
1211
#include <cinttypes>
13-
#include <cmath>
1412
#include <cstdio>
1513
#include <cstdlib>
1614
#include <cstring>
@@ -124,7 +122,7 @@ void hnsw_add_vertices(
124122
int i1 = n;
125123

126124
for (int pt_level = hist.size() - 1;
127-
pt_level >= !index_hnsw.init_level0;
125+
pt_level >= int(!index_hnsw.init_level0);
128126
pt_level--) {
129127
int i0 = i1 - hist[pt_level];
130128

faiss/impl/HNSW.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <faiss/impl/HNSW.h>
99

1010
#include <cstddef>
11-
#include <string>
1211

1312
#include <faiss/impl/AuxIndexStructures.h>
1413
#include <faiss/impl/DistanceComputer.h>

faiss/index_factory.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
#include <faiss/index_factory.h>
1313

14-
#include <cinttypes>
15-
#include <cmath>
16-
1714
#include <map>
1815

1916
#include <regex>
@@ -164,7 +161,7 @@ const std::string aq_norm_pattern =
164161
const std::string paq_def_pattern = "([0-9]+)x([0-9]+)x([0-9]+)";
165162

166163
AdditiveQuantizer::Search_type_t aq_parse_search_type(
167-
std::string stok,
164+
const std::string& stok,
168165
MetricType metric) {
169166
if (stok == "") {
170167
return metric == METRIC_L2 ? AdditiveQuantizer::ST_decompress
@@ -766,7 +763,7 @@ std::unique_ptr<Index> index_factory_sub(
766763
}
767764

768765
if (verbose) {
769-
printf("after () normalization: %s %ld parenthesis indexes d=%d\n",
766+
printf("after () normalization: %s %zd parenthesis indexes d=%d\n",
770767
description.c_str(),
771768
parenthesis_indexes.size(),
772769
d);

0 commit comments

Comments
 (0)