Skip to content

Commit

Permalink
Move static functions to header file (#3757)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
Michael Norris authored and facebook-github-bot committed Aug 20, 2024
1 parent c0b32d2 commit ed8d52a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
11 changes: 6 additions & 5 deletions faiss/impl/index_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

#include <faiss/impl/index_read_utils.h>
#include <faiss/index_io.h>

#include <faiss/impl/io_macros.h>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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<std::vector<idx_t>>* ids = nullptr) {
std::vector<std::vector<idx_t>>* ids) {
read_index_header(ivf, f);
READ1(ivf->nlist);
READ1(ivf->nprobe);
Expand Down
30 changes: 30 additions & 0 deletions faiss/impl/index_read_utils.h
Original file line number Diff line number Diff line change
@@ -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 <faiss/IndexIVF.h>
#include <faiss/impl/io.h>

#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<std::vector<idx_t>>* ids = nullptr);
void read_InvertedLists(IndexIVF* ivf, IOReader* f, int io_flags);

} // namespace faiss

#endif

0 comments on commit ed8d52a

Please sign in to comment.