1function test11
2%TEST11 test GrB_*_extractTuples
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7[~, ~, ~, types, ~, ~] = GB_spec_opsall ;
8types = types.all ;
9
10fprintf ('\n------------ testing GrB_extractTuples') ;
11
12% type of the output X
13for k1 = 1:length (types)
14    xtype = types {k1}  ;
15    fprintf ('\n%-14s ', xtype) ;
16
17    % type of the matrix A
18    for k2 = 1:length (types)
19        atype = types {k2}  ;
20
21        % create a matrix
22        fprintf ('.') ;
23        for m = [1 10 25]
24            for n = [1 10 25]
25                clear A
26                A = GB_spec_random (m, n, 0.1, 32, atype) ;
27
28                clear B
29                B = GB_spec_random (m*n, 1, 0.1, 32, atype) ;
30
31                for A_is_hyper = 0:1
32                for A_is_csc   = 0:1
33                A.is_hyper = A_is_hyper ;
34                A.is_csc   = A_is_csc   ;
35
36                [I1, J1, X1] = GB_mex_extractTuples  (A, xtype) ;
37                [I2, J2, X2] = GB_spec_extractTuples (A, xtype) ;
38
39                % If A is CSR, the extraction returns tuples in row major
40                % order, but the MATLAB GB_spec_extractTuples always returns
41                % the tuples in column major order.  Either way is fine since
42                % the order does not matter.
43
44                [~,p1] = sortrows ([I1 J1]) ;
45                I1 = I1 (p1) ;
46                J1 = J1 (p1) ;
47                X1 = X1 (p1) ;
48
49                [~,p2] = sortrows ([I2 J2]) ;
50                I2 = I2 (p2) ;
51                J2 = J2 (p2) ;
52                X2 = X2 (p2) ;
53
54                assert (isequal (I1, I2)) ;
55                assert (isequal (J1, J2)) ;
56                assert (isequal (X1, X2)) ;
57
58                end
59                end
60
61                [I1, J1, X1] = GB_mex_extractTuples  (B, xtype) ;
62                [I2, J2, X2] = GB_spec_extractTuples (B, xtype) ;
63
64                assert (isequal (I1, I2)) ;
65                assert (isequal (J1, J2)) ;
66                assert (isequal (X1, X2)) ;
67
68            end
69        end
70    end
71end
72
73fprintf ('\ntest11: all tests passed\n') ;
74
75