Faiss
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
Index_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 "Index_c.h"
13 #include "Index.h"
14 #include "macros_impl.h"
15 
16 extern "C" {
17 
18 DEFINE_DESTRUCTOR(Index)
19 
20 DEFINE_GETTER(Index, int, d)
21 
22 DEFINE_GETTER(Index, int, is_trained)
23 
24 DEFINE_GETTER(Index, idx_t, ntotal)
25 
26 DEFINE_GETTER(Index, FaissMetricType, metric_type)
27 
28 int faiss_Index_train(FaissIndex* index, idx_t n, const float* x) {
29  try {
30  reinterpret_cast<faiss::Index*>(index)->train(n, x);
31  } CATCH_AND_HANDLE
32 }
33 
34 int faiss_Index_add(FaissIndex* index, idx_t n, const float* x) {
35  try {
36  reinterpret_cast<faiss::Index*>(index)->add(n, x);
37  } CATCH_AND_HANDLE
38 }
39 
40 int faiss_Index_add_with_ids(FaissIndex* index, idx_t n, const float* x, const long* xids) {
41  try {
42  reinterpret_cast<faiss::Index*>(index)->add_with_ids(n, x, xids);
43  } CATCH_AND_HANDLE
44 }
45 
46 int faiss_Index_search(const FaissIndex* index, idx_t n, const float* x, idx_t k,
47  float* distances, idx_t* labels) {
48  try {
49  reinterpret_cast<const faiss::Index*>(index)->search(n, x, k, distances, labels);
50  } CATCH_AND_HANDLE
51 }
52 
53 int faiss_Index_range_search(const FaissIndex* index, idx_t n, const float* x, float radius,
54  FaissRangeSearchResult* result) {
55  try {
56  reinterpret_cast<const faiss::Index*>(index)->range_search(
57  n, x, radius, reinterpret_cast<faiss::RangeSearchResult*>(result));
58  } CATCH_AND_HANDLE
59 }
60 
61 int faiss_Index_assign(FaissIndex* index, idx_t n, const float * x, idx_t * labels, idx_t k) {
62  try {
63  reinterpret_cast<faiss::Index*>(index)->assign(n, x, labels, k);
64  } CATCH_AND_HANDLE
65 }
66 
67 int faiss_Index_reset(FaissIndex* index) {
68  try {
69  reinterpret_cast<faiss::Index*>(index)->reset();
70  } CATCH_AND_HANDLE
71 }
72 
73 int faiss_Index_remove_ids(FaissIndex* index, const FaissIDSelector* sel, long* n_removed) {
74  try {
75  long n = reinterpret_cast<faiss::Index*>(index)->remove_ids(
76  *reinterpret_cast<const faiss::IDSelector*>(sel));
77  if (n_removed) {
78  *n_removed = n;
79  }
80  } CATCH_AND_HANDLE
81 }
82 
83 int faiss_Index_reconstruct(const FaissIndex* index, idx_t key, float* recons) {
84  try {
85  reinterpret_cast<const faiss::Index*>(index)->reconstruct(key, recons);
86  } CATCH_AND_HANDLE
87 }
88 
89 int faiss_Index_reconstruct_n (const FaissIndex* index, idx_t i0, idx_t ni, float* recons) {
90  try {
91  reinterpret_cast<const faiss::Index*>(index)->reconstruct_n(i0, ni, recons);
92  } CATCH_AND_HANDLE
93 }
94 
95 int faiss_Index_compute_residual(const FaissIndex* index, const float* x, float* residual, idx_t key) {
96  try {
97  reinterpret_cast<const faiss::Index*>(index)->compute_residual(x, residual, key);
98  } CATCH_AND_HANDLE
99 }
100 
101 int faiss_Index_display(const FaissIndex* index) {
102  try {
103  reinterpret_cast<const faiss::Index*>(index)->display();
104  } CATCH_AND_HANDLE
105 }
106 
107 }