Skip to content

Commit 7f157ed

Browse files
committed
Merge branch 'master' into master_local
2 parents 1b716ca + 5308621 commit 7f157ed

File tree

9 files changed

+89
-58
lines changed

9 files changed

+89
-58
lines changed

cmake/flann_utils.cmake

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
macro(GET_OS_INFO)
22
string(REGEX MATCH "Linux" OS_IS_LINUX ${CMAKE_SYSTEM_NAME})
3-
if(OS_IS_LINUX)
4-
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
5-
set(FLANN_LIB_INSTALL_DIR "lib64")
6-
else(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
7-
set(FLANN_LIB_INSTALL_DIR "lib")
8-
endif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
9-
else(OS_IS_LINUX)
10-
set(FLANN_LIB_INSTALL_DIR "lib")
11-
endif(OS_IS_LINUX)
3+
set(FLANN_LIB_INSTALL_DIR "lib")
124
set(FLANN_INCLUDE_INSTALL_DIR
135
"include/${PROJECT_NAME_LOWER}-${FLANN_MAJOR_VERSION}.${FLANN_MINOR_VERSION}")
146
endmacro(GET_OS_INFO)

doc/manual.tex

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ \subsubsection{flann::Index}
482482
\begin{Verbatim}[fontsize=\footnotesize]
483483
struct KDTreeSingleIndexParams : public IndexParams
484484
{
485-
KDTreeSingleIndexParams( int max_leaf_size = 10 );
485+
KDTreeSingleIndexParams( int leaf_max_size = 10 );
486486
};
487487
\end{Verbatim}
488488
\begin{description}
@@ -511,7 +511,7 @@ \subsubsection{flann::Index}
511511
{
512512
HierarchicalClusteringIndexParams(int branching = 32,
513513
flann_centers_init_t centers_init = FLANN_CENTERS_RANDOM,
514-
int trees = 4, int leaf_size = 100)
514+
int trees = 4, int leaf_max_size = 100)
515515
};
516516
\end{Verbatim}
517517
\begin{description}
@@ -874,6 +874,11 @@ \subsubsection{flann\_build\_index()}
874874
float memory_weight; /* index memory weigthing factor */
875875
float sample_fraction; /* what fraction of the dataset to use for autotuning */
876876
877+
/* LSH parameters */
878+
unsigned int table_number_; /** The number of hash tables to use */
879+
unsigned int key_size_; /** The length of the key in the hash tables */
880+
unsigned int multi_probe_level_; /** Number of levels to use in multi-probe LSH, 0 for standard LSH */
881+
877882
/* other parameters */
878883
enum flann_log_level_t log_level; /* determines the verbosity of each flann function */
879884
long random_seed; /* random seed to use */
@@ -1327,14 +1332,15 @@ \subsubsection{Examples}
13271332

13281333
\subsubsection{Example 1:}
13291334

1330-
In this example the index is constructed using automatic parameter estimation, requesting 90\% as desired precision and using the default values for the build time and memory usage factors. The index is then used to search for the nearest-neighbors of the points in the testset matrix and finally the index is deleted.
1335+
In this example the index is constructed using automatic parameter estimation, requesting 70\% as desired precision and using the default values for the build time and memory usage factors. The index is then used to search for the nearest-neighbors of the points in the testset matrix and finally the index is deleted.
13311336

13321337
\begin{Verbatim}[fontsize=\footnotesize,frame=single]
13331338
13341339
dataset = single(rand(128,10000));
13351340
testset = single(rand(128,1000));
13361341
1337-
build_params.target_precision = 0.9;
1342+
build_params.algorithm = 'autotuned';
1343+
build_params.target_precision = 0.7;
13381344
build_params.build_weight = 0.01;
13391345
build_params.memory_weight = 0;
13401346
@@ -1435,7 +1441,7 @@ \subsection{Using FLANN from python}
14351441
testset = rand(1000, 128)
14361442
14371443
flann = FLANN()
1438-
params = flann.build_index(dataset, target_precision=0.9, log_level = "info");
1444+
params = flann.build_index(dataset, algorithm="autotuned", target_precision=0.9, log_level = "info");
14391445
print params
14401446
14411447
result, dists = flann.nn_index(testset,5, checks=params["checks"]);

src/cpp/CMakeLists.txt

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,7 @@ if (BUILD_CUDA_LIB)
6363
endif()
6464

6565

66-
#debug libraries
67-
add_library(flann_cpp-gd SHARED ${CPP_SOURCES})
68-
set_target_properties(flann_cpp-gd PROPERTIES
69-
COMPILE_FLAGS ${CMAKE_CXX_FLAGS_DEBUG}
70-
DEFINE_SYMBOL FLANN_EXPORTS
71-
)
7266

73-
add_library(flann_cpp_s-gd STATIC ${CPP_SOURCES})
74-
set_target_properties(flann_cpp_s-gd PROPERTIES COMPILE_FLAGS ${CMAKE_CXX_FLAGS_DEBUG})
75-
set_property(TARGET flann_cpp_s-gd PROPERTY COMPILE_DEFINITIONS FLANN_STATIC)
7667

7768

7869

@@ -95,17 +86,6 @@ if (HDF5_FOUND)
9586
endif()
9687
endif()
9788

98-
if (BUILD_CUDA_LIB)
99-
add_library(flann_cuda-gd SHARED ${CPP_SOURCES})
100-
set_target_properties(flann_cuda-gd PROPERTIES
101-
COMPILE_FLAGS ${CMAKE_CXX_FLAGS_DEBUG}
102-
DEFINE_SYMBOL FLANN_EXPORTS
103-
)
104-
105-
add_library(flann_cuda_s-gd STATIC ${CPP_SOURCES})
106-
set_target_properties(flann_cuda_s-gd PROPERTIES COMPILE_FLAGS ${CMAKE_CXX_FLAGS_DEBUG})
107-
set_property(TARGET flann_cuda_s-gd PROPERTY COMPILE_DEFINITIONS FLANN_STATIC)
108-
endif()
10989

11090
if (BUILD_C_BINDINGS)
11191
add_library(flann_s STATIC ${C_SOURCES})
@@ -129,7 +109,6 @@ if (BUILD_C_BINDINGS)
129109
)
130110
endif()
131111

132-
133112
if(WIN32)
134113
if (BUILD_C_BINDINGS)
135114
install (
@@ -141,15 +120,15 @@ endif(WIN32)
141120

142121

143122
install (
144-
TARGETS flann_cpp flann_cpp_s flann_cpp-gd flann_cpp_s-gd
123+
TARGETS flann_cpp flann_cpp_s
145124
RUNTIME DESTINATION bin
146125
LIBRARY DESTINATION ${FLANN_LIB_INSTALL_DIR}
147126
ARCHIVE DESTINATION ${FLANN_LIB_INSTALL_DIR}
148127
)
149128

150129
if (BUILD_CUDA_LIB)
151130
install (
152-
TARGETS flann_cuda flann_cuda_s flann_cuda-gd flann_cuda_s-gd
131+
TARGETS flann_cuda flann_cuda_s
153132
RUNTIME DESTINATION bin
154133
LIBRARY DESTINATION ${FLANN_LIB_INSTALL_DIR}
155134
ARCHIVE DESTINATION ${FLANN_LIB_INSTALL_DIR}

src/cpp/flann/algorithms/hierarchical_clustering_index.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct HierarchicalClusteringIndexParams : public IndexParams
5656
{
5757
HierarchicalClusteringIndexParams(int branching = 32,
5858
flann_centers_init_t centers_init = FLANN_CENTERS_RANDOM,
59-
int trees = 4, int leaf_size = 100)
59+
int trees = 4, int leaf_max_size = 100)
6060
{
6161
(*this)["algorithm"] = FLANN_INDEX_HIERARCHICAL;
6262
// The branching factor used in the hierarchical clustering
@@ -66,7 +66,7 @@ struct HierarchicalClusteringIndexParams : public IndexParams
6666
// number of parallel trees to build
6767
(*this)["trees"] = trees;
6868
// maximum leaf size
69-
(*this)["leaf_size"] = leaf_size;
69+
(*this)["leaf_max_size"] = leaf_max_size;
7070
}
7171
};
7272

@@ -101,7 +101,7 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
101101
branching_ = get_param(index_params_,"branching",32);
102102
centers_init_ = get_param(index_params_,"centers_init", FLANN_CENTERS_RANDOM);
103103
trees_ = get_param(index_params_,"trees",4);
104-
leaf_size_ = get_param(index_params_,"leaf_size",100);
104+
leaf_max_size_ = get_param(index_params_,"leaf_max_size",100);
105105

106106
initCenterChooser();
107107
}
@@ -123,7 +123,7 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
123123
branching_ = get_param(index_params_,"branching",32);
124124
centers_init_ = get_param(index_params_,"centers_init", FLANN_CENTERS_RANDOM);
125125
trees_ = get_param(index_params_,"trees",4);
126-
leaf_size_ = get_param(index_params_,"leaf_size",100);
126+
leaf_max_size_ = get_param(index_params_,"leaf_max_size",100);
127127

128128
initCenterChooser();
129129
chooseCenters_->setDataset(inputData);
@@ -138,7 +138,7 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
138138
branching_(other.branching_),
139139
trees_(other.trees_),
140140
centers_init_(other.centers_init_),
141-
leaf_size_(other.leaf_size_)
141+
leaf_max_size_(other.leaf_max_size_)
142142

143143
{
144144
initCenterChooser();
@@ -256,7 +256,7 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
256256
ar & branching_;
257257
ar & trees_;
258258
ar & centers_init_;
259-
ar & leaf_size_;
259+
ar & leaf_max_size_;
260260

261261
if (Archive::is_loading::value) {
262262
tree_roots_.resize(trees_);
@@ -273,7 +273,7 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
273273
index_params_["branching"] = branching_;
274274
index_params_["trees"] = trees_;
275275
index_params_["centers_init"] = centers_init_;
276-
index_params_["leaf_size"] = leaf_size_;
276+
index_params_["leaf_size"] = leaf_max_size_;
277277
}
278278
}
279279

@@ -485,7 +485,7 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
485485
*/
486486
void computeClustering(NodePtr node, int* indices, int indices_length)
487487
{
488-
if (indices_length < leaf_size_) { // leaf node
488+
if (indices_length < leaf_max_size_) { // leaf node
489489
node->points.resize(indices_length);
490490
for (int i=0;i<indices_length;++i) {
491491
node->points[i].index = indices[i];
@@ -638,7 +638,7 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
638638
std::swap(branching_, other.branching_);
639639
std::swap(trees_, other.trees_);
640640
std::swap(centers_init_, other.centers_init_);
641-
std::swap(leaf_size_, other.leaf_size_);
641+
std::swap(leaf_max_size_, other.leaf_max_size_);
642642
std::swap(chooseCenters_, other.chooseCenters_);
643643
}
644644

@@ -687,7 +687,7 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
687687
/**
688688
* Max size of leaf nodes
689689
*/
690-
int leaf_size_;
690+
int leaf_max_size_;
691691

692692
/**
693693
* Algorithm used to choose initial centers

src/cpp/flann/algorithms/kdtree_single_index.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ class KDTreeSingleIndex : public NNIndex<Distance>
530530
if (lim1>count/2) index = lim1;
531531
else if (lim2<count/2) index = lim2;
532532
else index = count/2;
533+
534+
assert(index > 0 && index < count);
533535
}
534536

535537

@@ -544,7 +546,6 @@ class KDTreeSingleIndex : public NNIndex<Distance>
544546
*/
545547
void planeSplit(int* ind, int count, int cutfeat, DistanceType cutval, int& lim1, int& lim2)
546548
{
547-
/* Move vector indices for left subtree to front of list. */
548549
int left = 0;
549550
int right = count-1;
550551
for (;; ) {
@@ -553,9 +554,6 @@ class KDTreeSingleIndex : public NNIndex<Distance>
553554
if (left>right) break;
554555
std::swap(ind[left], ind[right]); ++left; --right;
555556
}
556-
/* If either list is empty, it means that all remaining features
557-
* are identical. Split in the middle to maintain a balanced tree.
558-
*/
559557
lim1 = left;
560558
right = count-1;
561559
for (;; ) {

src/cpp/flann/flann.cpp

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ flann::IndexParams create_parameters(FLANNParameters* p)
6262
params["trees"] = p->trees;
6363
params["leaf_max_size"] = p->leaf_max_size;
6464
}
65+
6566
#ifdef FLANN_USE_CUDA
6667
if (p->algorithm == FLANN_INDEX_KDTREE_CUDA) {
6768
params["leaf_max_size"] = p->leaf_max_size;
@@ -85,7 +86,7 @@ flann::IndexParams create_parameters(FLANNParameters* p)
8586
params["branching"] = p->branching;
8687
params["centers_init"] = p->centers_init;
8788
params["trees"] = p->trees;
88-
params["leaf_size"] = p->leaf_max_size;
89+
params["leaf_max_size"] = p->leaf_max_size;
8990
}
9091

9192
if (p->algorithm == FLANN_INDEX_LSH) {
@@ -102,6 +103,57 @@ flann::IndexParams create_parameters(FLANNParameters* p)
102103

103104

104105

106+
107+
void update_flann_parameters(const IndexParams& params, FLANNParameters* flann_params)
108+
{
109+
if (has_param(params,"algorithm")) {
110+
flann_params->algorithm = get_param<flann_algorithm_t>(params,"algorithm");
111+
}
112+
if (has_param(params,"trees")) {
113+
flann_params->trees = get_param<int>(params,"trees");
114+
}
115+
if (has_param(params,"leaf_max_size")) {
116+
flann_params->leaf_max_size = get_param<int>(params,"leaf_max_size");
117+
}
118+
if (has_param(params,"branching")) {
119+
flann_params->branching = get_param<int>(params,"branching");
120+
}
121+
if (has_param(params,"iterations")) {
122+
flann_params->iterations = get_param<int>(params,"iterations");
123+
}
124+
if (has_param(params,"centers_init")) {
125+
flann_params->centers_init = get_param<flann_centers_init_t>(params,"centers_init");
126+
}
127+
if (has_param(params,"target_precision")) {
128+
flann_params->target_precision = get_param<float>(params,"target_precision");
129+
}
130+
if (has_param(params,"build_weight")) {
131+
flann_params->build_weight = get_param<float>(params,"build_weight");
132+
}
133+
if (has_param(params,"memory_weight")) {
134+
flann_params->memory_weight = get_param<float>(params,"memory_weight");
135+
}
136+
if (has_param(params,"sample_fraction")) {
137+
flann_params->sample_fraction = get_param<float>(params,"sample_fraction");
138+
}
139+
if (has_param(params,"table_number")) {
140+
flann_params->table_number_ = get_param<unsigned int>(params,"table_number");
141+
}
142+
if (has_param(params,"key_size")) {
143+
flann_params->key_size_ = get_param<unsigned int>(params,"key_size");
144+
}
145+
if (has_param(params,"multi_probe_level")) {
146+
flann_params->multi_probe_level_ = get_param<unsigned int>(params,"multi_probe_level");
147+
}
148+
if (has_param(params,"log_level")) {
149+
flann_params->log_level = get_param<flann_log_level_t>(params,"log_level");
150+
}
151+
if (has_param(params,"random_seed")) {
152+
flann_params->random_seed = get_param<long>(params,"random_seed");
153+
}
154+
}
155+
156+
105157
void init_flann_parameters(FLANNParameters* p)
106158
{
107159
if (p != NULL) {
@@ -142,10 +194,10 @@ flann_index_t __flann_build_index(typename Distance::ElementType* dataset, int r
142194
IndexParams params = create_parameters(flann_params);
143195
Index<Distance>* index = new Index<Distance>(Matrix<ElementType>(dataset,rows,cols), params, d);
144196
index->buildIndex();
145-
params = index->getParameters();
146197

147-
if (index->getType()==FLANN_INDEX_AUTOTUNED) {
198+
if (flann_params->algorithm==FLANN_INDEX_AUTOTUNED) {
148199
IndexParams params = index->getParameters();
200+
update_flann_parameters(params,flann_params);
149201
SearchParams search_params = get_param<SearchParams>(params,"search_params");
150202
*speedup = get_param<float>(params,"speedup");
151203
flann_params->checks = search_params.checks;

src/matlab/flann_build_index.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
% Marius Muja, January 2008
88

9-
algos = struct( 'linear', 0, 'kdtree', 1, 'kmeans', 2, 'composite', 3, 'kdtree_single', 4, 'saved', 254, 'autotuned', 255 );
9+
algos = struct( 'linear', 0, 'kdtree', 1, 'kmeans', 2, 'composite', 3, 'kdtree_single', 4, 'hierarchical', 5, 'lsh', 6, 'saved', 254, 'autotuned', 255 );
1010
center_algos = struct('random', 0, 'gonzales', 1, 'kmeanspp', 2 );
1111
log_levels = struct('none', 0, 'fatal', 1, 'error', 2, 'warning', 3, 'info', 4);
1212
function value = id2value(map, id)

src/matlab/nearest_neighbors.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,15 @@ static void flannStructToMatlabStruct( const FLANNParameters& flannParams, mxArr
8787
{
8888
mxSetField(mexParams, 0, "algorithm", to_mx_array(flannParams.algorithm));
8989
mxSetField(mexParams, 0, "checks", to_mx_array(flannParams.checks));
90+
mxSetField(mexParams, 0, "cb_index", to_mx_array(flannParams.cb_index));
91+
mxSetField(mexParams, 0, "eps", to_mx_array(flannParams.eps));
92+
9093
mxSetField(mexParams, 0, "trees", to_mx_array(flannParams.trees));
94+
mxSetField(mexParams, 0, "leaf_max_size", to_mx_array(flannParams.trees));
95+
9196
mxSetField(mexParams, 0, "branching", to_mx_array(flannParams.branching));
9297
mxSetField(mexParams, 0, "iterations", to_mx_array(flannParams.iterations));
9398
mxSetField(mexParams, 0, "centers_init", to_mx_array(flannParams.centers_init));
94-
mxSetField(mexParams, 0, "cb_index", to_mx_array(flannParams.cb_index));
9599
}
96100

97101

@@ -384,7 +388,7 @@ static void _build_index(int nOutArray, mxArray* OutArray[], int nInArray, const
384388
pOut[0] = typedIndex;
385389

386390
if (nOutArray > 1) {
387-
const char* fieldnames[] = {"algorithm", "checks", "trees", "branching", "iterations", "centers_init", "cb_index"};
391+
const char* fieldnames[] = {"algorithm", "checks", "cb_index", "eps", "trees", "leaf_max_size", "branching", "iterations", "centers_init"};
388392
OutArray[1] = mxCreateStructMatrix(1, 1, sizeof(fieldnames)/sizeof(const char*), fieldnames);
389393
flannStructToMatlabStruct(p, OutArray[1]);
390394
}

src/python/pyflann/flann_ctypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class FLANNParameters(CustomStructure):
121121
'random_seed' : -1
122122
}
123123
_translation_ = {
124-
"algorithm" : {"linear" : 0, "kdtree" : 1, "kmeans" : 2, "composite" : 3, "kdtree_simple" : 4, "saved": 254, "autotuned" : 255, "default" : 1},
124+
"algorithm" : {"linear" : 0, "kdtree" : 1, "kmeans" : 2, "composite" : 3, "kdtree_single" : 4, "hierarchical": 5, "lsh": 6, "saved": 254, "autotuned" : 255, "default" : 1},
125125
"centers_init" : {"random" : 0, "gonzales" : 1, "kmeanspp" : 2, "default" : 0},
126126
"log_level" : {"none" : 0, "fatal" : 1, "error" : 2, "warning" : 3, "info" : 4, "default" : 2}
127127
}

0 commit comments

Comments
 (0)