1use Test::More tests => 7;
2use PDL::LiteF;
3use Test::Exception;
4
5use strict;
6use warnings;
7
8my $pa = pdl [[ 1,  2,  3,  0],
9      [ 1, -1,  2,  7],
10      [ 1,  0,  0,  1]];
11
12my $pb = pdl [[1, 1],
13     [0, 2],
14     [0, 2],
15     [1, 1]];
16
17my $pc = pdl [[ 1, 11],
18      [ 8, 10],
19      [ 2,  2]];
20
21my $res = $pa x $pb;
22
23ok(all approx($pc,$res));
24
25my $eq = float [[1,1,1,1]];  # a 4,1-matrix ( 1 1 1 1 )
26
27# Check collapse: output should be a 1x2...
28ok(all approx($eq x $pb  , pdl([[2,6]]) )); # ([4x1] x [2x4] -> [1x2])
29
30# Check dimensional exception: mismatched dims should throw an error
31dies_ok {
32	my $pz = $pb x $eq; # [2x4] x [4x1] --> error (2 != 1)
33};
34
35{
36# Check automatic scalar multiplication
37my $pz;
38lives_ok { $pz = $pb x 2; };
39ok( all approx($pz,$pb * 2));
40}
41
42{
43my $pz;
44lives_ok { $pz = pdl(3) x $pb; };
45ok( all approx($pz,$pb * 3));
46}
47