0
我运行JRuby 1.6.7在红宝石1.8“需要”宝石错误JRuby中
我可以安装宝石:https://github.com/consti/tupalo-kdtree。
我有下面的代码:
require 'kdtree'
require 'benchmark'
def setup_tree(len)
@points = (0...len).map { |i| [rand_coord, rand_coord, i ] }
@kdtree = KDTree.new(@points)
end
def distance(a, b)
x, y = a[0] - b[0], a[1] - b[1]
x * x + y * y
end
def rand_coord
rand(0) * 10 - 5
end
def test_nearestk
pt = []
@list = []
20000.times do
pt = [rand_coord, rand_coord]
# kdtree search
@list << @kdtree.nearest(pt[0],pt[1]) #puts pt
end
puts "Points from search #{@list.size}"
puts "Points in graph #{@kdsize}"
end
@kdsize = 50000
setup_tree(@kdsize)
Benchmark.bm do |x|
x.report do
test_nearestk
end
end
然而,当我在JRuby中运行这个 - 我得到的错误
LoadError: no such file to load -- kdtree
require at org/jruby/RubyKernel.java:982
require at /home/charlie/.rvm/rubies/jruby-head/lib/ruby/shared/rubygems/custom_require.rb:36
(root) at newtest.rb:2
它的奇怪,因为它是说它甚至找不到kdtree - 当我知道它在那里 - 安装了宝石。我已经清理了gemset并在RVM下创建了一个新的gemset,但仍然出现了同样的错误。 jruby下有'require'的不同方式吗?或者还有其他问题吗?