Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
AutoTune_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 <cstring>
13 #include "AutoTune.h"
14 #include "AutoTune_c.h"
15 #include "macros_impl.h"
16
17 using faiss::Index;
18 using faiss::ParameterRange;
19 using faiss::ParameterSpace;
20
21 /** Build and index with the sequence of processing steps described in
22 * the string.
23 */
24 int faiss_index_factory(FaissIndex** p_index, int d, const char* description, FaissMetricType metric) {
25 try {
26 *p_index = reinterpret_cast<FaissIndex*>(faiss::index_factory(
27 d, description, static_cast<faiss::MetricType>(metric)));
28 } CATCH_AND_HANDLE
29 }
30
31 const char* faiss_ParameterRange_name(const FaissParameterRange* range) {
32 return reinterpret_cast<const ParameterRange*>(range)->name.c_str();
33 }
34
35 void faiss_ParameterRange_values(FaissParameterRange* range, double** p_values, size_t* p_size) {
36 auto& values = reinterpret_cast<ParameterRange*>(range)->values;
37 *p_values = values.data();
38 *p_size = values.size();
39 }
40
41 int faiss_ParameterSpace_new(FaissParameterSpace** space) {
42 try {
43 auto new_space = new ParameterSpace();
44 *space = reinterpret_cast<FaissParameterSpace*>(new_space);
45 } CATCH_AND_HANDLE
46 }
47
48 DEFINE_DESTRUCTOR(ParameterSpace)
49
50 size_t faiss_ParameterSpace_n_combinations(const FaissParameterSpace* space) {
51 return reinterpret_cast<const ParameterSpace*>(space)->n_combinations();
52 }
53
54 int faiss_ParameterSpace_combination_name(const FaissParameterSpace* space, size_t cno, char* char_buffer, size_t size) {
55 try {
56 auto rep = reinterpret_cast<const ParameterSpace*>(space)->combination_name(cno);
57 strncpy(char_buffer, rep.c_str(), size);
58 } CATCH_AND_HANDLE
59 }
60
61 int faiss_ParameterSpace_set_index_parameters(const FaissParameterSpace* space, FaissIndex* cindex, const char* param_string) {
62 try {
63 auto index = reinterpret_cast<Index*>(cindex);
64 reinterpret_cast<const ParameterSpace*>(space)->set_index_parameters(index, param_string);
65 } CATCH_AND_HANDLE
66 }
67
68 /// set a combination of parameters on an index
69 int faiss_ParameterSpace_set_index_parameters_cno(const FaissParameterSpace* space, FaissIndex* cindex, size_t cno) {
70 try {
71 auto index = reinterpret_cast<Index*>(cindex);
72 reinterpret_cast<const ParameterSpace*>(space)->set_index_parameters(index, cno);
73 } CATCH_AND_HANDLE
74 }
75
76 int faiss_ParameterSpace_set_index_parameter(const FaissParameterSpace* space, FaissIndex* cindex, const char * name, double value) {
77 try {
78 auto index = reinterpret_cast<Index*>(cindex);
79 reinterpret_cast<const ParameterSpace*>(space)->set_index_parameter(index, name, value);
80 } CATCH_AND_HANDLE
81 }
82
83 void faiss_ParameterSpace_display(const FaissParameterSpace* space) {
84 reinterpret_cast<const ParameterSpace*>(space)->display();
85 }
86
87 int faiss_ParameterSpace_add_range(FaissParameterSpace* space, const char* name, FaissParameterRange** p_range) {
88 try {
89 ParameterRange& range = reinterpret_cast<ParameterSpace*>(space)->add_range(name);
90 if (p_range) {
91 *p_range = reinterpret_cast<FaissParameterRange*>(&range);
92 }
93 } CATCH_AND_HANDLE
94 }
faiss::ParameterSpace
Definition: AutoTune.h:132
faiss::Index
Definition: Index.h:62
faiss::ParameterRange
possible values of a parameter, sorted from least to most expensive/accurate
Definition: AutoTune.h:125
faiss::index_factory
Index * index_factory(int d, const char *description_in, MetricType metric)
Definition: AutoTune.cpp:722