File: testc1.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 (107 lines) | stat: -rw-r--r-- 3,027 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
function testc1(use_builtin)
%TESTC1 test complex operators

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

rng 'default'

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

A = sparse (rand (2) + 1i * rand (2))  ;
C = GB_mex_dump (A,0) ;
GB_spec_compare (C, A) ;

B = sparse (rand (2) + 1i * rand (2))  ;

A = full (A) ;
B = full (B) ;

C1 = GB_mex_op ('plus', A, B, 1) ;
C2 = A+B ;

assert (isequal (C1,C2)) ;

E = rand (2) ;
F = rand (2) ;

C1 = GB_mex_op ('complex', E, F, 1) ;
C2 = complex (E,F) ;
assert (isequal (C1,C2)) ;

[complex_binary complex_unary] = GB_user_opsall ;

A (2,1) = B (2,1) ;

% create some complex test matrices

for m = [1 5 10 50 100 ]
    for n = [ 1 5 10  50 100 ]

        for akind = 1:5
            switch (akind)
                case 1
                    A = complex (zeros (m,n), 0) ;
                case 2
                    A = complex (ones (m,n), 0) ;
                case 3
                    A = complex (-ones (m,n), ones(m,n)) ;
                case 4
                    x = full (sprand(m,n,0.3)) ;
                    y = full (sprand(m,n,0.3)) ;
                    A = complex (x,y) ;
                case 5
                    A = complex (rand (m,n), rand (m,n)) ;
                end

            % test unary ops with complex x
            for k = 1:length (complex_unary)
                op = complex_unary {k} ;
                C1 = GB_mex_op (op, A, '',1) ;
                [C2 tol] = GB_user_op (op, A) ;
                GB_complex_compare (C1, C2, tol) ;
            end

            for bkind = 1:6
                switch (bkind)
                    case 1
                        B = complex (zeros (m,n), 0) ;
                    case 2
                        B = complex (ones (m,n), 0) ;
                    case 3
                        B = complex (-ones (m,n), ones(m,n)) ;
                    case 4
                        x = full (sprand(m,n,0.3)) ;
                        y = full (sprand(m,n,0.3)) ;
                        B = complex (x,y) ;
                    case 5
                        B = complex (rand (m,n), rand (m,n)) ;
                    case 6
                        B = A ;
                    end

                % test all but the last one, 'complex', which requires
                % x,y real
                for k = 1:length (complex_binary)-1
                    op = complex_binary {k} ;
                    C1 = GB_mex_op (op, A, B, 1) ;
                    [C2 tol] = GB_user_op (op, A, B) ;
                    GB_complex_compare (C1, C2, tol) ;
                end

                % test complex(A,B)
                C1 = GB_mex_op  ('complex', real (A), real (B), 1) ;
                C2 = GB_user_op ('complex', real (A), real (B)) ;
                assert (isequal (C1, C2)) 

            end
        end
    end
end

fprintf ('testc1: all complex operator tests passed\n') ;

GB_builtin_complex_set (true) ;