From ed8d52aea228fb28818ce2316fcd10e96f411465 Mon Sep 17 00:00:00 2001 From: Michael Norris Date: Tue, 20 Aug 2024 10:43:24 -0700 Subject: [PATCH] Move static functions to header file (#3757) Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/3757 In the telemetry wrapper, we need to wrap read_index to return wrapped index structs. D61049751 This read_index wrapper calls several static functions. These are not callable outside a C++ file. Thus this diff changes them to non static and declares them in the header file. Then the wrapper is able to call them. Differential Revision: D61282004 --- faiss/impl/index_read.cpp | 11 ++++++----- faiss/impl/index_read_utils.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 faiss/impl/index_read_utils.h diff --git a/faiss/impl/index_read.cpp b/faiss/impl/index_read.cpp index aa041c0fac..b3350d236b 100644 --- a/faiss/impl/index_read.cpp +++ b/faiss/impl/index_read.cpp @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. */ +#include #include #include @@ -61,7 +62,7 @@ namespace faiss { * Read **************************************************************/ -static void read_index_header(Index* idx, IOReader* f) { +void read_index_header(Index* idx, IOReader* f) { READ1(idx->d); READ1(idx->ntotal); idx_t dummy; @@ -230,7 +231,7 @@ InvertedLists* read_InvertedLists(IOReader* f, int io_flags) { } } -static void read_InvertedLists(IndexIVF* ivf, IOReader* f, int io_flags) { +void read_InvertedLists(IndexIVF* ivf, IOReader* f, int io_flags) { InvertedLists* ils = read_InvertedLists(f, io_flags); if (ils) { FAISS_THROW_IF_NOT(ils->nlist == ivf->nlist); @@ -438,7 +439,7 @@ ProductQuantizer* read_ProductQuantizer(IOReader* reader) { return pq; } -static void read_direct_map(DirectMap* dm, IOReader* f) { +void read_direct_map(DirectMap* dm, IOReader* f) { char maintain_direct_map; READ1(maintain_direct_map); dm->type = (DirectMap::Type)maintain_direct_map; @@ -454,10 +455,10 @@ static void read_direct_map(DirectMap* dm, IOReader* f) { } } -static void read_ivf_header( +void read_ivf_header( IndexIVF* ivf, IOReader* f, - std::vector>* ids = nullptr) { + std::vector>* ids) { read_index_header(ivf, f); READ1(ivf->nlist); READ1(ivf->nprobe); diff --git a/faiss/impl/index_read_utils.h b/faiss/impl/index_read_utils.h new file mode 100644 index 0000000000..0d31e4b600 --- /dev/null +++ b/faiss/impl/index_read_utils.h @@ -0,0 +1,30 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// Utils for index_read + +#ifndef FAISS_INDEX_READ_UTILS_H +#define FAISS_INDEX_READ_UTILS_H + +#include +#include + +#pragma once + +namespace faiss { + +void read_index_header(Index* idx, IOReader* f); +void read_direct_map(DirectMap* dm, IOReader* f); +void read_ivf_header( + IndexIVF* ivf, + IOReader* f, + std::vector>* ids = nullptr); +void read_InvertedLists(IndexIVF* ivf, IOReader* f, int io_flags); + +} // namespace faiss + +#endif