Skip to content

Commit fd390dd

Browse files
committed
Tried to make gem more robust to no flann_get_distance_type and
flann_get_distance_order functions.
1 parent 650ed86 commit fd390dd

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/ruby/lib/flann.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,11 @@ def cluster dataset, clusters, parameters = {}
271271
attach_function :flann_free_index_double, [:index_ptr, :index_params_ptr], :int
272272

273273
attach_function :flann_set_distance_type, [:distance_type, :int], :void
274-
attach_function :flann_get_distance_type, [], :distance_type
275-
attach_function :flann_get_distance_order, [], :int
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
276279

277280
attach_function :flann_compute_cluster_centers_byte, [:pointer, :int, :int, :int, :pointer, :index_params_ptr], :int
278281
attach_function :flann_compute_cluster_centers_int, [:pointer, :int, :int, :int, :pointer, :index_params_ptr], :int

src/ruby/spec/flann_spec.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,13 @@
6868

6969
context "#set_distance_type!" do
7070
it "sets the distance functor without error" do
71-
#pending "distance type unsupported in the C bindings, use the C++ bindings instead"
7271
Flann.set_distance_type! :euclidean
73-
d = Flann.get_distance_type
74-
expect(d).to eq(:euclidean)
72+
73+
# Version check needed before attempting get_distance_type
74+
if Flann.respond_to?(:flann_get_distance_type)
75+
d = Flann.get_distance_type
76+
expect(d).to eq(:euclidean)
77+
end
7578
end
7679
end
7780

0 commit comments

Comments
 (0)