Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
IndexIVF_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 "Clustering_c.h"
14 #include "IndexIVF_c.h"
15 #include "IndexIVF.h"
16 #include "macros_impl.h"
17
18 using faiss::IndexIVF;
19 using faiss::IndexIVFStats;
20
21 DEFINE_DESTRUCTOR(IndexIVF)
22 DEFINE_INDEX_DOWNCAST(IndexIVF)
23
24 /// number of possible key values
25 DEFINE_GETTER(IndexIVF, size_t, nlist)
26 /// number of probes at query time
27 DEFINE_GETTER(IndexIVF, size_t, nprobe)
28 /// quantizer that maps vectors to inverted lists
29 DEFINE_GETTER_PERMISSIVE(IndexIVF, FaissIndex*, quantizer)
30
31 /**
32 * = 0: use the quantizer as index in a kmeans training
33 * = 1: just pass on the training set to the train() of the quantizer
34 * = 2: kmeans training on a flat index + add the centroids to the quantizer
35 */
36 DEFINE_GETTER(IndexIVF, char, quantizer_trains_alone)
37
38 /// whether object owns the quantizer
39 DEFINE_GETTER(IndexIVF, int, own_fields)
40
41 using faiss::IndexIVF;
42
43 int faiss_IndexIVF_merge_from(
44 FaissIndexIVF* index, FaissIndexIVF* other, idx_t add_id) {
45 try {
46 reinterpret_cast<IndexIVF*>(index)->merge_from(
47 *reinterpret_cast<IndexIVF*>(other), add_id);
48 } CATCH_AND_HANDLE
49 }
50
51 int faiss_IndexIVF_copy_subset_to(
52 const FaissIndexIVF* index, FaissIndexIVF* other, int subset_type, long a1,
53 long a2) {
54 try {
55 reinterpret_cast<const IndexIVF*>(index)->copy_subset_to(
56 *reinterpret_cast<IndexIVF*>(other), subset_type, a1, a2);
57 } CATCH_AND_HANDLE
58 }
59
60 int faiss_IndexIVF_search_preassigned (const FaissIndexIVF* index,
61 idx_t n, const float *x, idx_t k, const idx_t *assign,
62 const float *centroid_dis, float *distances, idx_t *labels,
63 int store_pairs) {
64 try {
65 reinterpret_cast<const IndexIVF*>(index)->search_preassigned(
66 n, x, k, assign, centroid_dis, distances, labels, store_pairs);
67 } CATCH_AND_HANDLE
68 }
69
70 size_t faiss_IndexIVF_get_list_size(const FaissIndexIVF* index, size_t list_no) {
71 return reinterpret_cast<const IndexIVF*>(index)->get_list_size(list_no);
72 }
73
74 int faiss_IndexIVF_make_direct_map(FaissIndexIVF* index,
75 int new_maintain_direct_map) {
76 try {
77 reinterpret_cast<IndexIVF*>(index)->make_direct_map(
78 static_cast<bool>(new_maintain_direct_map));
79 } CATCH_AND_HANDLE
80 }
81
82 double faiss_IndexIVF_imbalance_factor (const FaissIndexIVF* index) {
83 return reinterpret_cast<const IndexIVF*>(index)->imbalance_factor();
84 }
85
86 /// display some stats about the inverted lists
87 void faiss_IndexIVF_print_stats (const FaissIndexIVF* index) {
88 reinterpret_cast<const IndexIVF*>(index)->print_stats();
89 }
90
91 void faiss_IndexIVFStats_reset(FaissIndexIVFStats* stats) {
92 reinterpret_cast<IndexIVFStats*>(stats)->reset();
93 }
faiss::IndexIVF
Definition: IndexIVF.h:91
FaissIndexIVFStats
Definition: IndexIVF_c.h:116
faiss::IndexIVFStats
Definition: IndexIVF.h:295
faiss::imbalance_factor
double imbalance_factor(int k, const int *hist)
same, takes a histogram as input
Definition: utils.cpp:1279