1function testc6
2%TESTC6 test complex apply
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7rng 'default'
8
9[complex_binary complex_unary] = GB_user_opsall ;
10
11dr  = struct ('outp', 'replace') ;
12dtr = struct ('outp', 'replace', 'inp0', 'tran') ;
13
14seed = 1 ;
15for m = [1 5 10 50 100 ]
16    for n = [ 1 5 10  50 100 ]
17
18        seed = seed + 1 ;
19        A = GB_mex_random (m, n, 10*(m+n), 1, seed) ;
20        D = GB_mex_random (n, m, 10*(m+n), 1, seed) ;
21        seed = seed + 1 ;
22        C = GB_mex_random (m, n, 10*(m+n), 1, seed) ;
23        seed = seed + 1 ;
24        B = GB_mex_random (m, n, 10*(m+n), 0, seed) ;
25        E = GB_mex_random (n, m, 10*(m+n), 0, seed) ;
26        a = pi + 1i ;
27        b = 42 ;
28
29        % test unary ops with complex x,z
30        for k = 1:6
31            op = complex_unary {k} ;
32            C1 = GB_mex_op (op, a, '',1) ;
33            [C2 tol] = GB_user_op (op, a) ;
34            GB_complex_compare (C1, C2, tol) ;
35
36            C1 = GB_mex_apply (C, [], [], op, A, dr) ;
37            [i j x1] = find (C1.matrix) ;
38            x1 = complex (x1) ;
39            [i j s] = find (A) ;
40            x2 = GB_user_op (op, complex (s)) ;
41            x2 = complex (x2) ;
42            GB_complex_compare (x1, x2, tol) ;
43        end
44
45        % test unary ops with complex x,z, array transposed
46        for k = 1:6
47            op = complex_unary {k} ;
48            C1 = GB_mex_apply (C, [], [], op, D, dtr) ;
49            [i j x1] = find (C1.matrix) ;
50            x1 = complex (x1) ;
51            [i j s] = find (D.') ;
52            x2 = GB_user_op (op, complex (s)) ;
53            x2 = complex (x2) ;
54            GB_complex_compare (x1, x2, true) ;
55        end
56
57        % test unary ops with complex x, real z
58        for k = 7:length(complex_unary)
59            op = complex_unary {k} ;
60            C1 = GB_mex_op (op, a, '',1) ;
61            [C2 tol] = GB_user_op (op, a) ;
62            GB_complex_compare (C1, C2, tol) ;
63
64            C1 = GB_mex_apply (B, [], [], op, A, dr) ;
65            % [i j x1] = find (sparse (C1.matrix)) ;
66            [i j x1] = GB_mex_extractTuples (C1.matrix) ;
67            x1 = complex (x1) ;
68            % [i j s] = find (sparse (A)) ;
69            [i j s] = GB_mex_extractTuples (A) ;
70            x2 = GB_user_op (op, complex (s)) ;
71            x2 = complex (x2) ;
72            GB_complex_compare (x1, x2, tol) ;
73        end
74
75        % test unary ops with complex x, real z, array transposed
76        for k = 8:length(complex_unary)
77            op = complex_unary {k} ;
78            C1 = GB_mex_apply (B, [], [], op, D, dtr) ;
79            % [i j x1] = find (C1.matrix) ;
80            [i j x1] = GB_mex_extractTuples (C1.matrix) ;
81            x1 = complex (x1) ;
82            % [i j s] = find (D.') ;
83            [i j s] = GB_mex_extractTuples (D.') ;
84            x2 = GB_user_op (op, complex (s)) ;
85            x2 = complex (x2) ;
86            GB_complex_compare (x1, x2, true) ;
87        end
88
89    end
90end
91
92fprintf ('testc6: all complex apply C<Mask>=op(A) tests passed\n') ;
93
94