Skip to content

Commit 7cbaa65

Browse files
committed
Added skeleton files for Ruby gem, enabled find nearest neighbors with
and without indexing.
1 parent 9125041 commit 7cbaa65

File tree

7 files changed

+192
-0
lines changed

7 files changed

+192
-0
lines changed

src/ruby/Gemfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
source 'https://rubygems.org'
2+
gemspec
3+
4+
gem "ffi"
5+
gem "nmatrix"
6+
7+
group :development do
8+
9+
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Rakefile
2+
Gemfile
3+
flann.gemspec
4+
lib/flann.rb
5+
lib/index.rb
6+
spec/basic_spec.rb
7+
spec/spec_helper.rb

src/ruby/Rakefile

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
require 'rubygems'
2+
require 'rubygems/package_task'
3+
require 'bundler'
4+
begin
5+
Bundler.setup(:default, :development)
6+
rescue
7+
$stderr.puts e.message
8+
$stderr.puts "Run `bundle install` to install missing gems"
9+
exit e.status_code
10+
end
11+
12+
require 'rake'
13+
14+
gemspec = eval(IO.read("flann.gemspec"))
15+
16+
Gem::PackageTask.new(gemspec).define
17+
18+
desc "install the gem locally"
19+
task :install => [:package] do
20+
sh %{gem install pkg/flann-#{NMatrix::VERSION}.gem}
21+
end
22+
23+
24+
require 'rspec/core/rake_task'
25+
require 'rspec/core'
26+
require 'rspec/core/rake_task'
27+
RSpec::Core::RakeTask.new(:spec) do |spec|
28+
spec.pattern = FileList['spec/**/*_spec.rb'].uniq
29+
end
30+
31+
task :console do |task|
32+
cmd = [ 'irb', "-r './lib/flann.rb'" ]
33+
run *cmd
34+
end
35+
36+
task :pry do |task|
37+
cmd = [ 'pry', "-r './lib/flann.rb'" ]
38+
run *cmd
39+
end
40+
41+
42+
task :default => :spec
43+
44+
def run *cmd
45+
sh(cmd.join(" "))
46+
end
47+
48+
49+
desc "Check the manifest for correctness"
50+
task :check_manifest do |task|
51+
manifest_files = File.read("Manifest.txt").split
52+
53+
git_files = `git ls-files |grep -v 'spec/'`.split
54+
ignore_files = %w{.gitignore .rspec}
55+
56+
possible_files = git_files - ignore_files
57+
58+
missing_files = possible_files - manifest_files
59+
extra_files = manifest_files - possible_files
60+
61+
unless missing_files.empty?
62+
STDERR.puts "The following files are in the git repo but not the Manifest:"
63+
missing_files.each { |f| STDERR.puts " -- #{f}"}
64+
end
65+
66+
unless extra_files.empty?
67+
STDERR.puts "The following files are in the Manifest but may not be necessary:"
68+
extra_files.each { |f| STDERR.puts " -- #{f}"}
69+
end
70+
71+
if extra_files.empty? && missing_files.empty?
72+
STDERR.puts "Manifest looks good!"
73+
end
74+
75+
end
76+
77+
78+
require "rdoc/task"
79+
RDoc::Task.new do |rdoc|
80+
rdoc.main = "README.rdoc"
81+
rdoc.rdoc_files.include(%w{README.rdoc History.txt LICENSE.txt lib/flann/**/*.rb})
82+
end
83+
84+
# vim: syntax=ruby

src/ruby/flann.gemspec

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
lib = File.expand_path('../lib/', __FILE__)
2+
$:.unshift lib unless $:.include?(lib)
3+
4+
# require 'flann/version'
5+
6+
Gem::Specification.new do |gem|
7+
gem.name = "flann"
8+
gem.version = '0.0.1'
9+
gem.summary = "Ruby interface for FLANN, approximate nearest neighbors methods in C"
10+
gem.description = "Ruby interface for FLANN, approximate nearest neighbors methods in C"
11+
gem.homepage = 'http://www.cs.ubc.ca/research/flann/'
12+
gem.authors = ['John Woods']
13+
gem.email = ['[email protected]']
14+
gem.license = 'BSD 2-clause'
15+
#gem.post_install_message = <<-EOF
16+
#EOF
17+
18+
gem.files = `git ls-files`.split("\n")
19+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21+
gem.require_paths = ["lib"]
22+
23+
gem.required_ruby_version = '>= 2.0'
24+
25+
gem.add_dependency 'rdoc'
26+
gem.add_development_dependency 'rake'
27+
gem.add_development_dependency 'bundler'
28+
gem.add_development_dependency 'rspec'
29+
gem.add_development_dependency 'pry'
30+
end
31+

src/ruby/spec/basic_spec.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
require File.dirname(__FILE__) + "/spec_helper.rb"
2+
3+
describe Flann do
4+
it "handles the example script without error" do
5+
dataset = NMatrix.random([1000,128])
6+
testset = NMatrix.random([100,128])
7+
8+
Flann.nearest_neighbors dataset, testset, 5
9+
end
10+
11+
it "#nearest_neighbors_by_index runs without error" do
12+
dataset = NMatrix.random([1000,128])
13+
testset = NMatrix.random([100,128])
14+
15+
index = Flann::Index.new(:dataset => dataset) do |t|
16+
t[:algorithm] = :kdtree
17+
t[:trees] = 4
18+
end
19+
index.build!
20+
21+
Flann.nearest_neighbors_by_index index, testset, 5
22+
end
23+
end
24+
25+
26+
describe Flann::Index do
27+
context "#new" do
28+
it "creates a kdtree index" do
29+
Flann::Index.new do |t|
30+
t[:algorithm] = :kdtree
31+
t[:trees] = 4
32+
end
33+
end
34+
end
35+
36+
37+
context "#build!" do
38+
it "builds a kdtree index with block parameters" do
39+
dataset = NMatrix.random([1000,128])
40+
index = Flann::Index.new(dataset: dataset) do |t|
41+
t[:algorithm] = :kdtree
42+
t[:trees] = 4
43+
end
44+
45+
index.build!
46+
end
47+
end
48+
end

src/ruby/spec/spec_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'rspec'
2+
3+
require "./lib/flann"

0 commit comments

Comments
 (0)