line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#=======================================================================
|
2
|
|
|
|
|
|
|
# ____ ____ _____ _ ____ ___ ____
|
3
|
|
|
|
|
|
|
# | _ \| _ \| ___| _ _ / \ | _ \_ _| |___ \
|
4
|
|
|
|
|
|
|
# | |_) | | | | |_ (_) (_) / _ \ | |_) | | __) |
|
5
|
|
|
|
|
|
|
# | __/| |_| | _| _ _ / ___ \| __/| | / __/
|
6
|
|
|
|
|
|
|
# |_| |____/|_| (_) (_) /_/ \_\_| |___| |_____|
|
7
|
|
|
|
|
|
|
#
|
8
|
|
|
|
|
|
|
# Copyright 1999-2001 Alfred Reibenschuh .
|
9
|
|
|
|
|
|
|
#
|
10
|
|
|
|
|
|
|
# This library is free software; you can redistribute it
|
11
|
|
|
|
|
|
|
# and/or modify it under the same terms as Perl itself.
|
12
|
|
|
|
|
|
|
#
|
13
|
|
|
|
|
|
|
#=======================================================================
|
14
|
|
|
|
|
|
|
#
|
15
|
|
|
|
|
|
|
# PDF::API3::Compat::API2::Matrix
|
16
|
|
|
|
|
|
|
# Original Copyright 1995-96 Ulrich Pfeifer.
|
17
|
|
|
|
|
|
|
# modified by Alfred Reibenschuh for PDF::API3::Compat::API2
|
18
|
|
|
|
|
|
|
#
|
19
|
|
|
|
|
|
|
# $Id: Matrix.pm,v 2.0 2005/11/16 02:16:00 areibens Exp $
|
20
|
|
|
|
|
|
|
#
|
21
|
|
|
|
|
|
|
#=======================================================================
|
22
|
|
|
|
|
|
|
package PDF::API3::Compat::API2::Matrix;
|
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
1
|
|
8
|
use vars qw( $VERSION );
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
107
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
( $VERSION ) = sprintf '%i.%03i', split(/\./,('$Revision: 2.0 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2005/11/16 02:16:00 $
|
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
1
|
|
5
|
no warnings qw[ deprecated recursion uninitialized ];
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1084
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub new {
|
31
|
0
|
|
|
0
|
0
|
|
my $type = shift;
|
32
|
0
|
|
|
|
|
|
my $self = [];
|
33
|
0
|
|
|
|
|
|
my $len = scalar(@{$_[0]});
|
|
0
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
for (@_) {
|
35
|
0
|
0
|
|
|
|
|
return undef if scalar(@{$_}) != $len;
|
|
0
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
push(@{$self}, [@{$_}]);
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
}
|
38
|
0
|
|
|
|
|
|
bless $self, $type;
|
39
|
|
|
|
|
|
|
}
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub concat {
|
42
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
43
|
0
|
|
|
|
|
|
my $other = shift;
|
44
|
0
|
|
|
|
|
|
my $result = new PDF::API3::Compat::API2::Matrix (@{$self});
|
|
0
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
return undef if scalar(@{$self}) != scalar(@{$other});
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
for my $i (0 .. $#{$self}) {
|
|
0
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
push @{$result->[$i]}, @{$other->[$i]};
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
}
|
50
|
0
|
|
|
|
|
|
$result;
|
51
|
|
|
|
|
|
|
}
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub transpose {
|
54
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
55
|
0
|
|
|
|
|
|
my @result;
|
56
|
|
|
|
|
|
|
my $m;
|
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
for my $col (@{$self->[0]}) {
|
|
0
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
push @result, [];
|
60
|
|
|
|
|
|
|
}
|
61
|
0
|
|
|
|
|
|
for my $row (@{$self}) {
|
|
0
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
$m=0;
|
63
|
0
|
|
|
|
|
|
for my $col (@{$row}) {
|
|
0
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
push(@{$result[$m++]}, $col);
|
|
0
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
}
|
66
|
|
|
|
|
|
|
}
|
67
|
0
|
|
|
|
|
|
new PDF::API3::Compat::API2::Matrix (@result);
|
68
|
|
|
|
|
|
|
}
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub vekpro {
|
71
|
0
|
|
|
0
|
0
|
|
my($a, $b) = @_;
|
72
|
0
|
|
|
|
|
|
my $result=0;
|
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
for my $i (0 .. $#{$a}) {
|
|
0
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
$result += $a->[$i] * $b->[$i];
|
76
|
|
|
|
|
|
|
}
|
77
|
0
|
|
|
|
|
|
$result;
|
78
|
|
|
|
|
|
|
}
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub multiply {
|
81
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
82
|
0
|
|
|
|
|
|
my $other = shift->transpose;
|
83
|
0
|
|
|
|
|
|
my @result;
|
84
|
|
|
|
|
|
|
my $m;
|
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
return undef if $#{$self->[0]} != $#{$other->[0]};
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
for my $row (@{$self}) {
|
|
0
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my $rescol = [];
|
89
|
0
|
|
|
|
|
|
for my $col (@{$other}) {
|
|
0
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
push(@{$rescol}, vekpro($row,$col));
|
|
0
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
}
|
92
|
0
|
|
|
|
|
|
push(@result, $rescol);
|
93
|
|
|
|
|
|
|
}
|
94
|
0
|
|
|
|
|
|
new PDF::API3::Compat::API2::Matrix (@result);
|
95
|
|
|
|
|
|
|
}
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub solve {
|
99
|
0
|
|
|
0
|
0
|
|
my $m = new PDF::API3::Compat::API2::Matrix (@{$_[0]});
|
|
0
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
my $mr = $#{$m};
|
|
0
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $mc = $#{$m->[0]};
|
|
0
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $f;
|
103
|
|
|
|
|
|
|
my $try;
|
104
|
0
|
|
|
|
|
|
my $k;
|
105
|
0
|
|
|
|
|
|
my $i;
|
106
|
0
|
|
|
|
|
|
my $j;
|
107
|
0
|
|
|
|
|
|
my $eps = 0.000001;
|
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
return undef if $mc <= $mr;
|
110
|
0
|
|
|
|
|
|
ROW: for($i = 0; $i <= $mr; $i++) {
|
111
|
0
|
|
|
|
|
|
$try=$i;
|
112
|
|
|
|
|
|
|
# make diagonal element nonzero if possible
|
113
|
0
|
|
|
|
|
|
while (abs($m->[$i]->[$i]) < $eps) {
|
114
|
0
|
0
|
|
|
|
|
last ROW if $try++ > $mr;
|
115
|
0
|
|
|
|
|
|
my $row = splice(@{$m},$i,1);
|
|
0
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
push(@{$m}, $row);
|
|
0
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
}
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# normalize row
|
120
|
0
|
|
|
|
|
|
$f = $m->[$i]->[$i];
|
121
|
0
|
|
|
|
|
|
for($k = 0; $k <= $mc; $k++) {
|
122
|
0
|
|
|
|
|
|
$m->[$i]->[$k] /= $f;
|
123
|
|
|
|
|
|
|
}
|
124
|
|
|
|
|
|
|
# subtract multiple of designated row from other rows
|
125
|
0
|
|
|
|
|
|
for($j = 0; $j <= $mr; $j++) {
|
126
|
0
|
0
|
|
|
|
|
next if $i == $j;
|
127
|
0
|
|
|
|
|
|
$f = $m->[$j]->[$i];
|
128
|
0
|
|
|
|
|
|
for($k = 0; $k <= $mc; $k++) {
|
129
|
0
|
|
|
|
|
|
$m->[$j]->[$k] -= $m->[$i]->[$k] * $f;
|
130
|
|
|
|
|
|
|
}
|
131
|
|
|
|
|
|
|
}
|
132
|
|
|
|
|
|
|
}
|
133
|
|
|
|
|
|
|
# Answer is in augmented column
|
134
|
0
|
|
|
|
|
|
transpose new PDF::API3::Compat::API2::Matrix @{$m->transpose}[$mr+1 .. $mc];
|
|
0
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
}
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub print {
|
138
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
print STDERR "Matrix: \n";
|
141
|
0
|
0
|
|
|
|
|
print @_ if scalar(@_);
|
142
|
0
|
|
|
|
|
|
for my $row (@{$self}) {
|
|
0
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
for my $col (@{$row}) {
|
|
0
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
printf STDERR "%10.5f ", $col;
|
145
|
|
|
|
|
|
|
}
|
146
|
0
|
|
|
|
|
|
print STDERR "\n";
|
147
|
|
|
|
|
|
|
}
|
148
|
|
|
|
|
|
|
}
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
1;
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
__END__
|