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
|
38
|
|
|
38
|
|
234
|
use strict; |
|
38
|
|
|
|
|
70
|
|
|
38
|
|
|
|
|
977
|
|
13
|
38
|
|
|
38
|
|
169
|
use warnings; |
|
38
|
|
|
|
|
70
|
|
|
38
|
|
|
|
|
725
|
|
14
|
38
|
|
|
38
|
|
159
|
use Carp; |
|
38
|
|
|
|
|
68
|
|
|
38
|
|
|
|
|
17144
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '3.024'; # 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
|
132
|
|
|
132
|
0
|
184
|
my $type = shift(); |
27
|
|
|
|
|
|
|
|
28
|
132
|
|
|
|
|
165
|
my $self = []; |
29
|
132
|
|
|
|
|
148
|
my $col_count = scalar(@{$_[0]}); |
|
132
|
|
|
|
|
162
|
|
30
|
132
|
|
|
|
|
180
|
foreach my $row (@_) { |
31
|
396
|
50
|
|
|
|
561
|
unless (scalar(@$row) == $col_count) { |
32
|
0
|
|
|
|
|
0
|
carp 'Inconsistent column count in matrix'; |
33
|
0
|
|
|
|
|
0
|
return; |
34
|
|
|
|
|
|
|
} |
35
|
396
|
|
|
|
|
415
|
push(@{$self}, [@$row]); |
|
396
|
|
|
|
|
698
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
132
|
|
|
|
|
444
|
return bless($self, $type); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# internal routine |
42
|
|
|
|
|
|
|
sub transpose { |
43
|
39
|
|
|
39
|
0
|
47
|
my $self = shift(); |
44
|
|
|
|
|
|
|
|
45
|
39
|
|
|
|
|
55
|
my @result; |
46
|
|
|
|
|
|
|
my $m; |
47
|
|
|
|
|
|
|
|
48
|
39
|
|
|
|
|
49
|
for my $col (@{$self->[0]}) { |
|
39
|
|
|
|
|
74
|
|
49
|
117
|
|
|
|
|
187
|
push @result, []; |
50
|
|
|
|
|
|
|
} |
51
|
39
|
|
|
|
|
59
|
for my $row (@$self) { |
52
|
117
|
|
|
|
|
129
|
$m = 0; |
53
|
117
|
|
|
|
|
140
|
for my $col (@$row) { |
54
|
351
|
|
|
|
|
336
|
push @{$result[$m++]}, $col; |
|
351
|
|
|
|
|
488
|
|
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
39
|
|
|
|
|
370
|
return PDF::Builder::Matrix->new(@result); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# internal routine |
62
|
|
|
|
|
|
|
sub vector_product { |
63
|
351
|
|
|
351
|
0
|
426
|
my ($a, $b) = @_; |
64
|
351
|
|
|
|
|
347
|
my $result = 0; |
65
|
|
|
|
|
|
|
|
66
|
351
|
|
|
|
|
358
|
for my $i (0 .. $#{$a}) { |
|
351
|
|
|
|
|
480
|
|
67
|
1053
|
|
|
|
|
1334
|
$result += $a->[$i] * $b->[$i]; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
351
|
|
|
|
|
881
|
return $result; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# used by Content.pm |
74
|
|
|
|
|
|
|
sub multiply { |
75
|
39
|
|
|
39
|
0
|
67
|
my $self = shift(); |
76
|
39
|
|
|
|
|
86
|
my $other = shift->transpose(); |
77
|
|
|
|
|
|
|
|
78
|
39
|
|
|
|
|
53
|
my @result; |
79
|
|
|
|
|
|
|
|
80
|
39
|
50
|
|
|
|
45
|
unless ($#{$self->[0]} == $#{$other->[0]}) { |
|
39
|
|
|
|
|
67
|
|
|
39
|
|
|
|
|
85
|
|
81
|
0
|
|
|
|
|
0
|
carp 'Mismatched dimensions in matrix multiplication'; |
82
|
0
|
|
|
|
|
0
|
return; |
83
|
|
|
|
|
|
|
} |
84
|
39
|
|
|
|
|
67
|
for my $row (@$self) { |
85
|
117
|
|
|
|
|
138
|
my $result_col = []; |
86
|
117
|
|
|
|
|
136
|
for my $col (@$other) { |
87
|
351
|
|
|
|
|
484
|
push @$result_col, vector_product($row,$col); |
88
|
|
|
|
|
|
|
} |
89
|
117
|
|
|
|
|
155
|
push @result, $result_col; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
39
|
|
|
|
|
133
|
return PDF::Builder::Matrix->new(@result); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |