File: testc6.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 (99 lines) | stat: -rw-r--r-- 3,196 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
function testc6(use_builtin)
%TESTC6 test complex apply

% 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) ;

[complex_binary complex_unary] = GB_user_opsall ;

dr  = struct ('outp', 'replace') ;
dtr = struct ('outp', 'replace', 'inp0', 'tran') ;

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

        seed = seed + 1 ;
        A = GB_mex_random (m, n, 10*(m+n), 1, seed) ;
        D = GB_mex_random (n, m, 10*(m+n), 1, seed) ;
        seed = seed + 1 ;
        C = GB_mex_random (m, n, 10*(m+n), 1, seed) ;
        seed = seed + 1 ;
        B = GB_mex_random (m, n, 10*(m+n), 0, seed) ;
        E = GB_mex_random (n, m, 10*(m+n), 0, seed) ;
        a = pi + 1i ;
        b = 42 ;

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

            C1 = GB_mex_apply (C, [], [], op, A, dr) ;
            [i j x1] = find (C1.matrix) ;
            x1 = complex (x1) ;
            [i j s] = find (A) ;
            x2 = GB_user_op (op, complex (s)) ;
            x2 = complex (x2) ;
            GB_complex_compare (x1, x2, tol) ;
        end

        % test unary ops with complex x,z, array transposed
        for k = 1:6
            op = complex_unary {k} ;
            C1 = GB_mex_apply (C, [], [], op, D, dtr) ;
            [i j x1] = find (C1.matrix) ;
            x1 = complex (x1) ;
            [i j s] = find (D.') ;
            x2 = GB_user_op (op, complex (s)) ;
            x2 = complex (x2) ;
            GB_complex_compare (x1, x2, true) ;
        end

        % test unary ops with complex x, real z
        for k = 7: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) ;

            C1 = GB_mex_apply (B, [], [], op, A, dr) ;
            % [i j x1] = find (sparse (C1.matrix)) ;
            [i j x1] = GB_mex_extractTuples (C1.matrix) ;
            x1 = complex (x1) ;
            % [i j s] = find (sparse (A)) ;
            [i j s] = GB_mex_extractTuples (A) ;
            x2 = GB_user_op (op, complex (s)) ;
            x2 = complex (x2) ;
            GB_complex_compare (x1, x2, tol) ;
        end

        % test unary ops with complex x, real z, array transposed
        for k = 8:length(complex_unary)
            op = complex_unary {k} ;
            C1 = GB_mex_apply (B, [], [], op, D, dtr) ;
            % [i j x1] = find (C1.matrix) ;
            [i j x1] = GB_mex_extractTuples (C1.matrix) ;
            x1 = complex (x1) ;
            % [i j s] = find (D.') ;
            [i j s] = GB_mex_extractTuples (D.') ;
            x2 = GB_user_op (op, complex (s)) ;
            x2 = complex (x2) ;
            GB_complex_compare (x1, x2, true) ;
        end

    end
end

fprintf ('testc6: all complex apply C<Mask>=op(A) tests passed\n') ;

GB_builtin_complex_set (true) ;