Add VectorTransform read from filename to the C API (#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: https://github.com/facebookresearch/faiss/pull/3970

Reviewed By: asadoughi

Differential Revision: D65192203

Pulled By: junjieqi

fbshipit-source-id: 949ae875924b9f3558d7a9f43c4f2aa8ae705f02
pull/4011/head
Michael Kosten 2024-10-30 12:01:15 -07:00 committed by Facebook GitHub Bot
parent 9766d64dde
commit 2c961cc308
2 changed files with 19 additions and 0 deletions

View File

@ -14,6 +14,7 @@
using faiss::Index;
using faiss::IndexBinary;
using faiss::VectorTransform;
int faiss_write_index(const FaissIndex* idx, FILE* f) {
try {
@ -83,3 +84,13 @@ int faiss_read_index_binary_fname(
}
CATCH_AND_HANDLE
}
int faiss_read_VectorTransform_fname(
const char* fname,
FaissVectorTransform** p_out) {
try {
auto out = faiss::read_VectorTransform(fname);
*p_out = reinterpret_cast<FaissVectorTransform*>(out);
}
CATCH_AND_HANDLE
}

View File

@ -14,6 +14,7 @@
#include <stdio.h>
#include "IndexBinary_c.h"
#include "Index_c.h"
#include "VectorTransform_c.h"
#include "faiss_c.h"
#ifdef __cplusplus
@ -71,6 +72,13 @@ int faiss_read_index_binary_fname(
const char* fname,
int io_flags,
FaissIndexBinary** p_out);
/** Read vector transform from a file.
* This is equivalent to `faiss:read_VectorTransform` when a file path is given.
*/
int faiss_read_VectorTransform_fname(
const char* fname,
FaissVectorTransform** p_out);
#ifdef __cplusplus
}
#endif