| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package PDF::API2::Matrix; |
|
2
|
|
|
|
|
|
|
|
|
3
|
38
|
|
|
38
|
|
305
|
use strict; |
|
|
38
|
|
|
|
|
79
|
|
|
|
38
|
|
|
|
|
1088
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
38
|
|
|
38
|
|
192
|
use Carp; |
|
|
38
|
|
|
|
|
86
|
|
|
|
38
|
|
|
|
|
18339
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '2.044'; # VERSION |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
|
10
|
132
|
|
|
132
|
0
|
195
|
my $type = shift(); |
|
11
|
132
|
|
|
|
|
210
|
my $self = []; |
|
12
|
132
|
|
|
|
|
168
|
my $col_count = scalar(@{$_[0]}); |
|
|
132
|
|
|
|
|
182
|
|
|
13
|
132
|
|
|
|
|
199
|
foreach my $row (@_) { |
|
14
|
396
|
50
|
|
|
|
654
|
unless (scalar(@$row) == $col_count) { |
|
15
|
0
|
|
|
|
|
0
|
carp 'Inconsistent column count in matrix'; |
|
16
|
0
|
|
|
|
|
0
|
return; |
|
17
|
|
|
|
|
|
|
} |
|
18
|
396
|
|
|
|
|
831
|
push @$self, [@$row]; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
132
|
|
|
|
|
457
|
return bless($self, $type); |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub transpose { |
|
25
|
39
|
|
|
39
|
0
|
51
|
my $self = shift(); |
|
26
|
39
|
|
|
|
|
60
|
my @result; |
|
27
|
|
|
|
|
|
|
my $m; |
|
28
|
|
|
|
|
|
|
|
|
29
|
39
|
|
|
|
|
54
|
for my $col (@{$self->[0]}) { |
|
|
39
|
|
|
|
|
84
|
|
|
30
|
117
|
|
|
|
|
181
|
push @result, []; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
39
|
|
|
|
|
69
|
for my $row (@$self) { |
|
33
|
117
|
|
|
|
|
138
|
$m = 0; |
|
34
|
117
|
|
|
|
|
163
|
for my $col (@$row) { |
|
35
|
351
|
|
|
|
|
405
|
push @{$result[$m++]}, $col; |
|
|
351
|
|
|
|
|
538
|
|
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
39
|
|
|
|
|
89
|
return PDF::API2::Matrix->new(@result); |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub vector_product { |
|
43
|
351
|
|
|
351
|
0
|
491
|
my ($a, $b) = @_; |
|
44
|
351
|
|
|
|
|
404
|
my $result = 0; |
|
45
|
|
|
|
|
|
|
|
|
46
|
351
|
|
|
|
|
418
|
for my $i (0 .. $#{$a}) { |
|
|
351
|
|
|
|
|
603
|
|
|
47
|
1053
|
|
|
|
|
1557
|
$result += $a->[$i] * $b->[$i]; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
351
|
|
|
|
|
640
|
return $result; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub multiply { |
|
54
|
39
|
|
|
39
|
0
|
53
|
my $self = shift(); |
|
55
|
39
|
|
|
|
|
80
|
my $other = shift->transpose(); |
|
56
|
39
|
|
|
|
|
55
|
my @result; |
|
57
|
|
|
|
|
|
|
|
|
58
|
39
|
50
|
|
|
|
51
|
unless ($#{$self->[0]} == $#{$other->[0]}) { |
|
|
39
|
|
|
|
|
68
|
|
|
|
39
|
|
|
|
|
81
|
|
|
59
|
0
|
|
|
|
|
0
|
carp 'Mismatched dimensions in matrix multiplication'; |
|
60
|
0
|
|
|
|
|
0
|
return; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
39
|
|
|
|
|
103
|
for my $row (@$self) { |
|
63
|
117
|
|
|
|
|
170
|
my $result_col = []; |
|
64
|
117
|
|
|
|
|
169
|
for my $col (@$other) { |
|
65
|
351
|
|
|
|
|
527
|
push @$result_col, vector_product($row, $col); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
117
|
|
|
|
|
171
|
push @result, $result_col; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
39
|
|
|
|
|
82
|
return PDF::API2::Matrix->new(@result); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |