Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
IndexFlat_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
12 #include "IndexFlat_c.h"
13 #include "IndexFlat.h"
14 #include "Index.h"
15 #include "macros_impl.h"
16
17 extern "C" {
18
19 using faiss::Index;
20 using faiss::IndexFlat;
21 using faiss::IndexFlatIP;
22 using faiss::IndexFlatL2;
23 using faiss::IndexFlatL2BaseShift;
24 using faiss::IndexRefineFlat;
25 using faiss::IndexFlat1D;
26
27 DEFINE_DESTRUCTOR(IndexFlat)
28 DEFINE_INDEX_DOWNCAST(IndexFlat)
29
30 int faiss_IndexFlat_new(FaissIndexFlat** p_index) {
31 try {
32 *p_index = reinterpret_cast<FaissIndexFlat*>(new IndexFlat());
33 return 0;
34 } CATCH_AND_HANDLE
35 }
36
37 int faiss_IndexFlat_new_with(FaissIndexFlat** p_index, idx_t d, FaissMetricType metric) {
38 try {
39 IndexFlat* index = new IndexFlat(d, static_cast<faiss::MetricType>(metric));
40 *p_index = reinterpret_cast<FaissIndexFlat*>(index);
41 return 0;
42 } CATCH_AND_HANDLE
43 }
44
45 void faiss_IndexFlat_xb(FaissIndexFlat* index, float** p_xb, size_t* p_size) {
46 auto& xb = reinterpret_cast<IndexFlat*>(index)->xb;
47 *p_xb = xb.data();
48 if (p_size) {
49 *p_size = xb.size();
50 }
51 }
52
53 int faiss_IndexFlat_compute_distance_subset(
54 FaissIndex* index,
55 idx_t n,
56 const float *x,
57 idx_t k,
58 float *distances,
59 const idx_t *labels) {
60 try {
61 reinterpret_cast<IndexFlat*>(index)->compute_distance_subset(
62 n, x, k, distances, labels);
63 return 0;
64 } CATCH_AND_HANDLE
65 }
66
67 int faiss_IndexFlatIP_new(FaissIndexFlatIP** p_index) {
68 try {
69 IndexFlatIP* index = new IndexFlatIP();
70 *p_index = reinterpret_cast<FaissIndexFlatIP*>(index);
71 return 0;
72 } CATCH_AND_HANDLE
73 }
74
75 int faiss_IndexFlatIP_new_with(FaissIndexFlatIP** p_index, idx_t d) {
76 try {
77 IndexFlatIP* index = new IndexFlatIP(d);
78 *p_index = reinterpret_cast<FaissIndexFlatIP*>(index);
79 return 0;
80 } CATCH_AND_HANDLE
81 }
82
83 int faiss_IndexFlatL2_new(FaissIndexFlatL2** p_index) {
84 try {
85 IndexFlatL2* index = new IndexFlatL2();
86 *p_index = reinterpret_cast<FaissIndexFlatL2*>(index);
87 return 0;
88 } CATCH_AND_HANDLE
89 }
90
91 int faiss_IndexFlatL2_new_with(FaissIndexFlatL2** p_index, idx_t d) {
92 try {
93 IndexFlatL2* index = new IndexFlatL2(d);
94 *p_index = reinterpret_cast<FaissIndexFlatL2*>(index);
95 return 0;
96 } CATCH_AND_HANDLE
97 }
98
99 int faiss_IndexFlatL2BaseShift_new(FaissIndexFlatL2BaseShift** p_index, idx_t d, size_t nshift, const float *shift) {
100 try {
101 IndexFlatL2BaseShift* index = new IndexFlatL2BaseShift(d, nshift, shift);
102 *p_index = reinterpret_cast<FaissIndexFlatL2BaseShift*>(index);
103 return 0;
104 } CATCH_AND_HANDLE
105 }
106
107 int faiss_IndexRefineFlat_new(FaissIndexRefineFlat** p_index, FaissIndex* base_index) {
108 try {
109 IndexRefineFlat* index = new IndexRefineFlat(
110 reinterpret_cast<faiss::Index*>(base_index));
111 *p_index = reinterpret_cast<FaissIndexRefineFlat*>(index);
112 return 0;
113 } CATCH_AND_HANDLE
114 }
115
116 DEFINE_DESTRUCTOR(IndexRefineFlat)
117
118 int faiss_IndexFlat1D_new(FaissIndexFlat1D** p_index) {
119 try {
120 IndexFlat1D* index = new IndexFlat1D();
121 *p_index = reinterpret_cast<FaissIndexFlat1D*>(index);
122 return 0;
123 } CATCH_AND_HANDLE
124 }
125
126 int faiss_IndexFlat1D_new_with(FaissIndexFlat1D** p_index, int continuous_update) {
127 try {
128 IndexFlat1D* index = new IndexFlat1D(static_cast<bool>(continuous_update));
129 *p_index = reinterpret_cast<FaissIndexFlat1D*>(index);
130 return 0;
131 } CATCH_AND_HANDLE
132 }
133
134 int faiss_IndexFlat1D_update_permutation(FaissIndexFlat1D* index) {
135 try {
136 reinterpret_cast<IndexFlat1D*>(index)->update_permutation();
137 return 0;
138 } CATCH_AND_HANDLE
139 }
140
141 }
faiss::IndexFlat
Definition: IndexFlat.h:22
faiss::IndexFlat1D
optimized version for 1D &quot;vectors&quot;
Definition: IndexFlat.h:137
faiss::IndexFlatL2
Definition: IndexFlat.h:78
faiss::IndexFlatIP
Definition: IndexFlat.h:72
faiss::IndexRefineFlat
Definition: IndexFlat.h:102
faiss::IndexFlatL2BaseShift
Definition: IndexFlat.h:85
faiss::Index
Definition: Index.h:62