I've tried using PDL to multiply arrays in a faster way, but get an error with one-element piddles. The example code is
use PDL::Core;
use PDL::Primitive;
my $m = [ [ 2 ] ];
pdl($m) x pdl($m);
The error is:
Undefined subroutine &PDL::mult called at /home/user/perl5/lib/perl5/x86_64-linux-gnu-thread-multi/PDL/Primitive.pm line 263.
Primitive.pm
source code is:
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;
It seems that multiplication is not defined when there is a single element. Is this a bug? Way it is the adequate way to solve it?