Skip to content

Commit dd905e7

Browse files
author
Marius Muja
committed
Merge branch 'master' of https://github.com/mohawkjohn/flann
2 parents b5b5623 + fbb3e72 commit dd905e7

File tree

5 files changed

+65604
-10
lines changed

5 files changed

+65604
-10
lines changed

src/ruby/lib/flann.rb

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,19 @@ class Parameters < InitializableStruct
105105

106106
DEFAULT = {algorithm: :kdtree,
107107
checks: 32, eps: 0.0,
108-
sorted: 0, max_neighbors: -1, cores: 0,
109-
trees: 4, leaf_max_size: 4,
110-
log_level: :none, random_seed: 0}
108+
sorted: 1, max_neighbors: -1, cores: 0,
109+
trees: 1, leaf_max_size: 4,
110+
branching: 32, iterations: 5,
111+
centers_init: :random,
112+
cluster_boundary_index: 0.5,
113+
target_precision: 0.9,
114+
build_weight: 0.01,
115+
memory_weight: 0.0,
116+
sample_fraction: 0.1,
117+
table_number: 12,
118+
key_size: 20,
119+
multi_probe_level: 2,
120+
log_level: :warn, random_seed: -1}
111121

112122

113123
end
@@ -271,11 +281,9 @@ def cluster dataset, clusters, parameters = {}
271281
attach_function :flann_free_index_double, [:index_ptr, :index_params_ptr], :int
272282

273283
attach_function :flann_set_distance_type, [:distance_type, :int], :void
274-
begin
275-
attach_function :flann_get_distance_type, [], :distance_type
276-
attach_function :flann_get_distance_order, [], :int
277-
rescue FFI::NotFoundError
278-
end
284+
285+
attach_function :flann_get_distance_type, [], :distance_type
286+
attach_function :flann_get_distance_order, [], :int
279287

280288
attach_function :flann_compute_cluster_centers_byte, [:pointer, :int, :int, :int, :pointer, :index_params_ptr], :int
281289
attach_function :flann_compute_cluster_centers_int, [:pointer, :int, :int, :int, :pointer, :index_params_ptr], :int

src/ruby/lib/flann/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module VERSION
3030
MAJOR = 1
3131
MINOR = 8
3232
TINY = 4
33-
MINISCULE = 1
33+
MINISCULE = 2
3434

3535
STRING = [MAJOR, MINOR, TINY, MINISCULE].compact.join('.')
3636
end

src/ruby/spec/index_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,37 @@
4848
it "runs without error" do
4949
@index.nearest_neighbors @testset, 5
5050
end
51+
52+
if dtype == :float32
53+
it "runs a :kdtree_single search correctly" do
54+
@dataset = read_dataset "test.dataset"
55+
@testset = @dataset[0,:*].clone
56+
@index = Flann::Index.new(@dataset) do |t|
57+
t[:algorithm] = :kdtree_single
58+
end
59+
@index.build!
60+
indices, distances = @index.nearest_neighbors @testset, 11
61+
#expect(indices).to eq([0,1,256,257,2,512,258,513,514,3,768])
62+
expect(indices[0]).to eq(0)
63+
expect(indices[1..2].sort).to eq([1,256])
64+
expect(indices[3]).to eq(257)
65+
expect(indices[4..5].sort).to eq([2,512])
66+
expect(indices[6..7].sort).to eq([258,513])
67+
expect(indices[8]).to eq(514)
68+
expect(indices[9..10].sort).to eq([3,768])
69+
70+
expect(distances[0]).to be_within(1E-16).of(0.0)
71+
expect(distances[1]).to be_within(1E-4).of(2.614689)
72+
expect(distances[2]).to be_within(1E-4).of(2.614689)
73+
expect(distances[3]).to be_within(1E-4).of(5.229378)
74+
expect(distances[4]).to be_within(1E-4).of(10.465225)
75+
expect(distances[5]).to be_within(1E-4).of(10.465225)
76+
expect(distances[6]).to be_within(1E-4).of(13.079914)
77+
expect(distances[7]).to be_within(1E-4).of(13.079914)
78+
expect(distances[8]).to be_within(1E-4).of(20.93045)
79+
expect(distances[9]).to be_within(1E-4).of(23.541904)
80+
end
81+
end
5182
end
5283

5384

src/ruby/spec/spec_helper.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,23 @@
2828
require 'rspec'
2929
require 'rspec/longrun'
3030

31-
require "./lib/flann"
31+
require "./lib/flann"
32+
33+
# Helper function for reading a test dataset so we can test nearest neighbors
34+
# and radius search and such.
35+
def read_dataset filename
36+
Dir.chdir("spec") do
37+
f = File.new(filename, 'r')
38+
n = NMatrix.new([65536, 3], dtype: :float32)
39+
i = 0
40+
while line = f.gets
41+
line.chomp!
42+
fields = line.split
43+
n[i,:*] = fields.map { |field| field.to_f }
44+
45+
i += 1
46+
end
47+
48+
n
49+
end
50+
end

0 commit comments

Comments
 (0)