File: testca.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 (112 lines) | stat: -rw-r--r-- 3,722 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
function testca(use_builtin)
%TESTCA test complex mxm, mxv, and vxm

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

if (nargin < 1)
    use_builtin = true ;
end
GB_builtin_complex_set (use_builtin) ;

fprintf ('testca: test complex mxm, mxv, and vxm\n') ;
rng ('default') ;
dnn = struct ;
dnt = struct ('inp1', 'tran') ;
dtn = struct ('inp0', 'tran') ;
dtt = struct ('inp0', 'tran', 'inp1', 'tran') ;

algos = {'auto', 'gustavson', 'dot', 'hash', 'saxpy'} ;

for kk = 1:length(algos)
dnn.algo = algos {kk} ;
dnt.algo = algos {kk} ;
dtn.algo = algos {kk} ;
dtt.algo = algos {kk} ;

semiring.add = 'plus' ;
semiring.multiply = 'times' ;
semiring.class = 'double complex' ;

seed = 1 ;
for m = [1 5 10 100]
    for n = [1 5 10 100]
        for k = [1 5 10 100]
            fprintf ('.') ;
            for trial = 1:31

                A = GB_mex_random (m, k, 10*(m+k), 1, seed) ; seed = seed + 1 ;
                B = GB_mex_random (k, n, 10*(k+n), 1, seed) ; seed = seed + 1 ;
                S = GB_mex_complex (sparse (m,n)) ;
                D = GB_mex_random (m, n, 10*(m+n), 1, seed) ; seed = seed + 1 ;

                if (trial == 31)
                    A (:,1) = 1i * rand (m,1) ;
                    B (1,:) = 1i * rand (1,n) ;
                    if (k > 1)
                        A (:,2) = 0 ;
                        A (1,2) = 1i ;
                        B (2,:) = 0 ;
                        B (2,1) = 1i ;
                    end
                end

                C = A*B ;
                C2 = GB_mex_mxm (S, [], [], semiring, A, B, dnn) ;
                assert (isequal_roundoff (C, C2.matrix)) ;

                if (n == 1)
                    C2 = GB_mex_mxv (S, [], [], semiring, A, B, dnn) ;
                    assert (isequal_roundoff (C, C2.matrix)) ;
                    C2 = GB_mex_vxm (S, [], [], semiring, B, A.', dnn) ;
                    assert (isequal_roundoff (C, C2.matrix)) ;
                end

                if (m > 1 && n > 1)
                    t = min (m,n) ;
                    Eye = speye (m,n) ;
                    C = A*B ;
                    C2 = GB_mex_mxm (S, Eye, [], semiring, A, B, dnn) ;
                    d = full (diag (C)) ;
                    d = GB_mex_complex (sparse (1:t, 1:t, d, m, n)) ;
                    assert (isequal_roundoff (d, C2.matrix)) ;
                end

                C = D + A*B ;
                C2 = GB_mex_mxm (D, [], 'plus', semiring, A, B, dnn) ;
                assert (isequal_roundoff (C, C2.matrix)) ;

                if (n == 1)
                    C2 = GB_mex_mxv (D, [], 'plus', semiring, A, B, dnn) ;
                    assert (isequal_roundoff (C, C2.matrix)) ;
                end

                C2 = GB_mex_mxm (D, [], 'plus', semiring, A, B.', dnt)  ;
                assert (isequal_roundoff (C, C2.matrix)) ;

                C2 = GB_mex_mxm (D, [], 'plus', semiring, A.', B, dtn)  ;
                assert (isequal_roundoff (C, C2.matrix)) ;

                if (n == 1)
                    C2 = GB_mex_mxv (D, [], 'plus', semiring, A.', B, dtn)  ;
                    assert (isequal_roundoff (C, C2.matrix)) ;
                end

                C2 = GB_mex_mxm (D, [], 'plus', semiring, A.', B.', dtt)  ;
                assert (isequal_roundoff (C, C2.matrix)) ;

                M = spones (sprand (m, n, 0.5)) ;
                C2 = GB_mex_mxm (S, M, [ ], semiring, A.', B.', dtt)  ;
                C = (A*B) .* M ;
                assert (isequal_roundoff (C, C2.matrix)) ;

            end
        end
    end
end
end

fprintf ('\ntestca: all complex mxm, mxv, vxm tests passed\n') ;

GB_builtin_complex_set (true) ;