1function testc3
2%TESTC3 test complex GrB_extract
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7rng ('default') ;
8
9d = struct ('outp', 'replace') ;
10seed = 1 ;
11for m = [1 5 10 100]
12    for n = [1 5 10 100]
13        seed = seed + 1 ;
14        A = GB_mex_random (m, n, 10*(m+n), 1, seed) ;
15        for trials = 1:10
16            j = randperm (n, 1) ;
17            j0 = uint64 (j-1) ;
18            w = GB_mex_complex (sprandn (m,1,0.1) + 1i*sprandn(m,1,0.1)) ;
19
20            x1 = GB_mex_Col_extract (w, [],[], A, [], j0, d) ;
21            x2 = A (:,j) ;
22            assert (isequal (x1.matrix, x2))
23
24            x1 = GB_mex_Col_extract (w, [],'plus', A, [], j0, []) ;
25            x2 = w + A (:,j) ;
26            assert (isequal (x1.matrix, x2))
27
28            if (m > 2)
29                I = 1:(m/2) ;
30                I0 = uint64 (I-1) ;
31                wi = GB_mex_complex (w (I)) ;
32
33                x1 = GB_mex_Col_extract (wi, [],[], A, I0, j0, d) ;
34                x2 = A (I,j) ;
35                assert (isequal (x1.matrix, x2))
36
37                x1 = GB_mex_Col_extract (wi, [],'plus', A, I0, j0, d) ;
38                x2 = GB_mex_complex (wi + A (I,j)) ;
39                assert (isequal (x1.matrix, x2))
40
41            end
42        end
43    end
44end
45fprintf ('All complex col extract w = A(:,j) tests passed\n') ;
46
47
48seed = 1 ;
49for m = [1 5 10 100]
50    for n = [1 5 10 100]
51        seed = seed + 1 ;
52        A = GB_mex_random (m, n, 10*(m+n), 1, seed) ;
53        C = GB_mex_complex (sprandn (m,n,0.1) + 1i*sprandn(m,n,0.1)) ;
54        S = GB_mex_complex (sparse (m,n)) ;
55        for trials = 1:10
56
57            J = randperm (n, 1+floor(n/2)) ;
58            I = randperm (m, 1+floor(m/2)) ;
59            J0 = uint64 (J-1) ;
60            I0 = uint64 (I-1) ;
61
62            x1 = GB_mex_Matrix_extract (S, [],[], A, [], [], []) ;
63            x2 = A ;
64            assert (isequal (x1.matrix, x2))
65
66            if (n == 1)
67                x1 = GB_mex_Vector_extract (S, [],[], A, [], []) ;
68                assert (isequal (x1.matrix, x2))
69            end
70
71            Sij = GB_mex_complex (S (I,J)) ;
72
73            x1 = GB_mex_Matrix_extract (Sij, [],[], A, I0, J0, []) ;
74            x2 = GB_mex_complex (A (I,J)) ;
75            assert (isequal (x1.matrix, x2))
76
77            if (n == 1)
78                x1 = GB_mex_Vector_extract (Sij, [],[], A, I0, []) ;
79                assert (isequal (x1.matrix, x2))
80            end
81
82            Cij = GB_mex_complex (C (I,J)) ;
83
84            x1 = GB_mex_Matrix_extract (Cij, [],'plus', A, I0, J0, []) ;
85            x2 = GB_mex_complex (Cij + A (I,J)) ;
86            assert (isequal (x1.matrix, x2))
87
88            if (n == 1)
89                x1 = GB_mex_Vector_extract (Cij, [],'plus', A, I0, []) ;
90                assert (isequal (x1.matrix, x2))
91            end
92
93        end
94    end
95end
96fprintf ('All complex extract C = A(I,J) tests passed\n') ;
97
98fprintf ('\ntestc3: all tests passed\n') ;
99
100