我有一个AoAs的哈希:
$hash{$key} = [
[0.0,1.0,2.0],
10.0,
[1.5,9.5,5.5],
];
Run Code Online (Sandbox Code Playgroud)
我需要紧缩如下:
$err += (($hash{$key}[0][$_]-$hash{key}[2][$_])*$hash{$key}[1])**2 foreach (0 .. 2);
Run Code Online (Sandbox Code Playgroud)
计算两个数组之间的平方加权差.由于我的哈希很大,我希望PDL有助于加速计算,但它不是出于某种原因.我还是PDL的新手,所以我可能搞砸了.PDL下面的脚本慢了大约10倍.描述:以下两个脚本是我试图简单地表示我的程序中的内容.我将一些参考值读入哈希值,然后我将观察值(在运行中拉入哈希值)与一些权重的那些值进行比较.在脚本中,我将引用数组,权重和观察数组设置为某个任意固定值,但在运行时不会出现这种情况.
这里有两个没有和PDL的简单脚本:
use strict;
use warnings;
use Time::HiRes qw(time);
my $t1 = time;
my %hash;
my $error = 0;
foreach (0 .. 10000){
$hash{$_} = [
[0.000, 1.000, 2.0000],
10.0,
[1.5,9.5,5.5],
];
foreach my $i (0 .. 2){
$error += (($hash{$_}[0][$i]-$hash{$_}[2][$i])*$hash{$_}[1])**2;
}
}
my $t2 = time;
printf ( "total time: %10.4f error: %10.4f\n", $t2-$t1,$error);
Run Code Online (Sandbox Code Playgroud)
use strict;
use warnings;
use PDL;
use …Run Code Online (Sandbox Code Playgroud) 我们的系统管理员最近升级了我的操作系统和perl(到5.12.3).当我加载local :: lib环境变量时,它似乎打破了依赖于xs的任何东西:
demianshell~> perl -e 'use Storable; store({a=>1}, 'test')'
demianshell~> eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)
demianshell~> perl -e 'use Storable; store({a=>1}, 'test')'
Assertion ((svtype)((_svi)->sv_flags & 0xff)) >= SVt_RV failed: file "Storable.xs", line 3753 at blib/lib/Storable.pm (autosplit into blib/lib/auto/Storable/_store.al) line 263, at -e line 1
Run Code Online (Sandbox Code Playgroud)
有一个简单的解决方案吗?