我正在尝试使用CPAN模块:Math::Vector::Real::Neighbors
我看到以下错误消息:
无法在/usr/local/share/perl/5.14.2/Math/Vector/Real/Neighbors.pm第12行通过包“Math :: Vector :: Real”找到对象方法“box”。< / p>
所以,我进入包中看到:my ($bottom, $top) = Math::Vector::Real->box(@_);
接下来,我将进入Real.pm
包裹:/usr/local/share/perl/5.14.2/Math/Vector/Real.pm
我看到其中存在box子例程:sub box {...
知道错误可能会出现的原因吗?
答案 0 :(得分:7)
您需要在脚本顶部添加use Math::Vector::Real
才能使Math :: Vector :: Real :: Neighbors正常工作。以下代码按预期运行:
use strict;
use warnings;
use Math::Vector::Real;
use Math::Vector::Real::Neighbors;
use Math::Vector::Real::Random;
my @v = map Math::Vector::Real->random_normal(2), 0..1000;
my @nearest_ixs = Math::Vector::Real::Neighbors->neighbors(@v);
但请注意,如果没有使用Math :: Vector :: Real 这行,它就无效。
答案 1 :(得分:2)
我是Math :: Vector :: Real系列Perl模块的作者。
如今,为了找到一组点的邻居,Math::Vector::Real::kdTree中提供的算法要好得多:
my @v = ...;
my $kdtree = Math::Vector::Real::kdTree->new(@v);
my @nearest_ixs = $kdtree->find_nearest_vector_all_internal;