| 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 "IndexBinary_c.h" |
| 11 |
#include <faiss/IndexBinary.h> |
| 12 |
#include "macros_impl.h" |
| 13 |
|
| 14 |
extern "C" { |
| 15 |
|
| 16 |
DEFINE_DESTRUCTOR(IndexBinary) |
| 17 |
|
| 18 |
DEFINE_GETTER(IndexBinary, int, d) |
| 19 |
|
| 20 |
DEFINE_GETTER(IndexBinary, int, is_trained) |
| 21 |
|
| 22 |
DEFINE_GETTER(IndexBinary, idx_t, ntotal) |
| 23 |
|
| 24 |
DEFINE_GETTER(IndexBinary, FaissMetricType, metric_type) |
| 25 |
|
| 26 |
DEFINE_GETTER(IndexBinary, int, verbose); |
| 27 |
DEFINE_SETTER(IndexBinary, int, verbose); |
| 28 |
|
| 29 |
int faiss_IndexBinary_train( |
| 30 |
FaissIndexBinary* index, |
| 31 |
idx_t n, |
| 32 |
const uint8_t* x) { |
| 33 |
try { |
| 34 |
reinterpret_cast<faiss::IndexBinary*>(index)->train(n, x); |
| 35 |
} |
| 36 |
CATCH_AND_HANDLE |
| 37 |
} |
| 38 |
|
| 39 |
int faiss_IndexBinary_add(FaissIndexBinary* index, idx_t n, const uint8_t* x) { |
| 40 |
try { |
| 41 |
reinterpret_cast<faiss::IndexBinary*>(index)->add(n, x); |
| 42 |
} |
| 43 |
CATCH_AND_HANDLE |
| 44 |
} |
| 45 |
|
| 46 |
int faiss_IndexBinary_add_with_ids( |
| 47 |
FaissIndexBinary* index, |
| 48 |
idx_t n, |
| 49 |
const uint8_t* x, |
| 50 |
const idx_t* xids) { |
| 51 |
try { |
| 52 |
reinterpret_cast<faiss::IndexBinary*>(index)->add_with_ids(n, x, xids); |
| 53 |
} |
| 54 |
CATCH_AND_HANDLE |
| 55 |
} |
| 56 |
|
| 57 |
int faiss_IndexBinary_search( |
| 58 |
const FaissIndexBinary* index, |
| 59 |
idx_t n, |
| 60 |
const uint8_t* x, |
| 61 |
idx_t k, |
| 62 |
int32_t* distances, |
| 63 |
idx_t* labels) { |
| 64 |
try { |
| 65 |
reinterpret_cast<const faiss::IndexBinary*>(index)->search( |
| 66 |
n, x, k, distances, labels); |
| 67 |
} |
| 68 |
CATCH_AND_HANDLE |
| 69 |
} |
| 70 |
|
| 71 |
int faiss_IndexBinary_range_search( |
| 72 |
const FaissIndexBinary* index, |
| 73 |
idx_t n, |
| 74 |
const uint8_t* x, |
| 75 |
int radius, |
| 76 |
FaissRangeSearchResult* result) { |
| 77 |
try { |
| 78 |
reinterpret_cast<const faiss::IndexBinary*>(index)->range_search( |
| 79 |
n, |
| 80 |
x, |
| 81 |
radius, |
| 82 |
reinterpret_cast<faiss::RangeSearchResult*>(result)); |
| 83 |
} |
| 84 |
CATCH_AND_HANDLE |
| 85 |
} |
| 86 |
|
| 87 |
int faiss_IndexBinary_assign( |
| 88 |
FaissIndexBinary* index, |
| 89 |
idx_t n, |
| 90 |
const uint8_t* x, |
| 91 |
idx_t* labels, |
| 92 |
idx_t k) { |
| 93 |
try { |
| 94 |
reinterpret_cast<faiss::IndexBinary*>(index)->assign(n, x, labels, k); |
| 95 |
} |
| 96 |
CATCH_AND_HANDLE |
| 97 |
} |
| 98 |
|
| 99 |
int faiss_IndexBinary_reset(FaissIndexBinary* index) { |
| 100 |
try { |
| 101 |
reinterpret_cast<faiss::IndexBinary*>(index)->reset(); |
| 102 |
} |
| 103 |
CATCH_AND_HANDLE |
| 104 |
} |
| 105 |
|
| 106 |
int faiss_IndexBinary_remove_ids( |
| 107 |
FaissIndexBinary* index, |
| 108 |
const FaissIDSelector* sel, |
| 109 |
size_t* n_removed) { |
| 110 |
try { |
| 111 |
size_t n{reinterpret_cast<faiss::IndexBinary*>(index)->remove_ids( |
| 112 |
*reinterpret_cast<const faiss::IDSelector*>(sel))}; |
| 113 |
if (n_removed) { |
| 114 |
*n_removed = n; |
| 115 |
} |
| 116 |
} |
| 117 |
CATCH_AND_HANDLE |
| 118 |
} |
| 119 |
|
| 120 |
int faiss_IndexBinary_reconstruct( |
| 121 |
const FaissIndexBinary* index, |
| 122 |
idx_t key, |
| 123 |
uint8_t* recons) { |
| 124 |
try { |
| 125 |
reinterpret_cast<const faiss::IndexBinary*>(index)->reconstruct( |
| 126 |
key, recons); |
| 127 |
} |
| 128 |
CATCH_AND_HANDLE |
| 129 |
} |
| 130 |
|
| 131 |
int faiss_IndexBinary_reconstruct_n( |
| 132 |
const FaissIndexBinary* index, |
| 133 |
idx_t i0, |
| 134 |
idx_t ni, |
| 135 |
uint8_t* recons) { |
| 136 |
try { |
| 137 |
reinterpret_cast<const faiss::IndexBinary*>(index)->reconstruct_n( |
| 138 |
i0, ni, recons); |
| 139 |
} |
| 140 |
CATCH_AND_HANDLE |
| 141 |
} |
| 142 |
} |