Skip to content

Commit 935090c

Browse files
committed
Limited radius search so that it doesn't return elements beyond index =
-1.
1 parent 678050d commit 935090c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/ruby/lib/flann/index.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,12 @@ def radius_search query, radius, max_k=nil, parameters = {}
122122
Flann.send(c_method, index_ptr, FFI::Pointer.new_from_nmatrix(query), indices_int_ptr, distances_t_ptr, max_k, radius, parameters_ptr)
123123

124124
# Return results: two arrays, one of indices and one of distances.
125-
[indices_int_ptr.read_array_of_int(max_k),
126-
c_type == :double ? distances_t_ptr.read_array_of_double(max_k) : distances_t_ptr.read_array_of_float(max_k)]
125+
indices = indices_int_ptr.read_array_of_int(max_k)
126+
distances = c_type == :double ? distances_t_ptr.read_array_of_double(max_k) : distances_t_ptr.read_array_of_float(max_k)
127+
128+
# Stop where indices == -1
129+
cutoff = indices.find_index(-1)
130+
cutoff.nil? ? [indices, distances] : [indices[0...cutoff], distances[0...cutoff]]
127131
end
128132

129133
# Save an index to a file (without the dataset).

0 commit comments

Comments
 (0)