1function test25
2%TEST25 test GxB_select
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7fprintf ('\ntest25: GxB_select tests\n') ;
8
9[~, ~, ~, types, ~, select_ops] = GB_spec_opsall ;
10types = types.all ;
11
12rng ('default') ;
13
14m = 10 ;
15n = 6 ;
16dt = struct ('inp0', 'tran') ;
17
18for k1 = 1:length(types)
19    atype = types {k1} ;
20    fprintf ('%s: ', atype) ;
21
22    for A_is_hyper = 0:1
23    for A_is_csc   = 0:1
24    for C_is_hyper = 0:1
25    for C_is_csc   = 0:1
26    for M_is_hyper = 0:1
27    for M_is_csc   = 0:1
28
29    if (A_is_hyper)
30        ha = 1 ;
31    else
32        ha = 0 ;
33    end
34
35    if (C_is_hyper)
36        hc = 1 ;
37    else
38        hc = 0 ;
39    end
40
41    if (M_is_hyper)
42        hm = 1 ;
43    else
44        hm = 0 ;
45    end
46
47    A = GB_spec_random (m, n, 0.3, 100, atype, A_is_csc, A_is_hyper, ha) ;
48    A.matrix (:,1) = rand (m,1) ;
49    A.pattern (:,1) = true (m,1) ;
50    Cin = GB_spec_random (m, n, 0.3, 100, atype, C_is_csc, C_is_hyper, hc) ;
51    B = GB_spec_random (n, m, 0.3, 100, atype, A_is_csc, A_is_hyper, ha) ;
52    cin = GB_mex_cast (0, atype) ;
53    % Mask = (sprand (m, n, 0.5) ~= 0) ;
54    Mask = GB_random_mask (m, n, 0.5, M_is_csc, M_is_hyper) ;
55    Mask.hyper_switch = hm ;
56
57    fprintf ('.') ;
58
59    for k2 = 1:length(select_ops)
60        op = select_ops {k2} ;
61        % fprintf ('%s ', op) ;
62
63        for k = -m:3:n % Was: [-m:n]
64
65            % no mask
66            C1 = GB_spec_select (Cin, [], [], op, A, k, []) ;
67            C2 = GB_mex_select  (Cin, [], [], op, A, k, [], 'test') ;
68            GB_spec_compare (C1, C2) ;
69
70            % no mask, with accum
71            C1 = GB_spec_select (Cin, [], 'plus', op, A, k, []) ;
72            C2 = GB_mex_select  (Cin, [], 'plus', op, A, k, [], 'test') ;
73            GB_spec_compare (C1, C2) ;
74
75            % with mask
76            C1 = GB_spec_select (Cin, Mask, [], op, A, k, []) ;
77            C2 = GB_mex_select  (Cin, Mask, [], op, A, k, [], 'test') ;
78            GB_spec_compare (C1, C2) ;
79
80            % with mask and accum
81            C1 = GB_spec_select (Cin, Mask, 'plus', op, A, k, []) ;
82            C2 = GB_mex_select  (Cin, Mask, 'plus', op, A, k, [], 'test') ;
83            GB_spec_compare (C1, C2) ;
84
85            % no mask, transpose
86            C1 = GB_spec_select (Cin, [], [], op, B, k, dt) ;
87            C2 = GB_mex_select  (Cin, [], [], op, B, k, dt, 'test') ;
88            GB_spec_compare (C1, C2) ;
89
90            % no mask, with accum, transpose
91            C1 = GB_spec_select (Cin, [], 'plus', op, B, k, dt) ;
92            C2 = GB_mex_select  (Cin, [], 'plus', op, B, k, dt, 'test') ;
93            GB_spec_compare (C1, C2) ;
94
95            % with mask, transpose
96            C1 = GB_spec_select (Cin, Mask, [], op, B, k, dt) ;
97            C2 = GB_mex_select  (Cin, Mask, [], op, B, k, dt, 'test') ;
98            GB_spec_compare (C1, C2) ;
99
100            % with mask and accum, transpose
101            C1 = GB_spec_select (Cin, Mask, 'plus', op, B, k, dt) ;
102            C2 = GB_mex_select  (Cin, Mask, 'plus', op, B, k, dt, 'test') ;
103            GB_spec_compare (C1, C2) ;
104
105        end
106    end
107    end
108    end
109    end
110    end
111    end
112    end
113    fprintf ('\n') ;
114end
115fprintf ('\ntest25: all tests passed\n') ;
116
117
118