1function test179
2%TEST179 bitmap select
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7fprintf ('test179: --------------------------------- bitmap select\n') ;
8
9ops = { 'nonzero',  'eq_zero', 'ne_thunk', 'eq_thunk' } ;
10
11n = 20 ;
12rng ('default') ;
13
14Cin = GB_spec_random (n, n, 0.5, 1, 'double complex') ;
15A = GB_spec_random (n, n, 0.5, 1, 'double complex') ;
16scalar = 3+1i ;
17A.matrix  (2:3,2:4) = scalar ;
18A.pattern (2:3,2:4) = true ;
19
20for builtin = 0:1
21    GB_builtin_complex_set (builtin) ;
22    for sparsity_control = [1 2 4]
23        Cin.sparsity = sparsity_control ;
24        A.sparsity = sparsity_control ;
25        for k = 1:length (ops)
26            op = ops {k} ;
27            C1 = GB_spec_select (Cin, [], [], op, A, scalar, []) ;
28            C2 = GB_mex_select  (Cin, [], [], op, A, scalar, []) ;
29            GB_spec_compare (C1, C2) ;
30        end
31    end
32end
33
34% try a user-defined selectop
35Cin = GB_spec_random (n, n, 0.5, 1, 'double') ;
36A = GB_spec_random (n, n, 0.5, 1, 'double') ;
37A.matrix  (2:3,2:4) = nan ;
38A.pattern (2:3,2:4) = true ;
39for sparsity_control = [1 2 4]
40    Cin.sparsity = sparsity_control ;
41    A.sparsity = sparsity_control ;
42    C1 = GB_spec_select (Cin, [], [], 'isnan', A, 0, []) ;
43    C2 = GB_mex_select  (Cin, [], [], 'isnan', A) ;
44    GB_spec_compare (C1, C2) ;
45end
46
47fprintf ('\ntest179: all tests passed\n') ;
48
49