Skip to content

Commit b5b5623

Browse files
author
Marius Muja
committed
Merge
2 parents e5b9cbe + 935090c commit b5b5623

File tree

17 files changed

+978
-5
lines changed

17 files changed

+978
-5
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ test/flann_simple_test
1515
test/flann_uint_autotune.py
1616
build
1717
build_win
18-
lib
1918
dist/
2019
flann.kdev4
2120
TODO

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FLANN - Fast Library for Approximate Nearest Neighbors
22
======================================================
33

44
FLANN is a library for performing fast approximate nearest neighbor searches in high dimensional spaces. It contains a collection of algorithms we found to work best for nearest neighbor search and a system for automatically choosing the best algorithm and optimum parameters depending on the dataset.
5-
FLANN is written in C++ and contains bindings for the following languages: C, MATLAB and Python.
5+
FLANN is written in C++ and contains bindings for the following languages: C, MATLAB, Python, and Ruby.
66

77

88
Documentation

doc/manual.pdf

-279 KB
Binary file not shown.

doc/manual.tex

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ \section{Introduction}
5050
FLANN (Fast Library for Approximate Nearest Neighbors) is a library for
5151
performing fast approximate nearest neighbor searches. FLANN is written in
5252
the C++ programming language. FLANN can be easily used in many contexts
53-
through the C, MATLAB and Python bindings provided with the library.
53+
through the C, MATLAB, Python, and Ruby bindings provided with the library.
5454

5555

5656

@@ -59,7 +59,7 @@ \subsection{Quick Start}
5959

6060

6161
This section contains small examples of how to use the FLANN library from
62-
different programming languages (C++, C, MATLAB and Python).
62+
different programming languages (C++, C, MATLAB, Python, and Ruby).
6363

6464
\begin{itemize}
6565

@@ -187,6 +187,31 @@ \subsection{Quick Start}
187187
branching=32, iterations=7, checks=16);
188188
\end{Verbatim}
189189

190+
\item \textbf{Ruby}
191+
\begin{Verbatim}[fontsize=\scriptsize,frame=single]
192+
require 'flann' # also requires NMatrix
193+
194+
dataset = NMatrix.random([10000,128])
195+
testset = NMatrix.random([1000,128])
196+
197+
index = Flann::Index.new(dataset) do |params|
198+
params[:algorithm] = :kmeans
199+
params[:branching] = 32
200+
params[:iterations] = 7
201+
params[:checks] = 16
202+
end
203+
speedup = index.build! # this is optional
204+
205+
results, distances = index.nearest_neighbors(testset, 5)
206+
207+
index.save "my_index.save"
208+
209+
# Alternatively, without an index:
210+
results, distances = Flann.nearest_neighbors(dataset, testset, 5,
211+
algorithm: :kmeans, branching: 32,
212+
iterations: 7, checks: 16)
213+
214+
\end{Verbatim}
190215
\end{itemize}
191216

192217

@@ -1539,7 +1564,7 @@ \subsection{Using FLANN from python}
15391564

15401565

15411566

1542-
See section \ref{sec:quickstart} for an example of how to use the Python
1567+
See section \ref{sec:quickstart} for an example of how to use the Python and Ruby
15431568
bindings.
15441569

15451570

src/cpp/flann/flann.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ void flann_set_distance_type(flann_distance_t distance_type, int order)
191191
}
192192

193193

194+
flann_distance_t flann_get_distance_type() {
195+
return flann_distance_type;
196+
}
197+
198+
int flann_get_distance_order() {
199+
return flann_distance_order;
200+
}
201+
202+
194203
template<typename Distance>
195204
flann_index_t __flann_build_index(typename Distance::ElementType* dataset, int rows, int cols, float* speedup,
196205
FLANNParameters* flann_params, Distance d = Distance())

src/cpp/flann/flann.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ FLANN_EXPORT void flann_log_verbosity(int level);
100100
*/
101101
FLANN_EXPORT void flann_set_distance_type(enum flann_distance_t distance_type, int order);
102102

103+
/**
104+
* Gets the distance type in use throughout FLANN.
105+
*/
106+
FLANN_EXPORT enum flann_distance_t flann_get_distance_type();
107+
108+
/**
109+
* Gets the distance order in use throughout FLANN (only applicable if minkowski distance
110+
* is in use).
111+
*/
112+
FLANN_EXPORT int flann_get_distance_order();
103113

104114
/**
105115
Builds and returns an index. It uses autotuning if the target_precision field of index_params

src/ruby/Gemfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2014 John O. Woods ([email protected]), West Virginia
2+
# University's Applied Space Exploration Lab, and West Virginia Robotic
3+
# Technology Center. All rights reserved.
4+
#
5+
# THE BSD LICENSE
6+
#
7+
# Redistribution and use in source and binary forms, with or without
8+
# modification, are permitted provided that the following conditions
9+
# are met:
10+
#
11+
# 1. Redistributions of source code must retain the above copyright
12+
# notice, this list of conditions and the following disclaimer.
13+
# 2. Redistributions in binary form must reproduce the above copyright
14+
# notice, this list of conditions and the following disclaimer in the
15+
# documentation and/or other materials provided with the distribution.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19+
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20+
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22+
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26+
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
28+
source 'https://rubygems.org'
29+
gemspec
30+
31+
gem "ffi"
32+
gem "nmatrix"
33+
34+
group :development do
35+
36+
end

src/ruby/LICENSE.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Copyright (c) 2014, John Woods, WVU Applied Space Exploration Laboratory, and West Virginia Robotic Technology Center.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5+
6+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7+
8+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9+
10+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

src/ruby/Manifest.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Rakefile
2+
Gemfile
3+
LICENSE.txt
4+
Manifest.txt
5+
flann.gemspec
6+
lib/flann.rb
7+
lib/index.rb
8+
lib/flann/index.rb
9+
lib/flann/version.rb
10+
spec/spec_helper.rb
11+
spec/flann_spec.rb
12+
spec/index_spec.rb

src/ruby/Rakefile

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Copyright 2014 John O. Woods ([email protected]), West Virginia
2+
# University's Applied Space Exploration Lab, and West Virginia Robotic
3+
# Technology Center. All rights reserved.
4+
#
5+
# THE BSD LICENSE
6+
#
7+
# Redistribution and use in source and binary forms, with or without
8+
# modification, are permitted provided that the following conditions
9+
# are met:
10+
#
11+
# 1. Redistributions of source code must retain the above copyright
12+
# notice, this list of conditions and the following disclaimer.
13+
# 2. Redistributions in binary form must reproduce the above copyright
14+
# notice, this list of conditions and the following disclaimer in the
15+
# documentation and/or other materials provided with the distribution.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19+
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20+
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22+
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26+
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
28+
require 'rubygems'
29+
require 'rubygems/package_task'
30+
require 'bundler'
31+
begin
32+
Bundler.setup(:default, :development)
33+
rescue
34+
$stderr.puts e.message
35+
$stderr.puts "Run `bundle install` to install missing gems"
36+
exit e.status_code
37+
end
38+
39+
require 'rake'
40+
41+
gemspec = eval(IO.read("flann.gemspec"))
42+
43+
Gem::PackageTask.new(gemspec).define
44+
45+
desc "install the gem locally"
46+
task :install => [:package] do
47+
sh %{gem install pkg/flann-#{NMatrix::VERSION}.gem}
48+
end
49+
50+
51+
require 'rspec/core/rake_task'
52+
require 'rspec/core'
53+
require 'rspec/core/rake_task'
54+
RSpec::Core::RakeTask.new(:spec) do |spec|
55+
spec.pattern = FileList['spec/**/*_spec.rb'].uniq
56+
end
57+
58+
task :console do |task|
59+
cmd = [ 'irb', "-r './lib/flann.rb'" ]
60+
run *cmd
61+
end
62+
63+
task :pry do |task|
64+
cmd = [ 'pry', "-r './lib/flann.rb'" ]
65+
run *cmd
66+
end
67+
68+
69+
task :default => :spec
70+
71+
def run *cmd
72+
sh(cmd.join(" "))
73+
end
74+
75+
76+
desc "Check the manifest for correctness"
77+
task :check_manifest do |task|
78+
manifest_files = File.read("Manifest.txt").split
79+
80+
git_files = `git ls-files |grep -v 'spec/'`.split
81+
ignore_files = %w{.gitignore .rspec}
82+
83+
possible_files = git_files - ignore_files
84+
85+
missing_files = possible_files - manifest_files
86+
extra_files = manifest_files - possible_files
87+
88+
unless missing_files.empty?
89+
STDERR.puts "The following files are in the git repo but not the Manifest:"
90+
missing_files.each { |f| STDERR.puts " -- #{f}"}
91+
end
92+
93+
unless extra_files.empty?
94+
STDERR.puts "The following files are in the Manifest but may not be necessary:"
95+
extra_files.each { |f| STDERR.puts " -- #{f}"}
96+
end
97+
98+
if extra_files.empty? && missing_files.empty?
99+
STDERR.puts "Manifest looks good!"
100+
end
101+
102+
end
103+
104+
105+
require "rdoc/task"
106+
RDoc::Task.new do |rdoc|
107+
rdoc.main = "README.rdoc"
108+
rdoc.rdoc_files.include(%w{README.rdoc History.txt LICENSE.txt lib/flann/**/*.rb})
109+
end
110+
111+
# vim: syntax=ruby

0 commit comments

Comments
 (0)