Debian Codegraph @

c_api/MetaIndexes_c.cpp

raw
1 /*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 // -*- c++ -*-
9
10 #include "MetaIndexes_c.h"
11 #include <faiss/MetaIndexes.h>
12 #include "macros_impl.h"
13
14 using faiss::Index;
15 using faiss::IndexIDMap;
16 using faiss::IndexIDMap2;
17
18 DEFINE_GETTER(IndexIDMap, int, own_fields)
19 DEFINE_SETTER(IndexIDMap, int, own_fields)
20
21 DEFINE_INDEX_DOWNCAST(IndexIDMap)
22
23 DEFINE_GETTER(IndexIDMap2, int, own_fields)
24 DEFINE_SETTER(IndexIDMap2, int, own_fields)
25
26 DEFINE_INDEX_DOWNCAST(IndexIDMap2)
27
28 int faiss_IndexIDMap_new(FaissIndexIDMap** p_index, FaissIndex* index) {
29 try {
30 auto out = new IndexIDMap(reinterpret_cast<Index*>(index));
31 *p_index = reinterpret_cast<FaissIndexIDMap*>(out);
32 }
33 CATCH_AND_HANDLE
34 }
35
36 void faiss_IndexIDMap_id_map(
37 FaissIndexIDMap* index,
38 idx_t** p_id_map,
39 size_t* p_size) {
40 auto idx = reinterpret_cast<IndexIDMap*>(index);
41 if (p_id_map)
42 *p_id_map = idx->id_map.data();
43 if (p_size)
44 *p_size = idx->id_map.size();
45 }
46
47 FaissIndex* faiss_IndexIDMap_sub_index(FaissIndexIDMap* index) {
48 auto idx = reinterpret_cast<IndexIDMap*>(index);
49 return (FaissIndex*)reinterpret_cast<Index*>(idx->index);
50 }
51
52 int faiss_IndexIDMap2_new(FaissIndexIDMap2** p_index, FaissIndex* index) {
53 try {
54 auto out = new IndexIDMap2(reinterpret_cast<Index*>(index));
55 *p_index = reinterpret_cast<FaissIndexIDMap2*>(out);
56 }
57 CATCH_AND_HANDLE
58 }
59
60 int faiss_IndexIDMap2_construct_rev_map(FaissIndexIDMap2* index) {
61 try {
62 reinterpret_cast<IndexIDMap2*>(index)->construct_rev_map();
63 }
64 CATCH_AND_HANDLE
65 }
66
67 void faiss_IndexIDMap2_id_map(
68 FaissIndexIDMap2* index,
69 idx_t** p_id_map,
70 size_t* p_size) {
71 auto idx = reinterpret_cast<IndexIDMap2*>(index);
72 if (p_id_map)
73 *p_id_map = idx->id_map.data();
74 if (p_size)
75 *p_size = idx->id_map.size();
76 }
77
78 FaissIndex* faiss_IndexIDMap2_sub_index(FaissIndexIDMap2* index) {
79 auto idx = reinterpret_cast<IndexIDMap2*>(index);
80 return (FaissIndex*)reinterpret_cast<Index*>(idx->index);
81 }