Skip to content

Commit 0dcd18c

Browse files
authored
Merge branch 'main' into export-D59988036
2 parents 821a548 + 8b5895f commit 0dcd18c

File tree

5 files changed

+48
-5
lines changed

5 files changed

+48
-5
lines changed

faiss/Index.h

+20-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@
2020
#define FAISS_VERSION_MINOR 8
2121
#define FAISS_VERSION_PATCH 0
2222

23+
// Macro to combine the version components into a single string
24+
#ifndef FAISS_STRINGIFY
25+
#define FAISS_STRINGIFY(ARG) #ARG
26+
#endif
27+
#ifndef FAISS_TOSTRING
28+
#define FAISS_TOSTRING(ARG) FAISS_STRINGIFY(ARG)
29+
#endif
30+
#define VERSION_STRING \
31+
FAISS_TOSTRING(FAISS_VERSION_MAJOR) \
32+
"." FAISS_TOSTRING(FAISS_VERSION_MINOR) "." FAISS_TOSTRING( \
33+
FAISS_VERSION_PATCH)
34+
2335
/**
2436
* @namespace faiss
2537
*
@@ -38,8 +50,8 @@
3850

3951
namespace faiss {
4052

41-
/// Forward declarations see impl/AuxIndexStructures.h, impl/IDSelector.h and
42-
/// impl/DistanceComputer.h
53+
/// Forward declarations see impl/AuxIndexStructures.h, impl/IDSelector.h
54+
/// and impl/DistanceComputer.h
4355
struct IDSelector;
4456
struct RangeSearchResult;
4557
struct DistanceComputer;
@@ -56,7 +68,8 @@ struct SearchParameters {
5668
virtual ~SearchParameters() {}
5769
};
5870

59-
/** Abstract structure for an index, supports adding vectors and searching them.
71+
/** Abstract structure for an index, supports adding vectors and searching
72+
* them.
6073
*
6174
* All vectors provided at add or search time are 32-bit float arrays,
6275
* although the internal representation may vary.
@@ -154,7 +167,8 @@ struct Index {
154167

155168
/** return the indexes of the k vectors closest to the query x.
156169
*
157-
* This function is identical as search but only return labels of neighbors.
170+
* This function is identical as search but only return labels of
171+
* neighbors.
158172
* @param n number of vectors
159173
* @param x input vectors to search, size n * d
160174
* @param labels output labels of the NNs, size n*k
@@ -179,7 +193,8 @@ struct Index {
179193
*/
180194
virtual void reconstruct(idx_t key, float* recons) const;
181195

182-
/** Reconstruct several stored vectors (or an approximation if lossy coding)
196+
/** Reconstruct several stored vectors (or an approximation if lossy
197+
* coding)
183198
*
184199
* this function may not be defined for some indexes
185200
* @param n number of vectors to reconstruct

faiss/utils/utils.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
// -*- c++ -*-
99

10+
#include <faiss/Index.h>
1011
#include <faiss/utils/utils.h>
1112

1213
#include <cassert>
@@ -129,6 +130,10 @@ std::string get_compile_options() {
129130
return options;
130131
}
131132

133+
std::string get_version() {
134+
return VERSION_STRING;
135+
}
136+
132137
#ifdef _MSC_VER
133138
double getmillisecs() {
134139
LARGE_INTEGER ts;

faiss/utils/utils.h

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ std::string get_compile_options();
3737
* Get some stats about the system
3838
**************************************************/
3939

40+
// Expose FAISS version as a string
41+
std::string get_version();
42+
4043
/// ms elapsed since some arbitrary epoch
4144
double getmillisecs();
4245

tests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ set(FAISS_TEST_SRC
3535
test_disable_pq_sdc_tables.cpp
3636
test_common_ivf_empty_index.cpp
3737
test_callback.cpp
38+
test_utils.cpp
3839
)
3940

4041
add_executable(faiss_test ${FAISS_TEST_SRC})

tests/test_utils.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include <gtest/gtest.h>
9+
10+
#include <faiss/Index.h>
11+
#include <faiss/utils/utils.h>
12+
13+
TEST(TestUtils, get_version) {
14+
std::string version = std::to_string(FAISS_VERSION_MAJOR) + "." +
15+
std::to_string(FAISS_VERSION_MINOR) + "." +
16+
std::to_string(FAISS_VERSION_PATCH);
17+
18+
EXPECT_EQ(version, faiss::get_version());
19+
}

0 commit comments

Comments
 (0)