| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package PDF::API2::Matrix; |
|
2
|
|
|
|
|
|
|
|
|
3
|
39
|
|
|
39
|
|
261
|
use strict; |
|
|
39
|
|
|
|
|
94
|
|
|
|
39
|
|
|
|
|
1527
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
39
|
|
|
39
|
|
199
|
use Carp; |
|
|
39
|
|
|
|
|
94
|
|
|
|
39
|
|
|
|
|
21478
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '2.048'; # VERSION |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
|
10
|
132
|
|
|
132
|
0
|
249
|
my $type = shift(); |
|
11
|
132
|
|
|
|
|
235
|
my $self = []; |
|
12
|
132
|
|
|
|
|
188
|
my $col_count = scalar(@{$_[0]}); |
|
|
132
|
|
|
|
|
228
|
|
|
13
|
132
|
|
|
|
|
259
|
foreach my $row (@_) { |
|
14
|
396
|
50
|
|
|
|
852
|
unless (scalar(@$row) == $col_count) { |
|
15
|
0
|
|
|
|
|
0
|
carp 'Inconsistent column count in matrix'; |
|
16
|
0
|
|
|
|
|
0
|
return; |
|
17
|
|
|
|
|
|
|
} |
|
18
|
396
|
|
|
|
|
1043
|
push @$self, [@$row]; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
132
|
|
|
|
|
651
|
return bless($self, $type); |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub transpose { |
|
25
|
39
|
|
|
39
|
0
|
57
|
my $self = shift(); |
|
26
|
39
|
|
|
|
|
74
|
my @result; |
|
27
|
|
|
|
|
|
|
my $m; |
|
28
|
|
|
|
|
|
|
|
|
29
|
39
|
|
|
|
|
66
|
for my $col (@{$self->[0]}) { |
|
|
39
|
|
|
|
|
158
|
|
|
30
|
117
|
|
|
|
|
218
|
push @result, []; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
39
|
|
|
|
|
79
|
for my $row (@$self) { |
|
33
|
117
|
|
|
|
|
192
|
$m = 0; |
|
34
|
117
|
|
|
|
|
204
|
for my $col (@$row) { |
|
35
|
351
|
|
|
|
|
525
|
push @{$result[$m++]}, $col; |
|
|
351
|
|
|
|
|
791
|
|
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
39
|
|
|
|
|
128
|
return PDF::API2::Matrix->new(@result); |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub vector_product { |
|
43
|
351
|
|
|
351
|
0
|
666
|
my ($a, $b) = @_; |
|
44
|
351
|
|
|
|
|
514
|
my $result = 0; |
|
45
|
|
|
|
|
|
|
|
|
46
|
351
|
|
|
|
|
483
|
for my $i (0 .. $#{$a}) { |
|
|
351
|
|
|
|
|
776
|
|
|
47
|
1053
|
|
|
|
|
2050
|
$result += $a->[$i] * $b->[$i]; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
351
|
|
|
|
|
865
|
return $result; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub multiply { |
|
54
|
39
|
|
|
39
|
0
|
70
|
my $self = shift(); |
|
55
|
39
|
|
|
|
|
117
|
my $other = shift->transpose(); |
|
56
|
39
|
|
|
|
|
74
|
my @result; |
|
57
|
|
|
|
|
|
|
|
|
58
|
39
|
50
|
|
|
|
58
|
unless ($#{$self->[0]} == $#{$other->[0]}) { |
|
|
39
|
|
|
|
|
98
|
|
|
|
39
|
|
|
|
|
119
|
|
|
59
|
0
|
|
|
|
|
0
|
carp 'Mismatched dimensions in matrix multiplication'; |
|
60
|
0
|
|
|
|
|
0
|
return; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
39
|
|
|
|
|
85
|
for my $row (@$self) { |
|
63
|
117
|
|
|
|
|
170
|
my $result_col = []; |
|
64
|
117
|
|
|
|
|
228
|
for my $col (@$other) { |
|
65
|
351
|
|
|
|
|
669
|
push @$result_col, vector_product($row, $col); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
117
|
|
|
|
|
226
|
push @result, $result_col; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
39
|
|
|
|
|
118
|
return PDF::API2::Matrix->new(@result); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |