Skip to content

Commit f1b02eb

Browse files
committed
Matlab bindings fixes in order to run on Octave. (Thanks Daniel Franke)
1 parent a43cfd1 commit f1b02eb

File tree

4 files changed

+33
-32
lines changed

4 files changed

+33
-32
lines changed

src/matlab/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ elseif(OCT_CMD)
7070
ADD_CUSTOM_COMMAND(
7171
OUTPUT ${MEX_FILE}
7272
COMMAND ${OCT_CMD}
73-
ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${MEX_NAME}.cpp -I${PROJECT_SOURCE_DIR}/src/cpp -L${FLANN_LIB_PATH} -DFLANN_STATIC -lflann_s --mex
73+
ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${MEX_NAME}.cpp -I${PROJECT_SOURCE_DIR}/src/cpp -L${FLANN_LIB_PATH} -DFLANN_STATIC -lflann_s -lgomp --mex
7474
DEPENDS flann_s ${CMAKE_CURRENT_SOURCE_DIR}/${MEX_NAME}.cpp
7575
COMMENT "Building MEX extension ${MEX_FILE}"
7676
)

src/matlab/flann_build_index.m

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,6 @@
99
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);
12-
function value = id2value(map, id)
13-
fields = fieldnames(map);
14-
for i = 1:length(fields),
15-
val = cell2mat(fields(i));
16-
if map.(val) == id
17-
value = val;
18-
break;
19-
end
20-
end
21-
end
22-
function id = value2id(map,value)
23-
id = map.(value);
24-
end
2512

2613
default_params = struct('algorithm', 'kdtree' ,'checks', 32, 'eps', 0.0, 'sorted', 1, 'max_neighbors', -1, 'cores', 1, 'trees', 4, 'branching', 32, 'iterations', 5, 'centers_init', 'random', 'cb_index', 0.4, 'target_precision', 0.9,'build_weight', 0.01, 'memory_weight', 0, 'sample_fraction', 0.1, 'log_level', 'warning', 'random_seed', 0);
2714

@@ -54,3 +41,17 @@
5441
params.centers_init = id2value(center_algos,params.centers_init);
5542
end
5643
end
44+
45+
function value = id2value(map, id)
46+
fields = fieldnames(map);
47+
for i = 1:length(fields),
48+
val = cell2mat(fields(i));
49+
if map.(val) == id
50+
value = val;
51+
break;
52+
end
53+
end
54+
end
55+
function id = value2id(map,value)
56+
id = map.(value);
57+
end

src/matlab/flann_search.m

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,9 @@
3737
algos = struct( 'linear', 0, 'kdtree', 1, 'kmeans', 2, 'composite', 3, 'saved', 254, 'autotuned', 255 );
3838
center_algos = struct('random', 0, 'gonzales', 1, 'kmeanspp', 2 );
3939
log_levels = struct('none', 0, 'fatal', 1, 'error', 2, 'warning', 3, 'info', 4);
40-
function value = id2value(map, id)
41-
fields = fieldnames(map);
42-
for i = 1:length(fields),
43-
val = cell2mat(fields(i));
44-
if map.(val) == id
45-
value = val;
46-
break;
47-
end
48-
end
49-
end
50-
function id = value2id(map,value)
51-
id = map.(value);
52-
end
5340

5441
default_params = struct('algorithm', 'kdtree' ,'checks', 32, 'eps', 0.0, 'sorted', 1, 'max_neighbors', -1, 'cores', 1, 'trees', 4, 'branching', 32, 'iterations', 5, 'centers_init', 'random', 'cb_index', 0.4, 'target_precision', 0.9,'build_weight', 0.01, 'memory_weight', 0, 'sample_fraction', 0.1, 'log_level', 'warning', 'random_seed', 0);
5542

56-
5743
if ~isstruct(search_params)
5844
error('The "search_params" argument must be a structure');
5945
end
@@ -82,3 +68,17 @@
8268
[indices,dists] = nearest_neighbors('find_nn', data, testset, n, params);
8369
end
8470
end
71+
72+
function value = id2value(map, id)
73+
fields = fieldnames(map);
74+
for i = 1:length(fields),
75+
val = cell2mat(fields(i));
76+
if map.(val) == id
77+
value = val;
78+
break;
79+
end
80+
end
81+
end
82+
function id = value2id(map,value)
83+
id = map.(value);
84+
end

src/matlab/flann_set_distance_type.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ function flann_set_distance_type(type, order)
3030
% Marius Muja, March 2009
3131

3232
distances = struct('euclidean', 1, 'manhattan', 2, 'minkowski', 3, 'max_dist', 4, 'hik', 5, 'hellinger', 6, 'chi_square', 7, 'cs', 7, 'kullback_leibler', 8, 'kl', 8);
33-
function id = value2id(map,value)
34-
id = map.(value);
35-
end
36-
3733

3834
if ~isnumeric(type),
3935
type = value2id(distances,type);
@@ -43,3 +39,7 @@ function flann_set_distance_type(type, order)
4339
end
4440
nearest_neighbors('set_distance_type', type, order);
4541
end
42+
43+
function id = value2id(map,value)
44+
id = map.(value);
45+
end

0 commit comments

Comments
 (0)