Faiss
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
/tmp/faiss/index_io.h
1 /**
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD+Patents license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 // -*- c++ -*-
10 
11 // I/O code for indexes
12 
13 #ifndef FAISS_INDEX_IO_H
14 #define FAISS_INDEX_IO_H
15 
16 
17 #include <cstdio>
18 
19 namespace faiss {
20 
21 
22 struct Index;
23 struct IndexBinary;
24 struct VectorTransform;
25 struct IndexIVF;
26 struct ProductQuantizer;
27 struct IOReader;
28 struct IOWriter;
29 struct InvertedLists;
30 
31 void write_index (const Index *idx, const char *fname);
32 void write_index (const Index *idx, FILE *f);
33 void write_index (const Index *idx, IOWriter *writer);
34 
35 void write_index_binary (const IndexBinary *idx, const char *fname);
36 void write_index_binary (const IndexBinary *idx, FILE *f);
37 void write_index_binary (const IndexBinary *idx, IOWriter *writer);
38 
39 const int IO_FLAG_MMAP = 1; // try to memmap if possible
40 const int IO_FLAG_READ_ONLY = 2;
41 
42 Index *read_index (const char *fname, int io_flags = 0);
43 Index *read_index (FILE * f, int io_flags = 0);
44 Index *read_index (IOReader *reader, int io_flags = 0);
45 
46 IndexBinary *read_index_binary (const char *fname, int io_flags = 0);
47 IndexBinary *read_index_binary (FILE * f, int io_flags = 0);
48 IndexBinary *read_index_binary (IOReader *reader, int io_flags = 0);
49 
50 void write_VectorTransform (const VectorTransform *vt, const char *fname);
51 VectorTransform *read_VectorTransform (const char *fname);
52 
53 ProductQuantizer * read_ProductQuantizer (const char*fname);
54 ProductQuantizer * read_ProductQuantizer (IOReader *reader);
55 
56 void write_ProductQuantizer (const ProductQuantizer*pq, const char *fname);
57 void write_ProductQuantizer (const ProductQuantizer*pq, IOWriter *f);
58 
59 void write_InvertedLists (const InvertedLists *ils, IOWriter *f);
60 InvertedLists *read_InvertedLists (IOReader *reader, int io_flags = 0);
61 
62 /* cloning functions */
63 Index *clone_index (const Index *);
64 
65 /** Cloner class, useful to override classes with other cloning
66  * functions. The cloning function above just calls
67  * Cloner::clone_Index. */
68 struct Cloner {
69  virtual VectorTransform *clone_VectorTransform (const VectorTransform *);
70  virtual Index *clone_Index (const Index *);
71  virtual IndexIVF *clone_IndexIVF (const IndexIVF *);
72  virtual ~Cloner() {}
73 };
74 
75 
76 
77 } // namespace faiss
78 
79 
80 #endif