line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PDF::API2::Matrix; |
2
|
|
|
|
|
|
|
|
3
|
38
|
|
|
38
|
|
275
|
use strict; |
|
38
|
|
|
|
|
81
|
|
|
38
|
|
|
|
|
1252
|
|
4
|
|
|
|
|
|
|
|
5
|
38
|
|
|
38
|
|
200
|
use Carp; |
|
38
|
|
|
|
|
81
|
|
|
38
|
|
|
|
|
18921
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '2.043'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
132
|
|
|
132
|
0
|
203
|
my $type = shift(); |
11
|
132
|
|
|
|
|
189
|
my $self = []; |
12
|
132
|
|
|
|
|
560
|
my $col_count = scalar(@{$_[0]}); |
|
132
|
|
|
|
|
194
|
|
13
|
132
|
|
|
|
|
216
|
foreach my $row (@_) { |
14
|
396
|
50
|
|
|
|
659
|
unless (scalar(@$row) == $col_count) { |
15
|
0
|
|
|
|
|
0
|
carp 'Inconsistent column count in matrix'; |
16
|
0
|
|
|
|
|
0
|
return; |
17
|
|
|
|
|
|
|
} |
18
|
396
|
|
|
|
|
833
|
push @$self, [@$row]; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
132
|
|
|
|
|
481
|
return bless($self, $type); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub transpose { |
25
|
39
|
|
|
39
|
0
|
54
|
my $self = shift(); |
26
|
39
|
|
|
|
|
70
|
my @result; |
27
|
|
|
|
|
|
|
my $m; |
28
|
|
|
|
|
|
|
|
29
|
39
|
|
|
|
|
52
|
for my $col (@{$self->[0]}) { |
|
39
|
|
|
|
|
88
|
|
30
|
117
|
|
|
|
|
186
|
push @result, []; |
31
|
|
|
|
|
|
|
} |
32
|
39
|
|
|
|
|
66
|
for my $row (@$self) { |
33
|
117
|
|
|
|
|
151
|
$m = 0; |
34
|
117
|
|
|
|
|
171
|
for my $col (@$row) { |
35
|
351
|
|
|
|
|
410
|
push @{$result[$m++]}, $col; |
|
351
|
|
|
|
|
569
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
39
|
|
|
|
|
99
|
return PDF::API2::Matrix->new(@result); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub vector_product { |
43
|
351
|
|
|
351
|
0
|
512
|
my ($a, $b) = @_; |
44
|
351
|
|
|
|
|
441
|
my $result = 0; |
45
|
|
|
|
|
|
|
|
46
|
351
|
|
|
|
|
426
|
for my $i (0 .. $#{$a}) { |
|
351
|
|
|
|
|
619
|
|
47
|
1053
|
|
|
|
|
1600
|
$result += $a->[$i] * $b->[$i]; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
351
|
|
|
|
|
670
|
return $result; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub multiply { |
54
|
39
|
|
|
39
|
0
|
72
|
my $self = shift(); |
55
|
39
|
|
|
|
|
80
|
my $other = shift->transpose(); |
56
|
39
|
|
|
|
|
56
|
my @result; |
57
|
|
|
|
|
|
|
|
58
|
39
|
50
|
|
|
|
54
|
unless ($#{$self->[0]} == $#{$other->[0]}) { |
|
39
|
|
|
|
|
81
|
|
|
39
|
|
|
|
|
81
|
|
59
|
0
|
|
|
|
|
0
|
carp 'Mismatched dimensions in matrix multiplication'; |
60
|
0
|
|
|
|
|
0
|
return; |
61
|
|
|
|
|
|
|
} |
62
|
39
|
|
|
|
|
86
|
for my $row (@$self) { |
63
|
117
|
|
|
|
|
149
|
my $result_col = []; |
64
|
117
|
|
|
|
|
174
|
for my $col (@$other) { |
65
|
351
|
|
|
|
|
550
|
push @$result_col, vector_product($row, $col); |
66
|
|
|
|
|
|
|
} |
67
|
117
|
|
|
|
|
205
|
push @result, $result_col; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
39
|
|
|
|
|
83
|
return PDF::API2::Matrix->new(@result); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |