Skip to content

Commit 2c961cc

Browse files
makostenfacebook-github-bot
authored andcommitted
Add VectorTransform read from filename to the C API (facebookresearch#3970)
Summary: This adds read_VectorTransform to the C API. This is helpful for independently loading a vector transform rather than as an IndexPreTransform. Pull Request resolved: facebookresearch#3970 Reviewed By: asadoughi Differential Revision: D65192203 Pulled By: junjieqi fbshipit-source-id: 949ae875924b9f3558d7a9f43c4f2aa8ae705f02
1 parent 9766d64 commit 2c961cc

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

c_api/index_io_c.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using faiss::Index;
1616
using faiss::IndexBinary;
17+
using faiss::VectorTransform;
1718

1819
int faiss_write_index(const FaissIndex* idx, FILE* f) {
1920
try {
@@ -83,3 +84,13 @@ int faiss_read_index_binary_fname(
8384
}
8485
CATCH_AND_HANDLE
8586
}
87+
88+
int faiss_read_VectorTransform_fname(
89+
const char* fname,
90+
FaissVectorTransform** p_out) {
91+
try {
92+
auto out = faiss::read_VectorTransform(fname);
93+
*p_out = reinterpret_cast<FaissVectorTransform*>(out);
94+
}
95+
CATCH_AND_HANDLE
96+
}

c_api/index_io_c.h

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <stdio.h>
1515
#include "IndexBinary_c.h"
1616
#include "Index_c.h"
17+
#include "VectorTransform_c.h"
1718
#include "faiss_c.h"
1819

1920
#ifdef __cplusplus
@@ -71,6 +72,13 @@ int faiss_read_index_binary_fname(
7172
const char* fname,
7273
int io_flags,
7374
FaissIndexBinary** p_out);
75+
76+
/** Read vector transform from a file.
77+
* This is equivalent to `faiss:read_VectorTransform` when a file path is given.
78+
*/
79+
int faiss_read_VectorTransform_fname(
80+
const char* fname,
81+
FaissVectorTransform** p_out);
7482
#ifdef __cplusplus
7583
}
7684
#endif

0 commit comments

Comments
 (0)