Skip to content

Commit

Permalink
Tried to make gem more robust to no flann_get_distance_type and
Browse files Browse the repository at this point in the history
flann_get_distance_order functions.
  • Loading branch information
translunar committed Mar 8, 2014
1 parent 650ed86 commit fd390dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/ruby/lib/flann.rb
Expand Up @@ -271,8 +271,11 @@ def cluster dataset, clusters, parameters = {}
attach_function :flann_free_index_double, [:index_ptr, :index_params_ptr], :int

attach_function :flann_set_distance_type, [:distance_type, :int], :void
attach_function :flann_get_distance_type, [], :distance_type
attach_function :flann_get_distance_order, [], :int
begin
attach_function :flann_get_distance_type, [], :distance_type
attach_function :flann_get_distance_order, [], :int
rescue FFI::NotFoundError
end

attach_function :flann_compute_cluster_centers_byte, [:pointer, :int, :int, :int, :pointer, :index_params_ptr], :int
attach_function :flann_compute_cluster_centers_int, [:pointer, :int, :int, :int, :pointer, :index_params_ptr], :int
Expand Down
9 changes: 6 additions & 3 deletions src/ruby/spec/flann_spec.rb
Expand Up @@ -68,10 +68,13 @@

context "#set_distance_type!" do
it "sets the distance functor without error" do
#pending "distance type unsupported in the C bindings, use the C++ bindings instead"
Flann.set_distance_type! :euclidean
d = Flann.get_distance_type
expect(d).to eq(:euclidean)

# Version check needed before attempting get_distance_type
if Flann.respond_to?(:flann_get_distance_type)
d = Flann.get_distance_type
expect(d).to eq(:euclidean)
end
end
end

Expand Down

0 comments on commit fd390dd

Please sign in to comment.