1function testc4
2%TESTC4 test complex extractElement and setElement
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7rng ('default') ;
8
9seed = 1 ;
10for m = [1 5 10 100]
11    for n = [1 5 10 100]
12        seed = seed + 1 ;
13        A = GB_mex_random (m, n, 10*(m+n), 1, seed) ;
14
15        ktuples = 400 ;
16
17        for trials = 1:10
18
19            J0 = irand (0, n-1, ktuples, 1) ;
20            I0 = irand (0, m-1, ktuples, 1) ;
21            J = double (J0+1) ;
22            I = double (I0+1) ;
23
24            x1 = GB_mex_Matrix_extractElement (A, I0, J0)  ;
25            x2 = complex (zeros (ktuples,1)) ;
26            for k = 1:ktuples
27                x2 (k) = A (I (k), J (k)) ;
28            end
29            assert (isequal (x1, x2))
30
31            if (n == 1)
32                x1 = GB_mex_Vector_extractElement (A, I0)  ;
33                assert (isequal (x1, x2))
34            end
35        end
36    end
37end
38fprintf ('All complex extractElement x = A(i,j) tests passed\n') ;
39
40
41seed = 1 ;
42for m = [1 5 10 100]
43    for n = [1 5 10 100]
44        seed = seed + 1 ;
45        A = GB_mex_random (m, n, 10*(m+n), 1, seed) ;
46
47        ktuples = 40 ;
48
49        for trials = 1:10
50
51            J0 = irand (0, n-1, ktuples, 1) ;
52            I0 = irand (0, m-1, ktuples, 1) ;
53            J = double (J0+1) ;
54            I = double (I0+1) ;
55            X = complex (rand (ktuples,1) + 1i*rand(ktuples,1)) ;
56
57            A1 = GB_mex_setElement (A, I0, J0, X)  ;
58
59            A2 = A ;
60            for k = 1:ktuples
61                A2 (I (k), J (k)) = X (k) ;
62            end
63            assert (isequal (A1.matrix, A2))
64
65        end
66    end
67end
68fprintf ('All complex setElement A(i,j) = x tests passed\n') ;
69
70fprintf ('\ntestc4: all tests passed\n') ;
71
72