File: gbtest37.m

package info (click to toggle)
suitesparse-graphblas 7.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,112 kB
  • sloc: ansic: 1,072,243; cpp: 8,081; sh: 512; makefile: 506; asm: 369; python: 125; awk: 10
file content (148 lines) | stat: -rw-r--r-- 5,667 bytes parent folder | download | duplicates (2)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
function gbtest37
%GBTEST37 test istril, istriu, isbanded, isdiag, ishermitian, ...
% issymmetric, bandwith

% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0

rng ('default') ;
nmax = 5 ;
for trial = 1:10
    fprintf ('.') ;

    for m = 1:nmax
        for n = 1:nmax
            A = sprand (m, n, 0.5) ;

            skew = false ;
            if (m == n)
                if (mod (trial, 10) == 1)
                    % make A symmetric
                    A = A + A' ;
                elseif (mod (trial, 10) == 2)
                    % make A skew symmetric
                    A = A - A' ;
                    skew = true ;
                end
            end

            if (m == n)
                C = A+A' ;
            else
                C = A*A' ;
            end

            if (~skew)
                if (rand < 0.1)
                    A = logical (A) ;
                    C = logical (C) ;
                end
            end

            L = tril (A) ;
            U = triu (A) ;
            D = diag (diag (A)) ;

            GA = GrB (A) ;
            GL = tril (GA) ;
            GU = triu (GA) ;
            GD = diag (diag (GA)) ;
            if (m == n)
                GC = GrB.prune (GA + GA') ;
            else
                GC = GrB.prune (GA * GA') ;
            end

            for fmt = 0:1

                if (fmt == 1)
                    GA = GrB (GA, 'by row') ;
                    GL = GrB (GL, 'by row') ;
                    GU = GrB (GU, 'by row') ;
                    GD = GrB (GD, 'by row') ;
                    GC = GrB (GC, 'by row') ;
                end

                assert (gbtest_eq (A, GA)) ;
                assert (gbtest_eq (L, GL)) ;
                assert (gbtest_eq (U, GU)) ;
                assert (gbtest_eq (D, GD)) ;
                assert (gbtest_eq (C, GC)) ;

                if (~islogical (A))
                    % built-in istril, istriu, and isdiag
                    % are not defined when A is logical.
                    assert (istril (A) == istril (GA)) ;
                    assert (istril (L) == istril (GL)) ;
                    assert (istril (U) == istril (GU)) ;
                    assert (istril (D) == istril (GD)) ;
                    assert (istril (C) == istril (GC)) ;

                    assert (istriu (A) == istriu (GA)) ;
                    assert (istriu (L) == istriu (GL)) ;
                    assert (istriu (U) == istriu (GU)) ;
                    assert (istriu (D) == istriu (GD)) ;
                    assert (istriu (C) == istriu (GC)) ;

                    assert (isdiag (A) == isdiag (GA)) ;
                    assert (isdiag (L) == isdiag (GL)) ;
                    assert (isdiag (U) == isdiag (GU)) ;
                    assert (isdiag (D) == isdiag (GD)) ;
                    assert (isdiag (C) == isdiag (GC)) ;
                end

                assert (ishermitian (A) == ishermitian (GA)) ;
                assert (ishermitian (L) == ishermitian (GL)) ;
                assert (ishermitian (U) == ishermitian (GU)) ;
                assert (ishermitian (D) == ishermitian (GD)) ;
                assert (ishermitian (C) == ishermitian (GC)) ;

                assert (ishermitian (A, 'skew') == ishermitian (GA, 'skew')) ;

                assert (issymmetric (A) == issymmetric (GA)) ;
                assert (issymmetric (L) == issymmetric (GL)) ;
                assert (issymmetric (U) == issymmetric (GU)) ;
                assert (issymmetric (D) == issymmetric (GD)) ;
                assert (issymmetric (C) == issymmetric (GC)) ;

                assert (issymmetric (A, 'skew') == issymmetric (GA, 'skew')) ;

                if (~islogical (A))
                    assert (isequal (bandwidth (A), bandwidth (GA))) ;
                    assert (isequal (bandwidth (L), bandwidth (GL))) ;
                    assert (isequal (bandwidth (U), bandwidth (GU))) ;
                    assert (isequal (bandwidth (D), bandwidth (GD))) ;
                    assert (isequal (bandwidth (C), bandwidth (GC))) ;

                    assert (bandwidth (A, 'lower') == bandwidth (GA, 'lower')) ;
                    assert (bandwidth (L, 'lower') == bandwidth (GL, 'lower')) ;
                    assert (bandwidth (U, 'lower') == bandwidth (GU, 'lower')) ;
                    assert (bandwidth (D, 'lower') == bandwidth (GD, 'lower')) ;
                    assert (bandwidth (C, 'lower') == bandwidth (GC, 'lower')) ;

                    assert (bandwidth (A, 'upper') == bandwidth (GA, 'upper')) ;
                    assert (bandwidth (L, 'upper') == bandwidth (GL, 'upper')) ;
                    assert (bandwidth (U, 'upper') == bandwidth (GU, 'upper')) ;
                    assert (bandwidth (D, 'upper') == bandwidth (GD, 'upper')) ;
                    assert (bandwidth (C, 'upper') == bandwidth (GC, 'upper')) ;

                    for lo = 0:nmax
                        for hi = 0:nmax
                            assert (isbanded (A,  lo, hi) == ...
                                    isbanded (GA, lo, hi)) ;
                            assert (isbanded (L,  lo, hi) == ...
                                    isbanded (GL, lo, hi)) ;
                            assert (isbanded (U,  lo, hi) == ...
                                    isbanded (GU, lo, hi)) ;
                            assert (isbanded (D,  lo, hi) == ...
                                    isbanded (GD, lo, hi)) ;
                        end
                    end
                end
            end
        end
    end
end

fprintf ('\ngbtest37: all tests passed\n') ;