| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#======================================================================= |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# PDF::Builder::Matrix |
|
4
|
|
|
|
|
|
|
# Original Copyright 1995-96 Ulrich Pfeifer. |
|
5
|
|
|
|
|
|
|
# modified by Alfred Reibenschuh for PDF::API2 |
|
6
|
|
|
|
|
|
|
# rewritten by Steve Simms and licensed under the same |
|
7
|
|
|
|
|
|
|
# terms as the rest of PDF::API2 |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
#======================================================================= |
|
10
|
|
|
|
|
|
|
package PDF::Builder::Matrix; |
|
11
|
|
|
|
|
|
|
|
|
12
|
34
|
|
|
34
|
|
256
|
use strict; |
|
|
34
|
|
|
|
|
102
|
|
|
|
34
|
|
|
|
|
1040
|
|
|
13
|
34
|
|
|
34
|
|
173
|
use warnings; |
|
|
34
|
|
|
|
|
73
|
|
|
|
34
|
|
|
|
|
804
|
|
|
14
|
34
|
|
|
34
|
|
172
|
use Carp; |
|
|
34
|
|
|
|
|
74
|
|
|
|
34
|
|
|
|
|
17956
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '3.023'; # VERSION |
|
17
|
|
|
|
|
|
|
our $LAST_UPDATE = '3.020'; # manually update whenever code is changed |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
PDF::Builder::Matrix - matrix operations library |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new { |
|
26
|
80
|
|
|
80
|
0
|
125
|
my $type = shift(); |
|
27
|
|
|
|
|
|
|
|
|
28
|
80
|
|
|
|
|
116
|
my $self = []; |
|
29
|
80
|
|
|
|
|
103
|
my $col_count = scalar(@{$_[0]}); |
|
|
80
|
|
|
|
|
114
|
|
|
30
|
80
|
|
|
|
|
138
|
foreach my $row (@_) { |
|
31
|
240
|
50
|
|
|
|
399
|
unless (scalar(@$row) == $col_count) { |
|
32
|
0
|
|
|
|
|
0
|
carp 'Inconsistent column count in matrix'; |
|
33
|
0
|
|
|
|
|
0
|
return; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
240
|
|
|
|
|
293
|
push(@{$self}, [@$row]); |
|
|
240
|
|
|
|
|
520
|
|
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
80
|
|
|
|
|
325
|
return bless($self, $type); |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# internal routine |
|
42
|
|
|
|
|
|
|
sub transpose { |
|
43
|
23
|
|
|
23
|
0
|
34
|
my $self = shift(); |
|
44
|
|
|
|
|
|
|
|
|
45
|
23
|
|
|
|
|
37
|
my @result; |
|
46
|
|
|
|
|
|
|
my $m; |
|
47
|
|
|
|
|
|
|
|
|
48
|
23
|
|
|
|
|
37
|
for my $col (@{$self->[0]}) { |
|
|
23
|
|
|
|
|
68
|
|
|
49
|
69
|
|
|
|
|
113
|
push @result, []; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
23
|
|
|
|
|
44
|
for my $row (@$self) { |
|
52
|
69
|
|
|
|
|
87
|
$m = 0; |
|
53
|
69
|
|
|
|
|
104
|
for my $col (@$row) { |
|
54
|
207
|
|
|
|
|
255
|
push @{$result[$m++]}, $col; |
|
|
207
|
|
|
|
|
340
|
|
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
23
|
|
|
|
|
52
|
return PDF::Builder::Matrix->new(@result); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# internal routine |
|
62
|
|
|
|
|
|
|
sub vector_product { |
|
63
|
207
|
|
|
207
|
0
|
293
|
my ($a, $b) = @_; |
|
64
|
207
|
|
|
|
|
261
|
my $result = 0; |
|
65
|
|
|
|
|
|
|
|
|
66
|
207
|
|
|
|
|
259
|
for my $i (0 .. $#{$a}) { |
|
|
207
|
|
|
|
|
347
|
|
|
67
|
621
|
|
|
|
|
1023
|
$result += $a->[$i] * $b->[$i]; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
207
|
|
|
|
|
408
|
return $result; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# used by Content.pm |
|
74
|
|
|
|
|
|
|
sub multiply { |
|
75
|
23
|
|
|
23
|
0
|
38
|
my $self = shift(); |
|
76
|
23
|
|
|
|
|
54
|
my $other = shift->transpose(); |
|
77
|
|
|
|
|
|
|
|
|
78
|
23
|
|
|
|
|
38
|
my @result; |
|
79
|
|
|
|
|
|
|
|
|
80
|
23
|
50
|
|
|
|
46
|
unless ($#{$self->[0]} == $#{$other->[0]}) { |
|
|
23
|
|
|
|
|
46
|
|
|
|
23
|
|
|
|
|
53
|
|
|
81
|
0
|
|
|
|
|
0
|
carp 'Mismatched dimensions in matrix multiplication'; |
|
82
|
0
|
|
|
|
|
0
|
return; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
23
|
|
|
|
|
41
|
for my $row (@$self) { |
|
85
|
69
|
|
|
|
|
115
|
my $result_col = []; |
|
86
|
69
|
|
|
|
|
110
|
for my $col (@$other) { |
|
87
|
207
|
|
|
|
|
331
|
push @$result_col, vector_product($row,$col); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
69
|
|
|
|
|
113
|
push @result, $result_col; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
23
|
|
|
|
|
61
|
return PDF::Builder::Matrix->new(@result); |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |