MetricKnn API
Fast Similarity Search using the Metric Space Approach
metricknn_impl.h
1 /*
2  * Copyright (C) 2012-2015, Juan Manuel Barrios <juanmanuel@barrios.cl>
3  * All rights reserved.
4  *
5  * This file is part of MetricKnn.
6  * MetricKnn is made available under the terms of the BSD 2-Clause License.
7  */
8 
9 #ifndef METRICKNN_IMPL_H_
10 #define METRICKNN_IMPL_H_
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 #include "../metricknn_c.h"
17 #include <myutils/myutils_c.h>
18 
19 #ifndef NO_OPENCV
20 #define WITH_OPENCV 1
21 #endif
22 
23 #ifndef NO_FLANN
24 #define WITH_FLANN 1
25 #endif
26 
27 typedef struct MknnHeap MknnHeap;
28 typedef struct MknnHistogram MknnHistogram;
29 
30 #include "impl/macros_util.h"
31 #include "impl/heap.h"
32 #include "impl/histogram.h"
33 #include "impl/mevaluation_wrapper.h"
34 
35 /******************/
36 
37 MknnDatatype mknn_datatype_convertMy2Mknn(const MyDatatype my_datatype);
38 MyDatatype mknn_datatype_convertMknn2My(const MknnDatatype mknn_datatype);
39 
40 void mknn_dataset_setCompactVectors(MknnDataset *dataset,
41  void *compactVectors_pointer, bool free_compactVectors_on_release);
42 
43 void mknn_dataset_computeStatsVectors(MknnDataset *dataset,
44  struct MyDataStatsCompute *stats);
45 
46 struct MyDataStatsCompute *mknn_dataset_computeDataStats(MknnDataset *dataset);
47 
48 /******************/
49 void mknn_dataset_printObjectsRaw(MknnDataset *dataset, FILE *out);
50 
51 void mknn_dataset_printObjectsText(MknnDataset *dataset, FILE *out);
52 
53 /******************/
54 
55 typedef void (*mknn_function_printHelp)(const char *id);
56 
57 /* *************** */
58 MknnDistanceEval **mknn_distance_createDistEvalArray(MknnDistance *distance,
59  int64_t num_instances, MknnDomain *domain_left,
60  MknnDomain *domain_right);
61 void mknn_distanceEval_releaseArray(MknnDistanceEval **dist_evals,
62  int64_t num_instances);
63 
64 /* *************** */
65 
67  void *state_distEval;
68  mknn_function_distanceEval_eval func_distanceEval_eval;
69  mknn_function_distanceEval_releaseState func_distanceEval_release;
70 };
71 
72 typedef struct MknnDistanceInstance (*mknn_function_distance_new)(
73  const char *id_dist, MknnDistanceParams *params_distance);
74 
75 typedef void (*mknn_function_distance_build)(void *state_distance,
76  const char *id_dist, MknnDistanceParams *params_distance);
77 
78 typedef void (*mknn_function_distance_load)(void *state_distance,
79  const char *id_dist, MknnDistanceParams *params_distance,
80  const char *filename_read);
81 
82 typedef void (*mknn_function_distance_save)(void *state_distance,
83  const char *id_dist, MknnDistanceParams *params_distance,
84  const char *filename_write);
85 
86 typedef void (*mknn_function_distance_release)(void *state_distance);
87 
88 typedef struct MknnDistEvalInstance (*mknn_function_distanceEval_new)(
89  void *state_distance, MknnDomain *domain_left,
90  MknnDomain *domain_right);
91 
93  void *state_distance;
94  mknn_function_distance_build func_distance_build;
95  mknn_function_distance_load func_distance_load;
96  mknn_function_distance_save func_distance_save;
97  mknn_function_distance_release func_distance_release;
98  mknn_function_distanceEval_new func_distanceEval_new;
99 };
100 
101 void mknn_register_default_distances();
102 
103 void mknn_register_distance(MknnGeneralDomain general_domain,
104  const char *id_dist, const char *help_line,
105  mknn_function_printHelp func_printHelp,
106  mknn_function_distance_new func_distance_new);
107 
108 /* **************** */
109 
110 typedef struct MknnIndexInstance (*mknn_function_index_new)(
111  const char *id_index, MknnIndexParams *params_index,
112  MknnDataset *search_dataset, MknnDistance *distance);
113 
114 typedef void (*mknn_function_index_build)(void *state_index,
115  const char *id_index, MknnIndexParams *params_index);
116 
117 typedef void (*mknn_function_index_load)(void *state_index,
118  const char *id_index, MknnIndexParams *params_index,
119  const char *filename_read);
120 
121 typedef void (*mknn_function_index_save)(void *state_index,
122  const char *id_index, MknnIndexParams *params_index,
123  const char *filename_write);
124 
125 typedef void (*mknn_function_index_release)(void *state_index);
126 
127 /* **************** */
128 
129 typedef struct MknnResolverInstance (*mknn_function_resolver_new)(
130  void *state_index, const char *id_index,
131  MknnResolverParams *parameters_resolver);
132 
133 typedef MknnResult *(*mknn_function_resolver_search)(void *state_resolver,
134  MknnDataset *query_dataset);
135 
136 typedef void (*mknn_function_resolver_release)(void *state_resolver);
137 
139  void *state_index;
140  mknn_function_index_build func_index_build;
141  mknn_function_index_load func_index_load;
142  mknn_function_index_save func_index_save;
143  mknn_function_index_release func_index_release;
144 };
146  void *state_resolver;
147  mknn_function_resolver_search func_resolver_search;
148  mknn_function_resolver_release func_resolver_release;
149 };
150 
151 void mknn_register_default_indexes();
152 
153 void metricknn_register_index(const char *id_index, const char *help_build,
154  const char *help_search, mknn_function_printHelp func_printHelp,
155  mknn_function_index_new func_index_new,
156  mknn_function_resolver_new func_resolver_new);
157 
158 MknnResolver *mknn_resolver_newInternal(
159  struct MknnResolverInstance resolverInstance, MknnIndex *index,
160  MknnResolverParams *parameters,
161  bool free_parameters_on_resolver_release);
162 
163 /* **************** */
164 
165 MknnResult *mknn_result_newEmpty(int64_t num_queries, int64_t num_nn_max);
166 
167 void mknn_result_updateTotalDistanceEvaluations(MknnResult *result);
168 void mknn_result_setTotalSearchTime(MknnResult *result,
169  double total_search_time);
170 void mknn_result_setResolverQueryDataset(MknnResult *result,
171  MknnResolver *resolver, MknnDataset *query_dataset,
172  bool free_resolver_on_release,
173  bool free_query_dataset_on_release);
174 void mknn_result_storeMatchesInResultQuery(MknnResult *result,
175  int64_t num_query, MknnHeap *heap, int64_t cont_evaluations);
176 
177 void mknn_sample_distances_multithread(MknnDataset *dataset_src,
178  MknnDataset *dataset_dst, int64_t sample_size, MknnDistance *distance,
179  int64_t num_threads, double *out_distances, int64_t *out_position_src,
180  int64_t *out_position_dst);
181 
182 MknnHistogram *mknn_computeDistHistogram(MknnDataset *dataset,
183  int64_t num_samples, MknnDistance *distance, int64_t max_threads);
184 
192 void mknn_fillDistanceMatrix(MknnDataset *dataset, MknnDistance *distance,
193  double *distance_matrix, int64_t max_threads);
194 
195 /* **************** */
196 
197 void mknn_laesa_select_pivots_sss(MknnDataset *dataset, MknnDistance *distance,
198  int64_t num_pivots, int64_t num_sets_eval, int64_t max_threads,
199  int64_t *selected_positions);
200 
201 /* **************** */
202 
203 #ifdef WITH_OPENCV
204 #include <opencv2/core/core_c.h>
205 IplImage *mknn_dataset_convertToIplImage(MknnDataset *dataset);
206 #endif
207 
208 #ifdef __cplusplus
209 }
210 #endif
211 
212 #endif
Definition: parameters.c:18
Definition: distance.c:17
Definition: metricknn_impl.h:66
Definition: parameters.c:23
Definition: metricknn_impl.h:138
Definition: dataset.c:11
Definition: index.c:20
void(* mknn_function_distanceEval_releaseState)(void *state_distEval)
The function of a custom distance that releases a state.
Definition: mknn_distance.h:92
Definition: histogram.c:11
Definition: result.c:11
Definition: heap.c:106
Represents a broad type of objects, like strings, vectors, etc.
Definition: metricknn_c.h:28
Definition: parameters.c:28
double(* mknn_function_distanceEval_eval)(void *state_distEval, void *object_left, void *object_right, double current_threshold)
Computes the distance between two objects.
Definition: mknn_distance.h:80
Definition: resolver.c:11
Represents a constant for a datatype, like integer 8bits, float 32 bits, etc.
Definition: metricknn_c.h:35
Definition: metricknn_impl.h:145
Definition: domain.c:11
Definition: metricknn_impl.h:92
Definition: distance.c:241
Powered by Download MetricKnn