我尝试使用 PDL 以更快的方式将数组相乘,但使用单元素 piddles 时出现错误。示例代码是
use PDL::Core;
use PDL::Primitive;
my $m = [ [ 2 ] ];
pdl($m) x pdl($m);
错误是:
Undefined subroutine &PDL::mult called at /home/user/perl5/lib/perl5/x86_64-linux-gnu-thread-multi/PDL/Primitive.pm line 263.
Primitive.pm
源代码是:
sub PDL::matmult {
my ($a,$b,$c) = @_;
$b = pdl($b) unless eval { $b->isa('PDL') };
$c = PDL->null unless eval { $c->isa('PDL') };
while($a->getndims < 2) {$a = $a->dummy(-1)}
while($b->getndims < 2) {$b = $b->dummy(-1)}
return ($c .= $a * $b) if( ($a->dim(0)==1 && $a->dim(1)==1) ||
($b->dim(0)==1 && $b->dim(1)==1) );
if($b->dim(1) != $a->dim(0)) {
barf(sprintf("Dim mismatch in matmult of [%dx%d] x [%dx%d]: %d != %d",$a->dim(0),$a->dim(1),$b->dim(0),$b->dim(1),$a->dim(0),$b->dim(1)));
}
PDL::_matmult_int($a,$b,$c);
$c;
}
*matmult = \&PDL::matmult;
当只有一个元素时,似乎没有定义乘法。这是一个错误吗?方法是解决它的适当方法吗?