lib/Math/MatrixDecomposition/Eigen.pm

filter: Statementstmt 81.7% 533 / 652 Branchbran 53.2% 115 / 216 Conditioncond 38.1% 55 / 144 MC/DCmcdc 17.1% 13 / 76 Subroutinesub 89.4% 17 / 19 Podpod 87.5% 7 / 8 totaltotal 66.3% 740 / 1115 CC 252 SCAR 61.4
CC
252
Cov
69%
sort
646.8
decompose
590.9
gebal
55.9
CRAP 462.7
↑ Summary blib/lib/Math/MatrixDecomposition.pm »
1 ## Math/MatrixDecomposition/Eigen.pm --- eigenvalues and eigenvectors.
2  
3 # Copyright (C) 2010 Ralph Schleicher. All rights reserved.
4  
5 # This program is free software; you can redistribute it and/or
6 # modify it under the same terms as Perl itself.
7  
8 # Commentary:
9 #
10 # Code derived from EiSPACK procedures and
11 # Jama's 'EigenvalueDecomposition' class.
12  
13 ## Code:
14  
15 package Math::MatrixDecomposition::Eigen;
16  
17 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use POSIX qw(:float_h);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Math::Complex qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 ▶use Math::BLAS;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use Math::MatrixDecomposition::Util qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 BEGIN
29 1 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 our $VERSION = '1.06';
31 1 our @EXPORT_OK = qw(eig);
32 }
33  
34 # Calculate eigenvalues and eigenvectors (convenience function).
35 sub eig
36 0 ▶{
Subroutine eig: not called CC=1 SCAR=6.9
Pod documented
37 0 __PACKAGE__->new (@_);
38 }
39  
40 # Standard constructor.
41 sub new
42 1 ▶{
Subroutine new: called CC=3 SCAR=11.8
Pod documented
43 1 my $class = shift;
44 1 my $self =
45 {
46 # Eigenvalues (a vector).
47 value => undef,
48  
49 # Eigenvectors (an array of vectors).
50 vector => undef,
51 };
52  
53 1 ▶ bless ($self, ref ($class) || $class);
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
54  
55 # Process arguments.
56 1 ▶ $self->decompose (@_)
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 0 0 1 1
57 if @_ > 0;
58  
59 # Return object.
60 1 $self;
61 }
62  
63 # Calculate eigenvalues and eigenvectors.
64 sub decompose
65 4 ▶{
Subroutine decompose: called CC=169 SCAR=63.8
Pod documented
66 4 my $self = shift;
67  
68 # Check arguments.
69 4 my $a = shift;
70  
71 4 ▶ my $m = @_ > 0 && looks_like_number ($_[0]) ? shift : sqrt (@$a);
Branch: 1 branch
BranchTrueFalseTotal
@_ > 0 && &looks_like_number($_[0]) ? : 0 4 4
Condition33%1/3
@_ > 0 and &looks_like_number($_[0])
!ll&&!rl&&r
400
MC/DC0%0/2
@_ > 0 and &looks_like_number($_[0])
@_ > 0 &looks_like_number($_[0])
Truth table33%1/3
A and B
A= @_ > 0B= &looks_like_number($_[0])
ABresult
0X0
100
111
72 4 ▶ my $n = @_ > 0 && looks_like_number ($_[0]) ? shift : $m ? @$a / $m : 0;
Branch: 2 branches
BranchTrueFalseTotal
@_ > 0 && &looks_like_number($_[0]) ? : 0 4 4
$m ? : 4 0 4
Condition33%1/3
@_ > 0 and &looks_like_number($_[0])
!ll&&!rl&&r
400
MC/DC0%0/2
@_ > 0 and &looks_like_number($_[0])
@_ > 0 &looks_like_number($_[0])
Truth table33%1/3
A and B
A= @_ > 0B= &looks_like_number($_[0])
ABresult
0X0
100
111
73  
74 4 ▶ croak ('Invalid argument')
Branch: 1 branch
BranchTrueFalseTotal
if @$a != $m * $n or mod($m, 1) != 0 or $m < 1 or mod($n, 1) != 0 or $n < 1 0 4 4
Condition33%4/12
@$a != $m * $n or mod($m, 1) != 0 or $m < 1 or mod($n, 1) != 0 or $n < 1
l!l&&r!l&&!r
004
@$a != $m * $n or mod($m, 1) != 0 or $m < 1 or mod($n, 1) != 0
l!l&&r!l&&!r
004
@$a != $m * $n or mod($m, 1) != 0 or $m < 1
l!l&&r!l&&!r
004
@$a != $m * $n or mod($m, 1) != 0
l!l&&r!l&&!r
004
MC/DC0%0/5
@$a != $m * $n or mod($m, 1) != 0 or $m < 1 or mod($n, 1) != 0 or $n < 1
@$a != $m * $n mod($m, 1) != 0 $m < 1 mod($n, 1) != 0 $n < 1
Truth table16%1/6
A or B or C or D or E
A= @$a != $m * $nB= mod($m, 1) != 0C= $m < 1D= mod($n, 1) != 0E= $n < 1
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
75 if (@$a != ($m * $n)
76 || mod ($m, 1) != 0 || $m < 1
77 || mod ($n, 1) != 0 || $n < 1);
78  
79 4 ▶ croak ('Matrix has to be square')
Branch: 1 branch
BranchTrueFalseTotal
if $m != $n 0 4 4
80 if $m != $n;
81  
82 # Get properties.
83 4 my %prop = @_;
84  
85 4 ▶ $prop{balance} //= 1;
Condition50%1/2
$prop{"balance"} //= 1
l!l
04
MC/DC0%0/1
$prop{"balance"} //= 1
$prop{"balance"}
Truth table50%1/2
A
A= $prop{"balance"}
Aresult
11
00
86 4 ▶ $prop{normalize} //= 1;
Condition50%1/2
$prop{"normalize"} //= 1
l!l
04
MC/DC0%0/1
$prop{"normalize"} //= 1
$prop{"normalize"}
Truth table50%1/2
A
A= $prop{"normalize"}
Aresult
11
00
87 4 ▶ $prop{positive} //= 1;
Condition50%1/2
$prop{"positive"} //= 1
l!l
04
MC/DC0%0/1
$prop{"positive"} //= 1
$prop{"positive"}
Truth table50%1/2
A
A= $prop{"positive"}
Aresult
11
00
88  
89 # Index of last row/column.
90 4 my $end = $n - 1;
91  
92 # Eigenvalues (a vector).
93 4 ▶ $$self{value} //= [];
Condition100%2/2
$self->{"value"} //= []
l!l
31
MC/DC100%1/1
$self->{"value"} //= []
$self->{"value"}
Truth table100%2/2
A
A= $self->{"value"}
Aresult
11
00
94  
95 # Vector $d contains the real part of the eigenvalues and vector $e
96 # contains the imaginary part of the eigenvalues.
97 4 my $d = $$self{value};
98 4 my $e = [];
99  
100 4 ▶ splice (@$d, $n)
Branch: 1 branch
BranchTrueFalseTotal
if @$d > $n 1 3 4
101 if @$d > $n;
102  
103 # Eigenvectors (an array of column vectors).
104 4 ▶ $$self{vector} //= [];
Condition100%2/2
$self->{"vector"} //= []
l!l
31
MC/DC100%1/1
$self->{"vector"} //= []
$self->{"vector"}
Truth table100%2/2
A
A= $self->{"vector"}
Aresult
11
00
105  
106 # Matrix $Z contains the eigenvectors, please note
107 # that $$Z[$j][$i] denotes matrix element Z(i,j).
108 4 my $Z = $$self{vector};
109  
110 4 ▶ splice (@$Z, $n)
Branch: 1 branch
BranchTrueFalseTotal
if @$Z > $n 1 3 4
111 if @$Z > $n;
112  
113 4 for my $v (@$Z)
114 {
115 7 ▶ splice (@$v, $n)
Branch: 1 branch
BranchTrueFalseTotal
if @$v > $n 2 5 7
116 if @$v > $n;
117 }
118  
119 # True if matrix is symmetric.
120 4 my $sym = 1;
121  
122 SYM:
123  
124 4 for my $i (0 .. $end)
125 {
126 6 for my $j ($i + 1 .. $end)
127 {
128 6 ▶ if ($$a[$i * $n + $j] != $$a[$j * $n + $i])
Branch: 1 branch
BranchTrueFalseTotal
if ($$a[$i * $n + $j] != $$a[$j * $n + $i]) 3 3 6
129 {
130 3 $sym = 0;
131 3 last SYM;
132 }
133 }
134 }
135  
136 4 ▶ if ($sym)
Branch: 1 branch
BranchTrueFalseTotal
if ($sym) { } 1 3 4
137 {
138 # Copy matrix elements.
139 1 for my $j (0 .. $end)
140 {
141 3 ▶ $$Z[$j] //= [];
Condition50%1/2
$Z->[$j] //= []
l!l
03
MC/DC0%0/1
$Z->[$j] //= []
$Z->[$j]
Truth table50%1/2
A
A= $Z->[$j]
Aresult
11
00
142  
143 3 for my $i (0 .. $end)
144 {
145 9 $$Z[$j][$i] = $$a[$i * $n + $j];
146 }
147 }
148  
149 # Reduce a real symmetric matrix to a symmetric tridiagonal matrix
150 # using and accumulating orthogonal similarity transformations.
151 #
152 # See EiSPACK procedure 'tred2'.
153 1 if (1)
154 {
155 1 my ($i, $j, $k, $l,
156 $f, $g, $h, $hh, $scale);
157  
158 1 for $i (0 .. $end)
159 {
160 3 $$d[$i] = $$Z[$i][$end];
161 }
162  
163 1 for $i (reverse (1 .. $end))
164 {
165 2 $l = $i - 1;
166 2 $h = 0;
167  
168 # Scale row.
169 2 $scale = 0;
170  
171 2 for $k (0 .. $l)
172 {
173 3 $scale += abs ($$d[$k]);
174 }
175  
176 2 ▶ if ($scale == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($scale == 0) { } 0 2 2
177 {
178 0 $$e[$i] = $$d[$l];
179  
180 0 for $j (0 .. $l)
181 {
182 0 $$d[$j] = $$Z[$j][$l];
183  
184 0 $$Z[$j][$i] = 0;
185 0 $$Z[$i][$j] = 0;
186 }
187 }
188 else
189 {
190 2 for $k (0 .. $l)
191 {
192 3 $$d[$k] /= $scale;
193 3 $h += $$d[$k] ** 2;
194 }
195  
196 2 $f = $$d[$l];
197 2 $g = - sign (sqrt ($h), $f);
198 2 $h -= $f * $g;
199  
200 2 $$d[$l] = $f - $g;
201 2 $$e[$i] = $scale * $g;
202  
203 # Form a*u.
204 2 for $j (0 .. $l)
205 {
206 3 $$e[$j] = 0;
207 }
208  
209 2 for $j (0 .. $l)
210 {
211 3 $f = $$d[$j];
212 3 $$Z[$i][$j] = $f;
213 3 $g = $$e[$j] + $$Z[$j][$j] * $f;
214  
215 3 for $k ($j + 1 .. $l)
216 {
217 1 $g += $$Z[$j][$k] * $$d[$k];
218 1 $$e[$k] += $$Z[$j][$k] * $f;
219 }
220  
221 3 $$e[$j] = $g;
222 }
223  
224 # Form p.
225 2 $f = 0;
226  
227 2 for $j (0 .. $l)
228 {
229 3 $$e[$j] /= $h;
230 3 $f += $$e[$j] * $$d[$j];
231 }
232  
233 # Form q.
234 2 $hh = $f / ($h + $h);
235  
236 2 for $j (0 .. $l)
237 {
238 3 $$e[$j] -= $hh * $$d[$j];
239 }
240  
241 # Form reduced a.
242 2 for $j (0 .. $l)
243 {
244 3 $f = $$d[$j];
245 3 $g = $$e[$j];
246  
247 3 for $k ($j .. $l)
248 {
249 4 $$Z[$j][$k] -= ($f * $$e[$k] + $g * $$d[$k]);
250 }
251  
252 3 $$d[$j] = $$Z[$j][$l];
253 3 $$Z[$j][$i] = 0;
254 }
255 }
256  
257 2 $$d[$i] = $h;
258 }
259  
260 # Accumulation of transformation matrices.
261 1 for $i (1 .. $end)
262 {
263 2 $l = $i - 1;
264  
265 2 $$Z[$l][$end] = $$Z[$l][$l];
266 2 $$Z[$l][$l] = 1;
267  
268 2 $h = $$d[$i];
269 2 ▶ if ($h != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($h != 0) 2 0 2
270 {
271 2 for $k (0 .. $l)
272 {
273 3 $$d[$k] = $$Z[$i][$k] / $h;
274 }
275  
276 2 for $j (0 .. $l)
277 {
278 3 $g = 0;
279  
280 3 for $k (0 .. $l)
281 {
282 5 $g += $$Z[$i][$k] * $$Z[$j][$k];
283 }
284  
285 3 for $k (0 .. $l)
286 {
287 5 $$Z[$j][$k] -= $g * $$d[$k];
288 }
289 }
290 }
291  
292 2 for $k (0 .. $l)
293 {
294 3 $$Z[$i][$k] = 0;
295 }
296 }
297  
298 1 for $j (0 .. $end)
299 {
300 3 $$d[$j] = $$Z[$j][$end];
301 3 $$Z[$j][$end] = 0;
302 }
303  
304 1 $$Z[$end][$end] = 1;
305 1 $$e[0] = 0;
306 }
307  
308 # Find the eigenvalues and eigenvectors of a symmetric tridiagonal
309 # matrix by the QL method.
310 #
311 # See EiSPACK procedure 'tql2'.
312 1 if (1)
313 {
314 1 my ($i, $j, $k, $l, $m,
315 $c, $c2, $c3, $dl1, $el1, $f, $g, $h, $p, $r, $s, $s2, $t, $t2);
316  
317 1 for $i (1 .. $end)
318 {
319 2 $$e[$i - 1] = $$e[$i];
320 }
321  
322 1 $$e[$end] = 0;
323  
324 1 $f = 0;
325 1 $t = 0;
326  
327 1 for $l (0 .. $end)
328 {
329 3 $t2 = abs ($$d[$l]) + abs ($$e[$l]);
330 3 ▶ $t = $t2 if $t2 > $t;
Branch: 1 branch
BranchTrueFalseTotal
if $t2 > $t 1 2 3
331  
332 3 ▶ for ($m = $l; $m < $n; ++$m)
Branch: 1 branch
BranchTrueFalseTotal
if ($m < $n) 6 0 6
333 {
334 6 ▶ last if abs ($$e[$m]) <= eps * $t;
Branch: 1 branch
BranchTrueFalseTotal
if abs $e->[$m] <= &eps() * $t 3 3 6
335 }
336  
337 3 ▶ if ($m > $l)
Branch: 1 branch
BranchTrueFalseTotal
if ($m > $l) 2 1 3
338 {
339 2 while (1)
340 {
341 5 $g = $$d[$l];
342 5 $p = ($$d[$l + 1] - $g) / (2 * $$e[$l]);
343 5 $r = sign (hypot ($p, 1), $p);
344  
345 5 $$d[$l] = $$e[$l] / ($p + $r);
346 5 $$d[$l + 1] = $$e[$l] * ($p + $r);
347 5 $dl1 = $$d[$l + 1];
348 5 $h = $g - $$d[$l];
349  
350 5 for $i ($l + 2 .. $end)
351 {
352 4 $$d[$i] -= $h;
353 }
354  
355 5 $f += $h;
356  
357 5 $p = $$d[$m];
358 5 $c = 1;
359 5 $c2 = $c;
360 5 $el1 = $$e[$l + 1];
361 5 $s = 0;
362  
363 5 for $i (reverse ($l .. $m - 1))
364 {
365 9 $c3 = $c2;
366 9 $c2 = $c;
367 9 $s2 = $s;
368 9 $g = $c * $$e[$i];
369 9 $h = $c * $p;
370 9 $r = hypot ($p, $$e[$i]);
371 9 $$e[$i + 1] = $s * $r;
372 9 $s = $$e[$i] / $r;
373 9 $c = $p / $r;
374 9 $p = $c * $$d[$i] - $s * $g;
375 9 $$d[$i + 1] = $h + $s * ($c * $g + $s * $$d[$i]);
376  
377 9 for $k (0 .. $end)
378 {
379 27 $h = $$Z[$i + 1][$k];
380 27 $$Z[$i + 1][$k] = $s * $$Z[$i][$k] + $c * $h;
381 27 $$Z[$i][$k] = $c * $$Z[$i][$k] - $s * $h;
382 }
383 }
384  
385 5 $p = 0 - $s * $s2 * $c3 * $el1 * $$e[$l] / $dl1;
386  
387 5 $$e[$l] = $s * $p;
388 5 $$d[$l] = $c * $p;
389  
390 # Check convergence.
391 5 ▶ last if abs ($$e[$l]) <= eps * $t;
Branch: 1 branch
BranchTrueFalseTotal
if abs $e->[$l] <= &eps() * $t 2 3 5
392 }
393 }
394  
395 3 $$d[$l] = $$d[$l] + $f;
396 3 $$e[$l] = 0;
397 }
398 }
399 }
400 else
401 {
402 # Hessenberg matrix.
403 3 my @H = @$a;
404 3 my $N = $n;
405  
406 # Row and column indices of the beginning and end
407 # of the principal sub-matrix.
408 3 my $lo = 0;
409 3 my $hi = $end;
410  
411 # Permutation vector.
412 3 my @perm = ();
413  
414 # Scaling vector.
415 3 my @scale = ();
416  
417 # Balance a real matrix and isolate eigenvalues whenever possible.
418 3 ▶ if ($prop{balance})
Branch: 1 branch
BranchTrueFalseTotal
if ($prop{"balance"}) 3 0 3
419 {
420 3 my ($p, $s) = gebal ($N, \@H, low => \$lo, high => \$hi);
421  
422 3 @perm = @$p;
423 3 @scale = @$s;
424 }
425  
426 # Reduce matrix to upper Hessenberg form by orthogonal similarity
427 # transformations.
428 #
429 # See EiSPACK procedure 'orthes'.
430 3 my @ort = ();
431  
432 3 if (1)
433 {
434 3 my ($i, $j, $k, $m,
435 $f, $g, $h, $scale);
436  
437 3 for $m ($lo + 1 .. $hi - 1)
438 {
439 2 $scale = 0;
440  
441 2 for $i ($m .. $hi)
442 {
443 4 $scale += abs ($H[$i * $N + ($m - 1)]);
444 }
445  
446 2 ▶ next if $scale == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $scale == 0 0 2 2
447  
448 2 $h = 0;
449  
450 2 for $i (reverse ($m .. $hi))
451 {
452 4 $ort[$i] = $H[$i * $N + ($m - 1)] / $scale;
453 4 $h += $ort[$i] ** 2;
454 }
455  
456 2 $g = - sign (sqrt ($h), $ort[$m]);
457 2 $h -= $ort[$m] * $g;
458 2 $ort[$m] -= $g;
459  
460 2 for $j ($m .. $end)
461 {
462 4 $f = 0;
463  
464 4 for $i (reverse ($m .. $hi))
465 {
466 8 $f += $ort[$i] * $H[$i * $N + $j];
467 }
468  
469 4 $f /= $h;
470  
471 4 for $i ($m .. $hi)
472 {
473 8 $H[$i * $N + $j] -= $f * $ort[$i];
474 }
475 }
476  
477 2 for $i (0 .. $hi)
478 {
479 6 $f = 0;
480  
481 6 for $j (reverse ($m .. $hi))
482 {
483 12 $f += $ort[$j] * $H[$i * $N + $j];
484 }
485  
486 6 $f /= $h;
487  
488 6 for $j ($m .. $hi)
489 {
490 12 $H[$i * $N + $j] -= $f * $ort[$j];
491 }
492 }
493  
494 2 $ort[$m] *= $scale;
495 2 $H[$m * $N + ($m - 1)] = $scale * $g;
496 }
497 }
498  
499 # Accumulate the orthogonal similarity transformations.
500 #
501 # See EiSPACK procedure 'ortran'.
502 3 if (1)
503 {
504 3 my ($i, $j, $k, $m,
505 $g);
506  
507 3 for $j (0 .. $end)
508 {
509 8 ▶ $$Z[$j] //= [];
Condition100%2/2
$Z->[$j] //= []
l!l
71
MC/DC100%1/1
$Z->[$j] //= []
$Z->[$j]
Truth table100%2/2
A
A= $Z->[$j]
Aresult
11
00
510  
511 8 for $i (0 .. $end)
512 {
513 22 ▶ $$Z[$j][$i] = ($i == $j ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$i == $j ? : 8 14 22
514 }
515 }
516  
517 3 for $m (reverse ($lo + 1 .. $hi - 1))
518 {
519 2 ▶ next if $H[$m * $N + ($m - 1)] == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $H[$m * $N + ($m - 1)] == 0 0 2 2
520  
521 2 for $i ($m + 1 .. $hi)
522 {
523 2 $ort[$i] = $H[$i * $N + ($m - 1)];
524 }
525  
526 2 for $j ($m .. $hi)
527 {
528 4 $g = 0;
529  
530 4 for $i ($m .. $hi)
531 {
532 8 $g += $ort[$i] * $$Z[$j][$i];
533 }
534  
535 4 $g = ($g / $ort[$m]) / $H[$m * $N + ($m - 1)];
536  
537 4 for $i ($m .. $hi)
538 {
539 8 $$Z[$j][$i] += $g * $ort[$i];
540 }
541 }
542 }
543 }
544  
545 # Find the eigenvalues and eigenvectors of a real upper Hessenberg
546 # matrix by the QR method.
547 #
548 # See EiSPACK procedure 'hqr2'.
549 3 if (1)
550 {
551 3 my ($i, $j, $k, $l, $m,
552 $h, $g, $f, $p, $q, $r, $s, $t, $w, $x, $y, $z,
553 $norm, $iter, $not_last, $vr, $vi, $ra, $sa);
554  
555 3 $t = 0;
556  
557 # Store isolated roots.
558 3 for $i (0 .. $end)
559 {
560 8 ▶ if ($i < $lo || $i > $hi)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $lo or $i > $hi) 2 6 8
Condition100%3/3
$i < $lo or $i > $hi
l!l&&r!l&&!r
116
MC/DC100%2/2
$i < $lo or $i > $hi
$i < $lo $i > $hi
Truth table100%3/3
A or B
A= $i < $loB= $i > $hi
ABresult
1X1
011
000
561 {
562 2 $$d[$i] = $H[$i * $N + $i];
563 2 $$e[$i] = 0;
564 }
565 }
566  
567 # Compute matrix norm.
568 3 $norm = 0;
569  
570 3 for $i (0 .. $end)
571 {
572 8 for $j ($i .. $end)
573 {
574 15 $norm += abs ($H[$i * $N + $j]);
575 }
576 }
577  
578 # Search for next eigenvalue.
579 3 $iter = 0;
580  
581 3 ▶ for ($n = $end; $n >= $lo; )
Branch: 1 branch
BranchTrueFalseTotal
if ($n >= $lo) 19 3 22
582 {
583 # Look for single small sub-diagonal element.
584 19 ▶ for ($l = $n; $l > $lo; --$l)
Branch: 1 branch
BranchTrueFalseTotal
if ($l > $lo) 30 16 46
585 {
586 30 $s = abs ($H[($l - 1) * $N + ($l - 1)]) + abs ($H[$l * $N + $l]);
587 30 ▶ $s = $norm
Branch: 1 branch
BranchTrueFalseTotal
if $s == 0 0 30 30
588 if $s == 0;
589  
590 30 ▶ last if abs ($H[$l * $N + ($l - 1)]) < eps * $s;
Branch: 1 branch
BranchTrueFalseTotal
if abs $H[$l * $N + ($l - 1)] < &eps() * $s 3 27 30
591 }
592  
593 19 $x = $H[$n * $N + $n];
594  
595 19 ▶ if ($l == $n)
Branch: 2 branches
BranchTrueFalseTotal
if ($l == $n) { } 5 14 19
elsif ($l == $n - 1) { } 1 13 14
596 {
597 # One root found,
598 5 $H[$n * $N + $n] = $x + $t;
599  
600 5 $$d[$n] = $H[$n * $N + $n];
601 5 $$e[$n] = 0;
602  
603 5 $n -= 1;
604 5 $iter = 0;
605 }
606 elsif ($l == $n - 1)
607 {
608 # Two roots found.
609 1 $y = $H[($n - 1) * $N + ($n - 1)];
610 1 $w = $H[$n * $N + ($n - 1)] * $H[($n - 1) * $N + $n];
611  
612 1 $p = ($y - $x) / 2;
613 1 $q = $p * $p + $w;
614 1 $z = sqrt (abs ($q));
615  
616 1 $H[$n * $N + $n] = $x + $t;
617 1 $H[($n - 1) * $N + ($n - 1)] = $y + $t;
618 1 $x = $H[$n * $N + $n];
619  
620 1 ▶ if ($q >= 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($q >= 0) { } 1 0 1
621 {
622 # Real pair.
623 1 $z = $p + sign ($z, $p);
624  
625 1 $$d[$n - 1] = $x + $z;
626 1 $$d[$n] = $$d[$n - 1];
627 1 ▶ $$d[$n] = $x - $w / $z
Branch: 1 branch
BranchTrueFalseTotal
if $z != 0 1 0 1
628 if $z != 0;
629  
630 1 $$e[$n - 1] = 0;
631 1 $$e[$n] = 0;
632  
633 1 $x = $H[$n * $N + ($n - 1)];
634 1 $s = abs ($x) + abs ($z);
635 1 $p = $x / $s;
636 1 $q = $z / $s;
637 1 $r = sqrt ($p * $p + $q * $q);
638 1 $p = $p / $r;
639 1 $q = $q / $r;
640  
641 # Row modification.
642 1 for $j ($n - 1 .. $end)
643 {
644 2 $z = $H[($n - 1) * $N + $j];
645 2 $H[($n - 1) * $N + $j] = $q * $z + $p * $H[$n * $N + $j];
646 2 $H[$n * $N + $j] = $q * $H[$n * $N + $j] - $p * $z;
647 }
648  
649 # Column modification.
650 1 for $i (0 .. $n)
651 {
652 3 $z = $H[$i * $N + ($n - 1)];
653 3 $H[$i * $N + ($n - 1)] = $q * $z + $p * $H[$i * $N + $n];
654 3 $H[$i * $N + $n] = $q * $H[$i * $N + $n] - $p * $z;
655 }
656  
657 # Accumulate transformations.
658 1 for $i ($lo .. $hi)
659 {
660 3 $z = $$Z[$n - 1][$i];
661 3 $$Z[$n - 1][$i] = $q * $z + $p * $$Z[$n][$i];
662 3 $$Z[$n][$i] = $q * $$Z[$n][$i] - $p * $z;
663 }
664 }
665 else
666 {
667 # Complex pair.
668 0 $$d[$n - 1] = $x + $p;
669 0 $$d[$n] = $x + $p;
670 0 $$e[$n - 1] = $z;
671 0 $$e[$n] = 0 - $z;
672 }
673  
674 1 $n -= 2;
675 1 $iter = 0;
676 }
677 else
678 {
679 # Form shift.
680 13 $y = $H[($n - 1) * $N + ($n - 1)];
681 13 $w = $H[$n * $N + ($n - 1)] * $H[($n - 1) * $N + $n];
682  
683 # Wilkinson's original ad hoc shift.
684 13 ▶ if ($iter == 10 || $iter == 20)
Branch: 1 branch
BranchTrueFalseTotal
if ($iter == 10 or $iter == 20) 0 13 13
Condition33%1/3
$iter == 10 or $iter == 20
l!l&&r!l&&!r
0013
MC/DC0%0/2
$iter == 10 or $iter == 20
$iter == 10 $iter == 20
Truth table33%1/3
A or B
A= $iter == 10B= $iter == 20
ABresult
1X1
011
000
685 {
686 0 $t += $x;
687  
688 0 for $i ($lo .. $n)
689 {
690 0 $H[$i * $N + $i] -= $x;
691 }
692  
693 0 $s = abs ($H[$n * $N + ($n - 1)]) + abs ($H[($n - 1) * $N + ($n - 2)]);
694 0 $x = 0.75 * $s;
695 0 $y = $x;
696 0 $w = -0.4375 * $s * $s;
697 }
698  
699 # Matlab's new ad hoc shift.
700 13 ▶ if ($iter == 30)
Branch: 1 branch
BranchTrueFalseTotal
if ($iter == 30) 0 13 13
701 {
702 0 $s = ($y - $x) / 2;
703 0 $s = $s * $s + $w;
704 0 ▶ if ($s > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($s > 0) 0 0 0
705 {
706 0 $s = sqrt ($s);
707 0 ▶ $s = - $s if $y < $x;
Branch: 1 branch
BranchTrueFalseTotal
if $y < $x 0 0 0
708 0 $s = $x - $w / (($y - $x) / 2 + $s);
709  
710 0 for $i ($lo .. $n)
711 {
712 0 $H[$i * $N + $i] -= $s;
713 }
714  
715 0 $t += $s;
716 0 $x = 0.964;
717 0 $w = $y = $x;
718 }
719 }
720  
721 13 ++$iter;
722  
723 # Look for two consecutive small sub-diagonal elements.
724 13 ▶ for ($m = $n - 2; $m >= $l; --$m)
Branch: 1 branch
BranchTrueFalseTotal
if ($m >= $l) 13 0 13
725 {
726 13 $z = $H[$m * $N + $m];
727 13 $r = $x - $z;
728 13 $s = $y - $z;
729 13 $p = ($r * $s - $w) / $H[($m + 1) * $N + $m] + $H[$m * $N + ($m + 1)];
730 13 $q = $H[($m + 1) * $N + ($m + 1)] - $z - $r - $s;
731 13 $r = $H[($m + 2) * $N + ($m + 1)];
732 13 $s = abs ($p) + abs ($q) + abs ($r);
733 13 $p = $p / $s;
734 13 $q = $q / $s;
735 13 $r = $r / $s;
736  
737 13 ▶ last if $m == $l;
Branch: 1 branch
BranchTrueFalseTotal
if $m == $l 13 0 13
738 0 ▶ last if abs ($H[$m * $N + ($m - 1)]) * (abs ($q) + abs ($r)) < eps * (abs ($p) * (abs ($H[($m - 1) * $N + ($m - 1)]) + abs ($z) + abs ($H[($m + 1) * $N + ($m + 1)])));
Branch: 1 branch
BranchTrueFalseTotal
if abs($H[$m * $N + ($m - 1)]) * (abs($q) + abs($r)) < &eps() * (abs($p) * (abs($H[($m - 1) * $N + ($m - 1)]) + abs($z) + abs($H[($m + 1) * $N + ($m + 1)]))) 0 0 0
739 }
740  
741 13 for $i ($m + 2 .. $n)
742 {
743 13 $H[$i * $N + ($i - 2)] = 0;
744 13 ▶ $H[$i * $N + ($i - 3)] = 0
Branch: 1 branch
BranchTrueFalseTotal
if $i > $m + 2 0 13 13
745 if $i > $m + 2;
746 }
747  
748 # Double QR step.
749 13 for $k ($m .. $n - 1)
750 {
751 26 $not_last = ($k != $n - 1);
752  
753 26 ▶ if ($k != $m)
Branch: 1 branch
BranchTrueFalseTotal
if ($k != $m) 13 13 26
754 {
755 13 $p = $H[$k * $N + ($k - 1)];
756 13 $q = $H[($k + 1) * $N + ($k - 1)];
757 13 ▶ $r = $not_last ? $H[($k + 2) * $N + ($k - 1)] : 0;
Branch: 1 branch
BranchTrueFalseTotal
$not_last ? : 0 13 13
758 13 $x = abs ($p) + abs ($q) + abs ($r);
759  
760 13 ▶ next if $x == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $x == 0 0 13 13
761  
762 13 $p = $p / $x;
763 13 $q = $q / $x;
764 13 $r = $r / $x;
765 }
766  
767 26 $s = sign (sqrt ($p * $p + $q * $q + $r * $r), $p);
768 26 ▶ if ($s != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($s != 0) 26 0 26
769 {
770 26 ▶ if ($k != $m)
Branch: 2 branches
BranchTrueFalseTotal
if ($k != $m) { } 13 13 26
elsif ($l != $m) { } 0 13 13
771 {
772 13 $H[$k * $N + ($k - 1)] = 0 - $s * $x;
773 }
774 elsif ($l != $m)
775 {
776 0 $H[$k * $N + ($k - 1)] = - $H[$k * $N + ($k - 1)];
777 }
778  
779 26 $p = $p + $s;
780 26 $x = $p / $s;
781 26 $y = $q / $s;
782 26 $z = $r / $s;
783 26 $q = $q / $p;
784 26 $r = $r / $p;
785  
786 26 ▶ if ($not_last)
Branch: 1 branch
BranchTrueFalseTotal
if ($not_last) { } 13 13 26
787 {
788 # Row modification.
789 13 for $j ($k .. $end)
790 {
791 39 $p = $H[$k * $N + $j] + $q * $H[($k + 1) * $N + $j] + $r * $H[($k + 2) * $N + $j];
792  
793 39 $H[$k * $N + $j] -= $p * $x;
794 39 $H[($k + 1) * $N + $j] -= $p * $y;
795 39 $H[($k + 2) * $N + $j] -= $p * $z;
796 }
797  
798 # Column modification.
799 13 for $i (0 .. min ($n, $k + 3))
800 {
801 39 $p = $x * $H[$i * $N + $k] + $y * $H[$i * $N + ($k + 1)] + $z * $H[$i * $N + ($k + 2)];
802  
803 39 $H[$i * $N + $k] -= $p;
804 39 $H[$i * $N + ($k + 1)] -= $p * $q;
805 39 $H[$i * $N + ($k + 2)] -= $p * $r;
806 }
807  
808 # Accumulate transformations.
809 13 for $i ($lo .. $hi)
810 {
811 39 $p = $x * $$Z[$k][$i] + $y * $$Z[$k + 1][$i] + $z * $$Z[$k + 2][$i];
812  
813 39 $$Z[$k][$i] -= $p;
814 39 $$Z[$k + 1][$i] -= $p * $q;
815 39 $$Z[$k + 2][$i] -= $p * $r;
816 }
817 }
818 else
819 {
820 # Row modification.
821 13 for $j ($k .. $end)
822 {
823 26 $p = $H[$k * $N + $j] + $q * $H[($k + 1) * $N + $j];
824  
825 26 $H[$k * $N + $j] -= $p * $x;
826 26 $H[($k + 1) * $N + $j] -= $p * $y;
827 }
828  
829 # Column modification.
830 13 for $i (0 .. min ($n, $k + 3))
831 {
832 39 $p = $x * $H[$i * $N + $k] + $y * $H[$i * $N + ($k + 1)];
833  
834 39 $H[$i * $N + $k] -= $p;
835 39 $H[$i * $N + ($k + 1)] -= $p * $q;
836 }
837  
838 # Accumulate transformations.
839 13 for $i (0 .. $end)
840 {
841 39 $p = $x * $$Z[$k][$i] + $y * $$Z[$k + 1][$i];
842  
843 39 $$Z[$k][$i] -= $p;
844 39 $$Z[$k + 1][$i] -= $p * $q;
845 }
846 }
847 }
848 }
849 }
850 }
851  
852 # Backsubstitute to find vectors of upper triangular form.
853 3 ▶ return if $norm == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $norm == 0 0 3 3
854  
855 3 for $n (reverse (0 .. $end))
856 {
857 8 $p = $$d[$n];
858 8 $q = $$e[$n];
859  
860 8 ▶ if ($q == 0)
Branch: 2 branches
BranchTrueFalseTotal
if ($q == 0) { } 8 0 8
elsif ($q < 0) { } 0 0 0
861 {
862 # Real vector.
863 8 $m = $n;
864 8 $H[$n * $N + $n] = 1;
865  
866 8 for $i (reverse (0 .. $n - 1))
867 {
868 7 $w = $H[$i * $N + $i] - $p;
869 7 $r = 0;
870  
871 7 for $j ($m .. $n)
872 {
873 9 $r += $H[$i * $N + $j] * $H[$j * $N + $n];
874 }
875  
876 7 ▶ if ($$e[$i] < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($e->[$i] < 0) { } 0 7 7
877 {
878 0 $z = $w;
879 0 $s = $r;
880 }
881 else
882 {
883 7 $m = $i;
884  
885 7 ▶ if ($$e[$i] == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($e->[$i] == 0) { } 7 0 7
886 {
887 7 ▶ $H[$i * $N + $n] = ($w != 0 ?
Branch: 1 branch
BranchTrueFalseTotal
$w != 0 ? : 7 0 7
888 0 - $r / $w :
889 0 - $r / (eps * $norm));
890 }
891 else
892 {
893 # Solve real equations.
894 0 $x = $H[$i * $N + ($i + 1)];
895 0 $y = $H[($i + 1) * $N + $i];
896 0 $q = ($$d[$i] - $p) ** 2 + $$e[$i] ** 2;
897 0 $t = ($x * $s - $z * $r) / $q;
898  
899 0 $H[$i * $N + $n] = $t;
900 0 ▶ $H[($i + 1) * $N + $n] = (abs ($x) > abs ($z) ?
Branch: 1 branch
BranchTrueFalseTotal
abs $x > abs $z ? : 0 0 0
901 (0 - $r - $w * $t) / $x :
902 (0 - $s - $y * $t) / $z);
903 }
904  
905 # Overflow control.
906 7 $t = abs ($H[$i * $N + $n]);
907 7 ▶ if ((eps * $t) * $t > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (&eps() * $t * $t > 1) 0 7 7
908 {
909 0 for $j ($i .. $n)
910 {
911 0 $H[$j * $N + $n] /= $t;
912 }
913 }
914 }
915 }
916 }
917 elsif ($q < 0)
918 {
919 # Complex vector.
920 0 $m = $n - 1;
921  
922 # Last vector component chosen imaginary so that
923 # eigenvector matrix is triangular.
924 0 ▶ if (abs ($H[$n * $N + ($n - 1)]) > abs ($H[($n - 1) * $N + $n]))
Branch: 1 branch
BranchTrueFalseTotal
if (abs $H[$n * $N + ($n - 1)] > abs $H[($n - 1) * $N + $n]) { } 0 0 0
925 {
926 0 $H[($n - 1) * $N + ($n - 1)] = $q / $H[$n * $N + ($n - 1)];
927 0 $H[($n - 1) * $N + $n] = ($p - $H[$n * $N + $n]) / $H[$n * $N + ($n - 1)];
928 }
929 else
930 {
931 0 ($H[($n - 1) * $N + ($n - 1)], $H[($n - 1) * $N + $n])
932 = cdiv (0, - $H[($n - 1) * $N + $n],
933 $H[($n - 1) * $N + ($n - 1)] - $p, $q);
934 }
935  
936 0 $H[$n * $N + ($n - 1)] = 0;
937 0 $H[$n * $N + $n] = 1;
938  
939 0 for $i (reverse (0 .. $n - 2))
940 {
941 0 $w = $H[$i * $N + $i] - $p;
942  
943 0 $ra = 0;
944 0 $sa = 0;
945  
946 0 for $j ($m .. $n)
947 {
948 0 $ra += $H[$i * $N + $j] * $H[$j * $N + ($n - 1)];
949 0 $sa += $H[$i * $N + $j] * $H[$j * $N + $n];
950 }
951  
952 0 ▶ if ($$e[$i] < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($e->[$i] < 0) { } 0 0 0
953 {
954 0 $z = $w;
955 0 $r = $ra;
956 0 $s = $sa;
957 }
958 else
959 {
960 0 $m = $i;
961  
962 0 ▶ if ($$e[$i] == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($e->[$i] == 0) { } 0 0 0
963 {
964 0 ($H[$i * $N + ($n - 1)], $H[$i * $N + $n])
965 = cdiv (- $ra, - $sa, $w, $q);
966 }
967 else
968 {
969 # Solve complex equations.
970 0 $x = $H[$i * $N + ($i + 1)];
971 0 $y = $H[($i + 1) * $N + $i];
972  
973 0 $vr = ($$d[$i] - $p) ** 2 + $$e[$i] ** 2 - $q ** 2;
974 0 $vi = ($$d[$i] - $p) * 2 * $q;
975  
976 0 ▶ if ($vr == 0 && $vi == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($vr == 0 and $vi == 0) 0 0 0
Condition0%0/3
$vr == 0 and $vi == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$vr == 0 and $vi == 0
$vr == 0 $vi == 0
Truth table0%0/3
A and B
A= $vr == 0B= $vi == 0
ABresult
0X0
100
111
977 {
978 0 $vr = eps * $norm * (abs ($w) + abs ($q) + abs ($x) + abs ($y) + abs ($z));
979 }
980  
981 0 ($H[$i * $N + ($n - 1)], $H[$i * $N + $n])
982 = cdiv ($x * $r - $z * $ra + $q * $sa,
983 $x * $s - $z * $sa - $q * $ra,
984 $vr,
985 $vi);
986  
987 0 ▶ if (abs ($x) > (abs ($z) + abs ($q)))
Branch: 1 branch
BranchTrueFalseTotal
if (abs $x > abs($z) + abs($q)) { } 0 0 0
988 {
989 0 $H[($i + 1) * $N + ($n - 1)] = (0 - $ra - $w * $H[$i * $N + ($n - 1)] + $q * $H[$i * $N + $n]) / $x;
990 0 $H[($i + 1) * $N + $n] = (0 - $sa - $w * $H[$i * $N + $n] - $q * $H[$i * $N + ($n - 1)]) / $x;
991 }
992 else
993 {
994 0 ($H[($i + 1) * $N + ($n - 1)], $H[($i + 1) * $N + $n])
995 = cdiv (0 - $r - $y * $H[$i * $N + ($n - 1)],
996 0 - $s - $y * $H[$i * $N + $n],
997 $z,
998 $q);
999 }
1000 }
1001  
1002 # Overflow control.
1003 0 $t = max (abs ($H[$i * $N + ($n - 1)]), abs ($H[$i * $N + $n]));
1004 0 ▶ if ((eps * $t) * $t > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (&eps() * $t * $t > 1) 0 0 0
1005 {
1006 0 for $j ($i .. $n)
1007 {
1008 0 $H[$j * $N + ($n - 1)] /= $t;
1009 0 $H[$j * $N + $n] /= $t;
1010 }
1011 }
1012 }
1013 }
1014 }
1015 }
1016  
1017 # Vectors of isolated roots.
1018 3 for $i (0 .. $end)
1019 {
1020 8 ▶ if ($i < $lo || $i > $hi)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $lo or $i > $hi) 2 6 8
Condition100%3/3
$i < $lo or $i > $hi
l!l&&r!l&&!r
116
MC/DC100%2/2
$i < $lo or $i > $hi
$i < $lo $i > $hi
Truth table100%3/3
A or B
A= $i < $loB= $i > $hi
ABresult
1X1
011
000
1021 {
1022 2 for $j ($i .. $end)
1023 {
1024 3 $$Z[$j][$i] = $H[$i * $N + $j];
1025 }
1026 }
1027 }
1028  
1029 # Multiply by transformation matrix to give
1030 # vectors of original full matrix.
1031 3 for $j (reverse ($lo .. $end))
1032 {
1033 7 $m = min ($j, $hi);
1034  
1035 7 for $i ($lo .. $hi)
1036 {
1037 18 $z = 0;
1038  
1039 18 for $k ($lo .. $m)
1040 {
1041 36 $z += $$Z[$k][$i] * $H[$k * $N + $j];
1042 }
1043  
1044 18 $$Z[$j][$i] = $z;
1045 }
1046 }
1047 }
1048  
1049 # Form the eigenvectors of a real general matrix by back
1050 # transforming those of the corresponding balanced matrix
1051 # determined by 'balance'.
1052 #
1053 # See EiSPACK procedure 'balbak'.
1054 3 ▶ if ($prop{balance})
Branch: 1 branch
BranchTrueFalseTotal
if ($prop{"balance"}) 3 0 3
1055 {
1056 3 my ($i, $j, $k);
1057  
1058 # Undo scaling.
1059 3 for $i ($lo .. $hi)
1060 {
1061 6 my $s = $scale[$i];
1062  
1063 6 for $j (0 .. $end)
1064 {
1065 18 $$Z[$j][$i] *= $s;
1066 }
1067 }
1068  
1069 # Undo permutations.
1070 3 for $i (reverse (0 .. $lo - 1))
1071 {
1072 1 $k = $perm[$i];
1073 1 ▶ if ($k != $i)
Branch: 1 branch
BranchTrueFalseTotal
if ($k != $i) 0 1 1
1074 {
1075 0 for $j (0 .. $end)
1076 {
1077 0 ($$Z[$j][$i], $$Z[$j][$k])
1078 = ($$Z[$j][$k], $$Z[$j][$i]);
1079 }
1080 }
1081 }
1082  
1083 3 for $i ($hi + 1 .. $end)
1084 {
1085 1 $k = $perm[$i];
1086 1 ▶ if ($k != $i)
Branch: 1 branch
BranchTrueFalseTotal
if ($k != $i) 0 1 1
1087 {
1088 0 for $j (0 .. $end)
1089 {
1090 0 ($$Z[$j][$i], $$Z[$j][$k])
1091 = ($$Z[$j][$k], $$Z[$j][$i]);
1092 }
1093 }
1094 }
1095 }
1096 }
1097  
1098 # Create complex eigenvalues.
1099 4 for my $i (0 .. $end)
1100 {
1101 11 ▶ $$d[$i] = Math::Complex->make ($$d[$i], $$e[$i])
Branch: 1 branch
BranchTrueFalseTotal
if $e->[$i] != 0 0 11 11
1102 if $$e[$i] != 0;
1103 }
1104  
1105 # Normalize eigenvectors.
1106 $self->normalize
1107 4 ▶ if $prop{normalize};
Branch: 1 branch
BranchTrueFalseTotal
if $prop{"normalize"} 4 0 4
1108  
1109 # Make first non-zero vector element a positive number.
1110 4 ▶ if ($prop{positive})
Branch: 1 branch
BranchTrueFalseTotal
if ($prop{"positive"}) 4 0 4
1111 {
1112 4 my ($i, $j, $k);
1113  
1114 4 for $j (0 .. $end)
1115 {
1116 11 for $i (0 .. $end)
1117 {
1118 11 ▶ next if $$Z[$j][$i] == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $Z->[$j][$i] == 0 0 11 11
1119  
1120 11 ▶ if ($$Z[$j][$i] < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($Z->[$j][$i] < 0) 5 6 11
1121 {
1122 5 for $k ($i .. $end)
1123 {
1124 15 $$Z[$j][$k] = - $$Z[$j][$k];
1125 }
1126 }
1127  
1128 11 last;
1129 }
1130 }
1131 }
1132  
1133 # Return object.
1134 4 $self;
1135 }
1136  
1137 # Balance a real matrix.
1138 #
1139 # See LAPACK procedure 'dgebal'.
1140 sub gebal ($$%)
1141 3 ▶{
Subroutine gebal: called CC=41 SCAR=40.2
Pod undocumented
1142 # Arguments.
1143 3 my ($n, $a, %opt) = @_;
1144  
1145 # Default options.
1146 3 ▶ $opt{permute} //= 1;
Condition50%1/2
$opt{"permute"} //= 1
l!l
03
MC/DC0%0/1
$opt{"permute"} //= 1
$opt{"permute"}
Truth table50%1/2
A
A= $opt{"permute"}
Aresult
11
00
1147 3 ▶ $opt{scale} //= 1;
Condition50%1/2
$opt{"scale"} //= 1
l!l
03
MC/DC0%0/1
$opt{"scale"} //= 1
$opt{"scale"}
Truth table50%1/2
A
A= $opt{"scale"}
Aresult
11
00
1148 3 ▶ $opt{low} //= undef;
Condition50%1/2
$opt{"low"} //= undef
l!l
30
MC/DC0%0/1
$opt{"low"} //= undef
$opt{"low"}
Truth table50%1/2
A
A= $opt{"low"}
Aresult
11
00
1149 3 ▶ $opt{high} //= undef;
Condition50%1/2
$opt{"high"} //= undef
l!l
30
MC/DC0%0/1
$opt{"high"} //= undef
$opt{"high"}
Truth table50%1/2
A
A= $opt{"high"}
Aresult
11
00
1150  
1151 # Index of last row/column.
1152 3 my $end = $n - 1;
1153  
1154 # Row and column indices of the beginning and end
1155 # of the principal sub-matrix.
1156 3 my $k = 0;
1157 3 my $l = $end;
1158  
1159 # Permutation vector.
1160 3 my @perm = (0 .. $end);
1161  
1162 # Scaling vector.
1163 3 my @scale = map (1, 0 .. $end);
1164  
1165 3 ▶ if ($n > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($n > 1) 3 0 3
1166 {
1167 # Isolate eigenvalues.
1168 3 ▶ if ($opt{permute})
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"permute"}) 3 0 3
1169 {
1170 # Search for rows isolating an eigenvalue
1171 # and push them down.
1172 L:
1173 {
1174 3 for my $j (reverse (0 .. $l))
1175 {
1176 7 my $swap = 1;
1177  
1178 7 for my $i (0 .. $l)
1179 {
1180 20 ▶ $swap = 0 if $i != $j && $$a[$j * $n + $i] != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $i != $j and $$a[$j * $n + $i] != 0 12 8 20
Condition100%3/3
$i != $j and $$a[$j * $n + $i] != 0
!ll&&!rl&&r
7112
MC/DC100%2/2
$i != $j and $$a[$j * $n + $i] != 0
$i != $j $$a[$j * $n + $i] != 0
Truth table100%3/3
A and B
A= $i != $jB= $$a[$j * $n + $i] != 0
ABresult
0X0
100
111
1181 }
1182  
1183 7 ▶ next unless $swap;
Branch: 1 branch
BranchTrueFalseTotal
unless $swap 6 1 7
1184  
1185 1 ▶ if ($j != $l)
Branch: 1 branch
BranchTrueFalseTotal
if ($j != $l) 0 1 1
1186 {
1187 # Exchange row and column.
1188 0 @perm[$j, $l] = @perm[$l, $j];
1189  
1190 0 blas_swap ($l + 1, $a, $a,
1191 x_ind => $j,
1192 x_incr => $n,
1193 y_ind => $l,
1194 y_incr => $n);
1195 0 blas_swap ($n - $k, $a, $a,
1196 x_ind => $j * $n + $k,
1197 x_incr => 1,
1198 y_ind => $l * $n + $k,
1199 y_incr => 1);
1200 }
1201  
1202 1 $l -= 1;
1203 1 next L;
1204 }
1205 }
1206  
1207 # Search for columns isolating an eigenvalue
1208 # and push them left.
1209 K:
1210 {
1211 3 for my $j ($k .. $l)
1212 {
1213 7 my $swap = 1;
1214  
1215 7 for my $i ($k .. $l)
1216 {
1217 19 ▶ $swap = 0 if $i != $j && $$a[$i * $n + $j] != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $i != $j and $$a[$i * $n + $j] != 0 12 7 19
Condition66%2/3
$i != $j and $$a[$i * $n + $j] != 0
!ll&&!rl&&r
7012
MC/DC50%1/2
$i != $j and $$a[$i * $n + $j] != 0
$i != $j $$a[$i * $n + $j] != 0
Truth table66%2/3
A and B
A= $i != $jB= $$a[$i * $n + $j] != 0
ABresult
0X0
100
111
1218 }
1219  
1220 7 ▶ next unless $swap;
Branch: 1 branch
BranchTrueFalseTotal
unless $swap 6 1 7
1221  
1222 1 ▶ if ($j != $k)
Branch: 1 branch
BranchTrueFalseTotal
if ($j != $k) 0 1 1
1223 {
1224 # Exchange row and column.
1225 0 @perm[$j, $k] = @perm[$k, $j];
1226  
1227 0 blas_swap ($l + 1, $a, $a,
1228 x_ind => $j,
1229 x_incr => $n,
1230 y_ind => $k,
1231 y_incr => $n);
1232 0 blas_swap ($n - $k, $a, $a,
1233 x_ind => $j * $n + $k,
1234 x_incr => 1,
1235 y_ind => $k * $n + $k,
1236 y_incr => 1);
1237 }
1238  
1239 1 $k += 1;
1240 1 next K;
1241 }
1242 }
1243 }
1244  
1245 # Balance the sub-matrix in rows k to l.
1246 3 ▶ if ($opt{scale})
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"scale"}) 3 0 3
1247 {
1248 3 my ($b, $c, $ca, $f, $g, $r, $ra, $s, $no_conv,
1249 $sfmin1, $sfmax1, $sfmin2, $sfmax2);
1250  
1251 # Scale factors are powers of two.
1252 3 $b = 2;
1253  
1254 3 if (1)
1255 {
1256 3 my $base = 2;
1257 3 my $eps = DBL_EPSILON;
1258 3 my $small = 1 / DBL_MAX;
1259 # Safe minimum, such that 1/sfmin does not overflow.
1260 3 ▶ my $sfmin = ($small >= DBL_MIN ? $small * (1 + $eps) : DBL_MIN);
Branch: 1 branch
BranchTrueFalseTotal
$small >= 2.2250738585072013831e-308 ? : 0 3 3
1261  
1262 3 $sfmin1 = $sfmin / ($eps * $base);
1263 3 $sfmax1 = 1 / $sfmin1;
1264 3 $sfmin2 = $sfmin1 * $b;
1265 3 $sfmax2 = 1 / $sfmin2;
1266 }
1267  
1268 # Iterative loop for norm reduction.
1269 3 while (1)
1270 {
1271 4 $no_conv = 0;
1272  
1273 4 for my $i ($k .. $l)
1274 {
1275 9 $c = blas_norm ($l - $k + 1, $a,
1276 norm => BLAS_TWO_NORM,
1277 x_ind => $k * $n + $i,
1278 x_incr => $n);
1279 9 $r = blas_norm ($l - $k + 1, $a,
1280 norm => BLAS_TWO_NORM,
1281 x_ind => $i * $n + $k,
1282 x_incr => 1);
1283 9 (undef, $ca) = blas_amax_val ($l + 1, $a,
1284 x_ind => $i,
1285 x_incr => $n);
1286 9 (undef, $ra) = blas_amax_val ($n - $k, $a,
1287 x_ind => $i * $n + $k,
1288 x_incr => 1);
1289  
1290 # Guard against zero c or r due to underflow.
1291 9 ▶ next if $c == 0 || $r == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $c == 0 or $r == 0 0 9 9
Condition33%1/3
$c == 0 or $r == 0
l!l&&r!l&&!r
009
MC/DC0%0/2
$c == 0 or $r == 0
$c == 0 $r == 0
Truth table33%1/3
A or B
A= $c == 0B= $r == 0
ABresult
1X1
011
000
1292  
1293 9 $s = $c + $r;
1294 9 $f = 1;
1295  
1296 9 $g = $r / $b;
1297 9 ▶ while ($c < $g
Branch: 1 branch
BranchTrueFalseTotal
if ($c < $g and &max($f, scalar &max($c, $ca)) < $sfmax2 and &min($g, scalar &min($r, $ra)) > $sfmin2) 1 9 10
Condition66%4/6
$c < $g and &max($f, scalar &max($c, $ca)) < $sfmax2 and &min($g, scalar &min($r, $ra)) > $sfmin2
!ll&&!rl&&r
901
$c < $g and &max($f, scalar &max($c, $ca)) < $sfmax2
!ll&&!rl&&r
901
MC/DC33%1/3
$c < $g and &max($f, scalar &max($c, $ca)) < $sfmax2 and &min($g, scalar &min($r, $ra)) > $sfmin2
$c < $g &max($f, scalar &max($c, $ca)) < $sfmax2 &min($g, scalar &min($r, $ra)) > $sfmin2
Truth table50%2/4
A and B and C
A= $c < $gB= &max($f, scalar &max($c, $ca)) < $sfmax2C= &min($g, scalar &min($r, $ra)) > $sfmin2
ABCresult
0XX0
10X0
1100
1111
1298 && max ($f, max ($c, $ca)) < $sfmax2
1299 && min ($g, min ($r, $ra)) > $sfmin2)
1300 {
1301 1 ▶ croak ('Infinite loop')
Branch: 1 branch
BranchTrueFalseTotal
if &isnan($f + $c + $ca + $g + $r + $ra) 0 1 1
1302 if isnan ($f + $c + $ca + $g + $r + $ra);
1303  
1304 1 $f *= $b;
1305 1 $c *= $b;
1306 1 $ca *= $b;
1307 1 $g /= $b;
1308 1 $r /= $b;
1309 1 $ra /= $b;
1310 }
1311  
1312 9 $g = $c / $b;
1313 9 ▶ while ($g >= $r
Branch: 1 branch
BranchTrueFalseTotal
if ($g >= $r and &max($r, $ra) < $sfmax2 and &min($g, scalar &min($f, scalar &min($c, $ca))) > $sfmin2) 2 9 11
Condition66%4/6
$g >= $r and &max($r, $ra) < $sfmax2 and &min($g, scalar &min($f, scalar &min($c, $ca))) > $sfmin2
!ll&&!rl&&r
902
$g >= $r and &max($r, $ra) < $sfmax2
!ll&&!rl&&r
902
MC/DC33%1/3
$g >= $r and &max($r, $ra) < $sfmax2 and &min($g, scalar &min($f, scalar &min($c, $ca))) > $sfmin2
$g >= $r &max($r, $ra) < $sfmax2 &min($g, scalar &min($f, scalar &min($c, $ca))) > $sfmin2
Truth table50%2/4
A and B and C
A= $g >= $rB= &max($r, $ra) < $sfmax2C= &min($g, scalar &min($f, scalar &min($c, $ca))) > $sfmin2
ABCresult
0XX0
10X0
1100
1111
1314 && max ($r, $ra) < $sfmax2
1315 && min ($g, min ($f, min ($c, $ca))) > $sfmin2)
1316 {
1317 2 $f /= $b;
1318 2 $c /= $b;
1319 2 $ca /= $b;
1320 2 $g /= $b;
1321 2 $r *= $b;
1322 2 $ra *= $b;
1323 }
1324  
1325 # Now balance.
1326 9 ▶ if (! (($c + $r) >= 0.95 * $s
Branch: 1 branch
BranchTrueFalseTotal
unless ($c + $r >= "0.95" * $s or $f < 1 and $scale[$i] < 1 and $f * $scale[$i] <= $sfmin1 or $f > 1 and $scale[$i] > 1 and $scale[$i] >= $sfmax1 / $f) 3 6 9
Condition55%10/18
$c + $r >= "0.95" * $s or $f < 1 and $scale[$i] < 1 and $f * $scale[$i] <= $sfmin1 or $f > 1 and $scale[$i] > 1 and $scale[$i] >= $sfmax1 / $f
l!l&&r!l&&!r
603
$c + $r >= "0.95" * $s or $f < 1 and $scale[$i] < 1 and $f * $scale[$i] <= $sfmin1
l!l&&r!l&&!r
603
$f < 1 and $scale[$i] < 1 and $f * $scale[$i] <= $sfmin1
!ll&&!rl&&r
300
$f < 1 and $scale[$i] < 1
!ll&&!rl&&r
120
$f > 1 and $scale[$i] > 1 and $scale[$i] >= $sfmax1 / $f
!ll&&!rl&&r
300
$f > 1 and $scale[$i] > 1
!ll&&!rl&&r
210
MC/DC14%1/7
$c + $r >= "0.95" * $s or $f < 1 and $scale[$i] < 1 and $f * $scale[$i] <= $sfmin1 or $f > 1 and $scale[$i] > 1 and $scale[$i] >= $sfmax1 / $f
$c + $r >= "0.95" * $s $f < 1 $scale[$i] < 1 $f * $scale[$i] <= $sfmin1 $f > 1 $scale[$i] > 1 $scale[$i] >= $sfmax1 / $f
Truth table21%3/14
A or B and C and D or E and F and G
A= $c + $r >= "0.95" * $sB= $f < 1C= $scale[$i] < 1D= $f * $scale[$i] <= $sfmin1E= $f > 1F= $scale[$i] > 1G= $scale[$i] >= $sfmax1 / $f
ABCDEFGresult
1XXXXXX1
0111XXX1
00XX1111
010X1111
01101111
00XX0XX0
00XX10X0
00XX1100
010X0XX0
010X10X0
010X1100
01100XX0
011010X0
01101100
1327 || ($f < 1 && $scale[$i] < 1 && $f * $scale[$i] <= $sfmin1)
1328 || ($f > 1 && $scale[$i] > 1 && $scale[$i] >= $sfmax1 / $f)))
1329 {
1330 3 blas_rscale ($n - $k, $a,
1331 alpha => $f,
1332 x_ind => $i * $n + $k,
1333 x_incr => 1);
1334 3 blas_scale ($l + 1, $a,
1335 alpha => $f,
1336 x_ind => $i,
1337 x_incr => $n);
1338  
1339 3 $scale[$i] *= $f;
1340 3 $no_conv = 1;
1341 }
1342 }
1343  
1344 4 ▶ last unless $no_conv;
Branch: 1 branch
BranchTrueFalseTotal
unless $no_conv 3 1 4
1345 }
1346 }
1347 }
1348  
1349 3 ${$opt{low}} = $k
1350 3 ▶ if ref ($opt{low});
Branch: 1 branch
BranchTrueFalseTotal
if ref $opt{"low"} 3 0 3
1351  
1352 3 ${$opt{high}} = $l
1353 3 ▶ if ref ($opt{high});
Branch: 1 branch
BranchTrueFalseTotal
if ref $opt{"high"} 3 0 3
1354  
1355 3 return (\@perm, \@scale);
1356 }
1357  
1358 # Normalize eigenvectors.
1359 sub normalize
1360 4 ▶{
Subroutine normalize: called CC=3 SCAR=11.0
Pod documented
1361 4 my $self = shift;
1362  
1363 # Work variables.
1364 4 my $len;
1365  
1366 4 for my $v (@{ $$self{vector} })
1367 {
1368 11 $len = blas_norm (@$v, $v, norm => BLAS_TWO_NORM);
1369 11 ▶ blas_rscale (@$v, $v, alpha => $len) if $len != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $len != 0 11 0 11
1370 }
1371  
1372 # Return object.
1373 4 $self;
1374 }
1375  
1376 # Sort eigenvalues and corresponding eigenvectors.
1377 sub sort
1378 4 ▶{
Subroutine sort: called CC=35 SCAR=64.7
Pod documented
1379 4 my $self = shift;
1380 4 ▶ my $order = shift // 'abs_desc';
Condition50%1/2
shift() // "abs_desc"
l!l
40
MC/DC0%0/1
shift() // "abs_desc"
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1381  
1382 # Permutation vector.
1383 4 my @p = ();
1384  
1385 4 ▶ if ($order =~ m/\Avec_/)
Branch: 2 branches
BranchTrueFalseTotal
if ($order =~ /\Avec_/) { } 0 4 4
elsif (grep ref($_), @{$$self{'value'};}) { } 0 4 4
1386 {
1387 0 my $Z = $$self{vector};
1388  
1389 @p = ($order eq 'vec_desc' ?
1390 0 ▶ sort { _cmp_vec ($$Z[$b], $$Z[$a]) } 0 .. $#$Z :
Branch: 1 branch
BranchTrueFalseTotal
$order eq 'vec_asc' ? : 0 0 0
1391 ($order eq 'vec_asc' ?
1392 0 ▶ sort { _cmp_vec ($$Z[$a], $$Z[$b]) } 0 .. $#$Z :
Branch: 1 branch
BranchTrueFalseTotal
$order eq 'vec_desc' ? : 0 0 0
1393 croak ("Invalid argument")));
1394 }
1395 4 elsif (grep (ref ($_), @{ $$self{value} }))
1396 {
1397 # Consider complex eigenvalues.
1398 0 my (@d, @e, @m) = ();
1399  
1400 0 for (@{ $$self{value} })
1401 {
1402 0 ▶ if (ref ($_))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_) { } 0 0 0
1403 {
1404 0 push (@d, $_->Re);
1405 0 push (@e, $_->Im);
1406 0 push (@m, abs ($_));
1407 }
1408 else
1409 {
1410 0 push (@d, $_);
1411 0 push (@e, 0);
1412 0 push (@m, abs ($_));
1413 }
1414 }
1415  
1416 @p = ($order eq 'abs_desc' ?
1417 0 ▶ sort { abs ($d[$b]) <=> abs ($d[$a]) || $m[$b] <=> $m[$a] || $d[$b] <=> $d[$a] || $e[$b] <=> $e[$a] } 0 .. $#d :
Branch: 1 branch
BranchTrueFalseTotal
$order eq 'abs_asc' ? : 0 0 0
Condition0%0/9
abs $d[$b] <=> abs $d[$a] || $m[$b] <=> $m[$a] || $d[$b] <=> $d[$a] || $e[$b] <=> $e[$a]
l!l&&r!l&&!r
000
abs $d[$b] <=> abs $d[$a] or $m[$b] <=> $m[$a] or $d[$b] <=> $d[$a]
l!l&&r!l&&!r
000
abs $d[$b] <=> abs $d[$a] or $m[$b] <=> $m[$a]
l!l&&r!l&&!r
000
MC/DC0%0/4
abs $d[$b] <=> abs $d[$a] || $m[$b] <=> $m[$a] || $d[$b] <=> $d[$a] || $e[$b] <=> $e[$a]
abs $d[$b] <=> abs $d[$a] $m[$b] <=> $m[$a] $d[$b] <=> $d[$a] $e[$b] <=> $e[$a]
Truth table0%0/5
A or B or C || D
A= abs $d[$b] <=> abs $d[$a]B= $m[$b] <=> $m[$a]C= $d[$b] <=> $d[$a]D= $e[$b] <=> $e[$a]
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1418 ($order eq 'abs_asc' ?
1419 0 ▶ sort { abs ($d[$a]) <=> abs ($d[$b]) || $m[$a] <=> $m[$b] || $d[$a] <=> $d[$b] || $e[$a] <=> $e[$b] } 0 .. $#d :
Branch: 1 branch
BranchTrueFalseTotal
$order eq 'norm_desc' ? : 0 0 0
Condition0%0/9
abs $d[$a] <=> abs $d[$b] || $m[$a] <=> $m[$b] || $d[$a] <=> $d[$b] || $e[$a] <=> $e[$b]
l!l&&r!l&&!r
000
abs $d[$a] <=> abs $d[$b] or $m[$a] <=> $m[$b] or $d[$a] <=> $d[$b]
l!l&&r!l&&!r
000
abs $d[$a] <=> abs $d[$b] or $m[$a] <=> $m[$b]
l!l&&r!l&&!r
000
MC/DC0%0/4
abs $d[$a] <=> abs $d[$b] || $m[$a] <=> $m[$b] || $d[$a] <=> $d[$b] || $e[$a] <=> $e[$b]
abs $d[$a] <=> abs $d[$b] $m[$a] <=> $m[$b] $d[$a] <=> $d[$b] $e[$a] <=> $e[$b]
Truth table0%0/5
A or B or C || D
A= abs $d[$a] <=> abs $d[$b]B= $m[$a] <=> $m[$b]C= $d[$a] <=> $d[$b]D= $e[$a] <=> $e[$b]
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1420 ($order eq 'norm_desc' ?
1421 0 ▶ sort { $m[$b] <=> $m[$a] || $d[$b] <=> $d[$a] || $e[$b] <=> $e[$a] } 0 .. $#d :
Branch: 1 branch
BranchTrueFalseTotal
$order eq 'norm_asc' ? : 0 0 0
Condition0%0/6
$m[$b] <=> $m[$a] || $d[$b] <=> $d[$a] || $e[$b] <=> $e[$a]
l!l&&r!l&&!r
000
$m[$b] <=> $m[$a] or $d[$b] <=> $d[$a]
l!l&&r!l&&!r
000
MC/DC0%0/3
$m[$b] <=> $m[$a] || $d[$b] <=> $d[$a] || $e[$b] <=> $e[$a]
$m[$b] <=> $m[$a] $d[$b] <=> $d[$a] $e[$b] <=> $e[$a]
Truth table0%0/4
A or B || C
A= $m[$b] <=> $m[$a]B= $d[$b] <=> $d[$a]C= $e[$b] <=> $e[$a]
ABCresult
1XX1
01X1
0011
0000
1422 ($order eq 'norm_asc' ?
1423 0 ▶ sort { $m[$a] <=> $m[$b] || $d[$a] <=> $d[$b] || $e[$a] <=> $e[$b] } 0 .. $#d :
Branch: 1 branch
BranchTrueFalseTotal
$order eq 'desc' ? : 0 0 0
Condition0%0/6
$m[$a] <=> $m[$b] || $d[$a] <=> $d[$b] || $e[$a] <=> $e[$b]
l!l&&r!l&&!r
000
$m[$a] <=> $m[$b] or $d[$a] <=> $d[$b]
l!l&&r!l&&!r
000
MC/DC0%0/3
$m[$a] <=> $m[$b] || $d[$a] <=> $d[$b] || $e[$a] <=> $e[$b]
$m[$a] <=> $m[$b] $d[$a] <=> $d[$b] $e[$a] <=> $e[$b]
Truth table0%0/4
A or B || C
A= $m[$a] <=> $m[$b]B= $d[$a] <=> $d[$b]C= $e[$a] <=> $e[$b]
ABCresult
1XX1
01X1
0011
0000
1424 ($order eq 'desc' ?
1425 0 ▶ sort { $d[$b] <=> $d[$a] || $e[$b] <=> $e[$a] } 0 .. $#d :
Branch: 1 branch
BranchTrueFalseTotal
$order eq 'asc' ? : 0 0 0
Condition0%0/3
$d[$b] <=> $d[$a] || $e[$b] <=> $e[$a]
l!l&&r!l&&!r
000
MC/DC0%0/2
$d[$b] <=> $d[$a] || $e[$b] <=> $e[$a]
$d[$b] <=> $d[$a] $e[$b] <=> $e[$a]
Truth table0%0/3
A || B
A= $d[$b] <=> $d[$a]B= $e[$b] <=> $e[$a]
ABresult
1X1
011
000
1426 ($order eq 'asc' ?
1427 0 ▶ sort { $d[$a] <=> $d[$b] || $e[$a] <=> $e[$b] } 0 .. $#d :
Branch: 1 branch
BranchTrueFalseTotal
$order eq 'abs_desc' ? : 0 0 0
Condition0%0/3
$d[$a] <=> $d[$b] || $e[$a] <=> $e[$b]
l!l&&r!l&&!r
000
MC/DC0%0/2
$d[$a] <=> $d[$b] || $e[$a] <=> $e[$b]
$d[$a] <=> $d[$b] $e[$a] <=> $e[$b]
Truth table0%0/3
A || B
A= $d[$a] <=> $d[$b]B= $e[$a] <=> $e[$b]
ABresult
1X1
011
000
1428 croak ("Invalid argument")))))));
1429 }
1430 else
1431 {
1432 # Only real eigenvalues.
1433 4 my $d = $$self{value};
1434  
1435 @p = ($order eq 'abs_desc' || $order eq 'norm_desc' ?
1436 0 ▶ sort { abs ($$d[$b]) <=> abs ($$d[$a]) || $$d[$b] <=> $$d[$a] } 0 .. $#$d :
Branch: 1 branch
BranchTrueFalseTotal
$order eq 'abs_asc' || $order eq 'norm_asc' ? : 0 4 4
Condition16%1/6
abs $d->[$b] <=> abs $d->[$a] || $d->[$b] <=> $d->[$a]
l!l&&r!l&&!r
000
$order eq "abs_asc" or $order eq "norm_asc"
l!l&&r!l&&!r
004
MC/DC0%0/2
abs $d->[$b] <=> abs $d->[$a] || $d->[$b] <=> $d->[$a]
abs $d->[$b] <=> abs $d->[$a] $d->[$b] <=> $d->[$a]
MC/DC0%0/2
$order eq "abs_asc" or $order eq "norm_asc"
$order eq "abs_asc" $order eq "norm_asc"
Truth table0%0/3
A || B
A= abs $d->[$b] <=> abs $d->[$a]B= $d->[$b] <=> $d->[$a]
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $order eq "abs_asc"B= $order eq "norm_asc"
ABresult
1X1
011
000
1437 ($order eq 'abs_asc' || $order eq 'norm_asc' ?
1438 0 ▶ sort { abs ($$d[$a]) <=> abs ($$d[$b]) || $$d[$a] <=> $$d[$b] } 0 .. $#$d :
Branch: 1 branch
BranchTrueFalseTotal
$order eq 'desc' ? : 0 4 4
Condition0%0/3
abs $d->[$a] <=> abs $d->[$b] || $d->[$a] <=> $d->[$b]
l!l&&r!l&&!r
000
MC/DC0%0/2
abs $d->[$a] <=> abs $d->[$b] || $d->[$a] <=> $d->[$b]
abs $d->[$a] <=> abs $d->[$b] $d->[$a] <=> $d->[$b]
Truth table0%0/3
A || B
A= abs $d->[$a] <=> abs $d->[$b]B= $d->[$a] <=> $d->[$b]
ABresult
1X1
011
000
1439 ($order eq 'desc' ?
1440 0 ▶ sort { $$d[$b] <=> $$d[$a] } 0 .. $#$d :
Branch: 1 branch
BranchTrueFalseTotal
$order eq 'asc' ? : 4 0 4
1441 ($order eq 'asc' ?
1442 4 ▶ sort { $$d[$a] <=> $$d[$b] } 0 .. $#$d :
Branch: 1 branch
BranchTrueFalseTotal
$order eq 'abs_desc' || $order eq 'norm_desc' ? : 0 4 4
Condition33%1/3
$order eq "abs_desc" or $order eq "norm_desc"
l!l&&r!l&&!r
004
MC/DC0%0/2
$order eq "abs_desc" or $order eq "norm_desc"
$order eq "abs_desc" $order eq "norm_desc"
Truth table33%1/3
A or B
A= $order eq "abs_desc"B= $order eq "norm_desc"
ABresult
1X1
011
000
1443 croak ("Invalid argument")))));
1444 }
1445  
1446 # Reorder eigenvalues and corresponding eigenvectors.
1447 4 ▶ if (@p > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@p > 0) 4 0 4
1448 {
1449 4 my $ref;
1450  
1451 4 $ref = $$self{value};
1452 4 @$ref = @$ref[@p];
1453  
1454 4 $ref = $$self{vector};
1455 4 @$ref = @$ref[@p];
1456 }
1457  
1458 # Return object.
1459 4 $self;
1460 }
1461  
1462 # Compare two eigenvectors.
1463 sub _cmp_vec
1464 0 ▶{
Subroutine _cmp_vec: not called CC=4 SCAR=30.0
1465 0 my ($u, $v) = @_;
1466  
1467 0 ▶ croak ("Invalid argument")
Branch: 1 branch
BranchTrueFalseTotal
if $u->$#* != $v->$#* 0 0 0
1468 if $#$u != $#$v;
1469  
1470 0 my $d = 0;
1471  
1472 0 for my $i (0 .. $#$u)
1473 {
1474 0 ▶ last if $d = ($$u[$i] <=> $$v[$i]);
Branch: 1 branch
BranchTrueFalseTotal
if $d = $u->[$i] <=> $v->[$i] 0 0 0
1475 }
1476  
1477 0 $d;
1478 }
1479  
1480 # Return one or more eigenvalues.
1481 sub value
1482 4 ▶{
Subroutine value: called CC=2 SCAR=7.6
Pod documented
1483 4 my $self = shift;
1484  
1485 0 ▶ @_ > 0 ? @{ $$self{value} }[@_] : @{ $$self{value} };
Branch: 1 branch
BranchTrueFalseTotal
@_ > 0 ? : 0 4 4
1486 }
1487  
1488 1 *values = \&value;
1489  
1490 # Return one or more eigenvectors.
1491 sub vector
1492 11 ▶{
Subroutine vector: called CC=2 SCAR=7.6
Pod documented
1493 11 my $self = shift;
1494  
1495 0 ▶ @_ > 0 ? @{ $$self{vector} }[@_] : @{ $$self{vector} };
Branch: 1 branch
BranchTrueFalseTotal
@_ > 0 ? : 11 0 11
1496 }
1497  
1498 1 *vectors = \&vector;
1499  
1500 1 1;
1501  
1502 __END__
↑ Summary blib/lib/Math/MatrixDecomposition.pm »