File: diag.t

package info (click to toggle)
libmath-matrixreal-perl 2.13-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,120 kB
  • sloc: perl: 2,837; makefile: 8
file content (85 lines) | stat: -rw-r--r-- 2,354 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use Test::More tests => 8;
use Math::MatrixReal;
use File::Spec;
use lib File::Spec->catfile("..","lib");

do 'funcs.pl';

##########################
## test to see if is_diagonal works
my $matrix = Math::MatrixReal->new_from_string(<<'MATRIX');
[  1  0  0  0  0  0  0  ]
[  0  5  0  0  0  0  0  ]
[  0  0  1  0  0  0  0  ]
[  0  0  0  1  0  0  0  ]
[  0  0  0  0  5  0  0  ]
[  0  0  0  0  0  1  0  ]
[  0  0  0  0  0  0 -5  ]
MATRIX
ok( $matrix->is_diagonal(), 'is_diagonal works' );
###############################
## make sure it recognizes a matrix that is not diagonal
$matrix = Math::MatrixReal->new_from_string(<<"MATRIX");
      [  3  0  1  ]
      [  0  3  0  ]
      [  0  0  3  ]
MATRIX
ok(! $matrix->is_diagonal() );
###############################
## see if knows that if it ain't square, it ain't diagonal
$matrix = Math::MatrixReal->new_from_string(<<"MATRIX");
[ 1  0 ]
[ 0  0 ]
[ 0  1 ]
MATRIX
ok( ! $matrix->is_diagonal(), 'nonsquare matrix is not diagonal' );
##############################
## 1x1 matrix is diagonal by definition
$matrix = Math::MatrixReal->new_from_string(<<"MATRIX");
[ 1 ]
MATRIX
ok( $matrix->is_diagonal() ,'1x1 matrix is diagonal by definition');
##############################
### see if is_tridiagonal works
$matrix = Math::MatrixReal->new_from_string(<<'MATRIX');
[  4  7  0  0  0  0  0  ]
[  1  5  2  0  0  0  0  ]
[  0  9  1  3  0  0  0  ]
[  0  0  5  1  8  0  0  ]
[  0  0  0  6  5  3  0  ]
[  0  0  0  0  7  1  4  ]
[  0  0  0  0  0  4 -5  ]
MATRIX
ok($matrix->is_tridiagonal() );
##############################
### this isn't tridiag
$matrix = Math::MatrixReal->new_from_string(<<'MATRIX');
[  2  4  0  0  0  0  9  ]
[  1  5  2  0  0  0  0  ]
[  0  3  1  3  0  0  0  ]
[  0  0  5  1  8  0  0  ]
[  0  0  0  6  5  3  0  ]
[  0  0  0  0  7  1  4  ]
[  0  0  0  0  0  4  2  ]
MATRIX
ok( ! $matrix->is_tridiagonal() );
##############################
$matrix = Math::MatrixReal->new_from_string(<<'MATRIX');
[ 1 1 ]
[ 1 1 ]
MATRIX
ok( $matrix->is_tridiagonal(), '2x2 is always tridiag' );
###############################
### not quadratic => not tridiag
$matrix = Math::MatrixReal->new_from_string(<<'MATRIX');
[  2  4  0  0  0  0 ]
[  1  5  2  0  0  0 ]
[  0  3  1  3  0  0 ]
[  0  0  5  1  8  0 ]
[  0  0  0  6  5  3 ]
[  0  0  0  0  7  1 ]
[  0  0  0  0  0  4 ]
MATRIX
ok(! $matrix->is_tridiagonal() );