Faiss
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
index_io_c.cpp
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 // Copyright 2004-present Facebook. All Rights Reserved
10 // -*- c++ -*-
11 // I/O code for indexes
12 
13 #include "index_io_c.h"
14 #include "index_io.h"
15 #include "macros_impl.h"
16 
17 using faiss::Index;
18 
19 int faiss_write_index(const FaissIndex *idx, FILE *f) {
20  try {
21  faiss::write_index(reinterpret_cast<const Index*>(idx), f);
22  } CATCH_AND_HANDLE
23 }
24 
25 int faiss_write_index_fname(const FaissIndex *idx, const char *fname) {
26  try {
27  faiss::write_index(reinterpret_cast<const Index*>(idx), fname);
28  } CATCH_AND_HANDLE
29 }
30 
31 int faiss_read_index(FILE *f, int io_flags, FaissIndex **p_out) {
32  try {
33  auto out = faiss::read_index(f, io_flags);
34  *p_out = reinterpret_cast<FaissIndex*>(out);
35  } CATCH_AND_HANDLE
36 }
37 
38 int faiss_read_index_fname(const char *fname, int io_flags, FaissIndex **p_out) {
39  try {
40  auto out = faiss::read_index(fname, io_flags);
41  *p_out = reinterpret_cast<FaissIndex*>(out);
42  } CATCH_AND_HANDLE
43 }
44 
45 int faiss_clone_index (const FaissIndex *idx, FaissIndex **p_out) {
46  try {
47  auto out = faiss::clone_index(reinterpret_cast<const Index*>(idx));
48  *p_out = reinterpret_cast<FaissIndex*>(out);
49  } CATCH_AND_HANDLE
50 }