| 1 | 56 | $DEBUG = 0; | |||||||||||
| 2 | 56 | my $eps = 1e-8; | |||||||||||
| 3 | ######### help funcs | ||||||||||||
| 4 | sub ok_matrix ($$$) | ||||||||||||
| 5 | 69 | ▶ | { | ||||||||||
|
Subroutine
ok_matrix: called CC=2 SCAR=7.0
| |||||||||||||
| 6 | 69 | my ($a, $b, $msg) = @_; | |||||||||||
| 7 | 69 | my $res = abs($a-$b); | |||||||||||
| 8 | 69 | ok( similar($a,$b) , $msg); | |||||||||||
| 9 | 69 | ▶ | print " (|Delta| = $res)\n" if $DEBUG; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 10 | } | ||||||||||||
| 11 | sub ok_matrix_orthogonal ($) | ||||||||||||
| 12 | 7 | ▶ | { | ||||||||||
|
Subroutine
ok_matrix_orthogonal: called CC=2 SCAR=6.9
| |||||||||||||
| 13 | 7 | my ($M) = @_; | |||||||||||
| 14 | 7 | my $tmp = $M->shadow(); | |||||||||||
| 15 | 7 | $tmp->one(); | |||||||||||
| 16 | 7 | my $transp = $M->shadow(); | |||||||||||
| 17 | 7 | $transp->transpose($M); | |||||||||||
| 18 | 7 | $tmp->subtract($M->multiply($transp), $tmp); | |||||||||||
| 19 | 7 | my $v = $tmp->norm_one(); | |||||||||||
| 20 | 7 | ok(($v < $eps), 'matrix is orthogonal'); | |||||||||||
| 21 | 7 | ▶ | print " (|M * ~M - I| = $v)\n" if $DEBUG; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 22 | } | ||||||||||||
| 23 | sub ok_eigenvectors ($$$;$) | ||||||||||||
| 24 | 7 | ▶ | { | ||||||||||
|
Subroutine
ok_eigenvectors: called CC=5 SCAR=16.4
| |||||||||||||
| 25 | 7 | my ($M, $L, $V, $msg) = @_; | |||||||||||
| 26 | 7 | ▶ | $msg ||= 'eigenvectors computed correctly'; | ||||||||||
|
Condition50%1/2
$msg ||= "eigenvectors computed correctly"
MC/DC0%0/1
$msg ||= "eigenvectors computed correctly"
$msg
Truth table50%1/2
A
A= $msg
| |||||||||||||
| 27 | # Now check that all of them correspond to eigenvalue * eigenvector | ||||||||||||
| 28 | 7 | my ($rows, $columns) = $M->dim(); | |||||||||||
| 29 | 7 | ▶ | unless ($rows == $columns) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 30 | 0 | ok(0,'matrix should be square to compute eigenvalues'); | |||||||||||
| 31 | 0 | return; | |||||||||||
| 32 | } | ||||||||||||
| 33 | # Computes the result of all eigenvectors... | ||||||||||||
| 34 | 7 | my $test = $M * $V; | |||||||||||
| 35 | 7 | my $test2 = $V->clone(); | |||||||||||
| 36 | 7 | ▶ | for (my $i = 1; $i <= $columns; $i++) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 37 | { | ||||||||||||
| 38 | 105 | my $lambda = $L->element($i,1); | |||||||||||
| 39 | 105 | ▶ | for (my $j = 1; $j <= $rows; $j++) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 40 | { # Compute new vector via lambda * x | ||||||||||||
| 41 | 2541 | $test2->assign($j, $i, $lambda * $test2->element($j, $i)); | |||||||||||
| 42 | } | ||||||||||||
| 43 | } | ||||||||||||
| 44 | 7 | ok_matrix($test,$test2, $msg ); | |||||||||||
| 45 | 7 | return; | |||||||||||
| 46 | } | ||||||||||||
| 47 | 108 | ▶ | sub similar($$;$) { | ||||||||||
|
Subroutine
similar: called CC=3 SCAR=11.0
| |||||||||||||
| 48 | 108 | my ($x,$y, $eps) = @_; | |||||||||||
| 49 | 108 | ▶ | $eps ||= 1e-8; | ||||||||||
|
Condition100%2/2
$eps ||= "1e-08"
MC/DC100%1/1
$eps ||= "1e-08"
$eps
Truth table100%2/2
A
A= $eps
| |||||||||||||
| 50 | 108 | ▶ | abs($x-$y) < $eps ? 1 : 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 51 | } | ||||||||||||
| 52 | |||||||||||||
| 53 | sub _debug_info | ||||||||||||
| 54 | 0 | ▶ | { | ||||||||||
|
Subroutine
_debug_info: not called CC=6 SCAR=37.4
| |||||||||||||
| 55 | 0 | my($text,$object,$argument,$flag) = @_; | |||||||||||
| 56 | |||||||||||||
| 57 | 0 | ▶ | unless (defined $object) { $object = 'undef'; }; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | 0 | ▶ | unless (defined $argument) { $argument = 'undef'; }; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 59 | 0 | ▶ | unless (defined $flag) { $flag = 'undef'; }; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 60 | 0 | ▶ | if (ref($object)) { $object = ref($object); } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 61 | 0 | ▶ | if (ref($argument)) { $argument = ref($argument); } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 62 | 0 | print "$text: \$obj='$object' \$arg='$argument' \$flag='$flag'\n"; | |||||||||||
| 63 | } | ||||||||||||
| 64 | |||||||||||||
| 65 | sub assert_dies($;$) | ||||||||||||
| 66 | 13 | ▶ | { | ||||||||||
|
Subroutine
assert_dies: called CC=1 SCAR=0.0
| |||||||||||||
| 67 | 13 | my ($code,$msg) = @_; | |||||||||||
| 68 | 13 | eval { &$code }; | |||||||||||
| 69 | 13 | ok($@, $msg); | |||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | 56 | 1; | |||||||||||