forked from facebookresearch/faiss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndexFlat_c.cpp
More file actions
141 lines (121 loc) · 3.86 KB
/
Copy pathIndexFlat_c.cpp
File metadata and controls
141 lines (121 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD+Patents license found in the
* LICENSE file in the root directory of this source tree.
*/
// Copyright 2004-present Facebook. All Rights Reserved.
// -*- c++ -*-
#include "IndexFlat_c.h"
#include "IndexFlat.h"
#include "Index.h"
#include "macros_impl.h"
extern "C" {
using faiss::Index;
using faiss::IndexFlat;
using faiss::IndexFlatIP;
using faiss::IndexFlatL2;
using faiss::IndexFlatL2BaseShift;
using faiss::IndexRefineFlat;
using faiss::IndexFlat1D;
DEFINE_DESTRUCTOR(IndexFlat)
DEFINE_INDEX_DOWNCAST(IndexFlat)
int faiss_IndexFlat_new(FaissIndexFlat** p_index) {
try {
*p_index = reinterpret_cast<FaissIndexFlat*>(new IndexFlat());
return 0;
} CATCH_AND_HANDLE
}
int faiss_IndexFlat_new_with(FaissIndexFlat** p_index, idx_t d, FaissMetricType metric) {
try {
IndexFlat* index = new IndexFlat(d, static_cast<faiss::MetricType>(metric));
*p_index = reinterpret_cast<FaissIndexFlat*>(index);
return 0;
} CATCH_AND_HANDLE
}
void faiss_IndexFlat_xb(FaissIndexFlat* index, float** p_xb, size_t* p_size) {
auto& xb = reinterpret_cast<IndexFlat*>(index)->xb;
*p_xb = xb.data();
if (p_size) {
*p_size = xb.size();
}
}
int faiss_IndexFlat_compute_distance_subset(
FaissIndex* index,
idx_t n,
const float *x,
idx_t k,
float *distances,
const idx_t *labels) {
try {
reinterpret_cast<IndexFlat*>(index)->compute_distance_subset(
n, x, k, distances, labels);
return 0;
} CATCH_AND_HANDLE
}
int faiss_IndexFlatIP_new(FaissIndexFlatIP** p_index) {
try {
IndexFlatIP* index = new IndexFlatIP();
*p_index = reinterpret_cast<FaissIndexFlatIP*>(index);
return 0;
} CATCH_AND_HANDLE
}
int faiss_IndexFlatIP_new_with(FaissIndexFlatIP** p_index, idx_t d) {
try {
IndexFlatIP* index = new IndexFlatIP(d);
*p_index = reinterpret_cast<FaissIndexFlatIP*>(index);
return 0;
} CATCH_AND_HANDLE
}
int faiss_IndexFlatL2_new(FaissIndexFlatL2** p_index) {
try {
IndexFlatL2* index = new IndexFlatL2();
*p_index = reinterpret_cast<FaissIndexFlatL2*>(index);
return 0;
} CATCH_AND_HANDLE
}
int faiss_IndexFlatL2_new_with(FaissIndexFlatL2** p_index, idx_t d) {
try {
IndexFlatL2* index = new IndexFlatL2(d);
*p_index = reinterpret_cast<FaissIndexFlatL2*>(index);
return 0;
} CATCH_AND_HANDLE
}
int faiss_IndexFlatL2BaseShift_new(FaissIndexFlatL2BaseShift** p_index, idx_t d, size_t nshift, const float *shift) {
try {
IndexFlatL2BaseShift* index = new IndexFlatL2BaseShift(d, nshift, shift);
*p_index = reinterpret_cast<FaissIndexFlatL2BaseShift*>(index);
return 0;
} CATCH_AND_HANDLE
}
int faiss_IndexRefineFlat_new(FaissIndexRefineFlat** p_index, FaissIndex* base_index) {
try {
IndexRefineFlat* index = new IndexRefineFlat(
reinterpret_cast<faiss::Index*>(base_index));
*p_index = reinterpret_cast<FaissIndexRefineFlat*>(index);
return 0;
} CATCH_AND_HANDLE
}
DEFINE_DESTRUCTOR(IndexRefineFlat)
int faiss_IndexFlat1D_new(FaissIndexFlat1D** p_index) {
try {
IndexFlat1D* index = new IndexFlat1D();
*p_index = reinterpret_cast<FaissIndexFlat1D*>(index);
return 0;
} CATCH_AND_HANDLE
}
int faiss_IndexFlat1D_new_with(FaissIndexFlat1D** p_index, int continuous_update) {
try {
IndexFlat1D* index = new IndexFlat1D(static_cast<bool>(continuous_update));
*p_index = reinterpret_cast<FaissIndexFlat1D*>(index);
return 0;
} CATCH_AND_HANDLE
}
int faiss_IndexFlat1D_update_permutation(FaissIndexFlat1D* index) {
try {
reinterpret_cast<IndexFlat1D*>(index)->update_permutation();
return 0;
} CATCH_AND_HANDLE
}
}