Faiss
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
IndexIVFFlat_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 "IndexIVFFlat_c.h"
15 #include "IndexIVFFlat.h"
16 #include "macros_impl.h"
17 
18 using faiss::Index;
20 using faiss::MetricType;
21 
22 DEFINE_DESTRUCTOR(IndexIVFFlat)
23 DEFINE_INDEX_DOWNCAST(IndexIVFFlat)
24 
25 int faiss_IndexIVFFlat_new(FaissIndexIVFFlat** p_index) {
26  try {
27  *p_index = reinterpret_cast<FaissIndexIVFFlat*>(new IndexIVFFlat());
28  } CATCH_AND_HANDLE
29 }
30 
31 int faiss_IndexIVFFlat_new_with(FaissIndexIVFFlat** p_index,
32  FaissIndex* quantizer, size_t d, size_t nlist)
33 {
34  try {
35  auto q = reinterpret_cast<Index*>(quantizer);
36  *p_index = reinterpret_cast<FaissIndexIVFFlat*>(new IndexIVFFlat(q, d, nlist));
37  } CATCH_AND_HANDLE
38 }
39 
40 int faiss_IndexIVFFlat_new_with_metric(
41  FaissIndexIVFFlat** p_index, FaissIndex* quantizer, size_t d, size_t nlist,
42  FaissMetricType metric)
43 {
44  try {
45  auto q = reinterpret_cast<Index*>(quantizer);
46  auto m = static_cast<MetricType>(metric);
47  *p_index = reinterpret_cast<FaissIndexIVFFlat*>(new IndexIVFFlat(q, d, nlist, m));
48  } CATCH_AND_HANDLE
49 }
50 
51 int faiss_IndexIVFFlat_add_core(FaissIndexIVFFlat* index, idx_t n,
52  const float * x, const long *xids, const long *precomputed_idx)
53 {
54  try {
55  reinterpret_cast<IndexIVFFlat*>(index)->add_core(n, x, xids, precomputed_idx);
56  } CATCH_AND_HANDLE
57 }
58 
59 int faiss_IndexIVFFlat_update_vectors(FaissIndexIVFFlat* index, int nv,
60  idx_t *idx, const float *v)
61 {
62  try {
63  reinterpret_cast<IndexIVFFlat*>(index)->update_vectors(nv, idx, v);
64  } CATCH_AND_HANDLE
65 }
MetricType
Some algorithms support both an inner product version and a L2 search version.
Definition: Index.h:45