1function test129
2%TEST129 test GxB_select (tril and nonzero, hypersparse)
3
4% This is a shorter version of test25
5
6% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
7% SPDX-License-Identifier: Apache-2.0
8
9fprintf ('\ntest129: GxB_select tests (tril and nonzero)\n') ;
10
11[~, ~, ~, ~, ~, select_ops] = GB_spec_opsall ;
12
13rng ('default') ;
14
15if (~ispc)
16    % This test is not done on Windows, since the Complex type is
17    % always the same as the built-in GxB_FC64, and not user-defined.
18    fprintf ('\n---------- Trigger an intentional error (domain mismatch):\n\n') ;
19    GB_builtin_complex_set (0) ;    % use the user-defined Complex type
20    try
21        % this must fail; the scalar thunk cannot be user-defined for tril
22        C = sparse (1i) ;
23        C = GB_mex_select (C, [ ], [ ], 'tril', C, C, [ ]) ;
24        % ack! The call to GB_mex_select was supposed to have failed.
25        ok = false ;
26    catch me
27        % GB_mex_select correctly returned an error
28        fprintf ('Intentional error: %s\n', me.message) ;
29        ok = true ;
30    end
31    assert (ok) ;
32    fprintf ('---------- Domain mismatch error above is expected\n\n') ;
33    GB_builtin_complex_set (1) ;    % use the built-in GxB_FC64 Complex type
34end
35
36m = 10 ;
37n = 6 ;
38dt = struct ('inp0', 'tran') ;
39
40    atype = 'double' ;
41
42    for A_is_hyper = 0:1
43    for A_is_csc   = 0:1
44    for C_is_hyper = 0:1
45
46    for C_is_csc   = 0:1
47    for M_is_hyper = 0:1
48    for M_is_csc   = 0:1
49
50    if (A_is_hyper)
51        ha = 1 ;
52    else
53        ha = 0 ;
54    end
55
56    if (C_is_hyper)
57        hc = 1 ;
58    else
59        hc = 0 ;
60    end
61
62    if (M_is_hyper)
63        hm = 1 ;
64    else
65        hm = 0 ;
66    end
67
68    A = GB_spec_random (m, n, 0.3, 100, atype, A_is_csc, A_is_hyper, ha) ;
69    A.matrix (:,1) = rand (m,1) ;
70    A.pattern (:,1) = true (m,1) ;
71    Cin = GB_spec_random (m, n, 0.3, 100, atype, C_is_csc, C_is_hyper, hc) ;
72    B = GB_spec_random (n, m, 0.3, 100, atype, A_is_csc, A_is_hyper, ha) ;
73    cin = GB_mex_cast (0, atype) ;
74    % Mask = (sprand (m, n, 0.5) ~= 0) ;
75    Mask = GB_random_mask (m, n, 0.5, M_is_csc, M_is_hyper) ;
76    Mask.hyper_switch = hm ;
77
78    fprintf ('.') ;
79
80    for k2 = [ 1 5 ]
81        op = select_ops {k2} ;
82
83        k = sparse (0) ;
84
85            % no mask
86            C1 = GB_spec_select (Cin, [], [], op, A, k, []) ;
87            C2 = GB_mex_select  (Cin, [], [], op, A, k, [], 'test') ;
88            GB_spec_compare (C1, C2) ;
89
90            % no mask, with accum
91            C1 = GB_spec_select (Cin, [], 'plus', op, A, k, []) ;
92            C2 = GB_mex_select  (Cin, [], 'plus', op, A, k, [], 'test') ;
93            GB_spec_compare (C1, C2) ;
94
95            % with mask
96            C1 = GB_spec_select (Cin, Mask, [], op, A, k, []) ;
97            C2 = GB_mex_select  (Cin, Mask, [], op, A, k, [], 'test') ;
98            GB_spec_compare (C1, C2) ;
99
100            % with mask and accum
101            C1 = GB_spec_select (Cin, Mask, 'plus', op, A, k, []) ;
102            C2 = GB_mex_select  (Cin, Mask, 'plus', op, A, k, [], 'test') ;
103            GB_spec_compare (C1, C2) ;
104
105            % no mask, transpose
106            C1 = GB_spec_select (Cin, [], [], op, B, k, dt) ;
107            C2 = GB_mex_select  (Cin, [], [], op, B, k, dt, 'test') ;
108            GB_spec_compare (C1, C2) ;
109
110            % no mask, with accum, transpose
111            C1 = GB_spec_select (Cin, [], 'plus', op, B, k, dt) ;
112            C2 = GB_mex_select  (Cin, [], 'plus', op, B, k, dt, 'test') ;
113            GB_spec_compare (C1, C2) ;
114
115            % with mask, transpose
116            C1 = GB_spec_select (Cin, Mask, [], op, B, k, dt) ;
117            C2 = GB_mex_select  (Cin, Mask, [], op, B, k, dt, 'test') ;
118            GB_spec_compare (C1, C2) ;
119
120            % with mask and accum, transpose
121            C1 = GB_spec_select (Cin, Mask, 'plus', op, B, k, dt) ;
122            C2 = GB_mex_select  (Cin, Mask, 'plus', op, B, k, dt, 'test') ;
123            GB_spec_compare (C1, C2) ;
124
125    end
126
127    end
128    end
129    end
130    end
131    end
132    end
133
134fprintf ('\ntest129: all tests passed\n') ;
135
136
137