1function test151b
2%TEST151B test bitshift operators
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7fprintf ('test151b: test bshift operator\n') ;
8
9[binops, ~, ~, types, ~, ~,] = GB_spec_opsall ;
10types = types.int ;
11ops2 = { 'bshift' } ;
12
13int_nbits = [ 8, 16, 32, 64, 8, 16, 32, 64 ] ;
14
15rng ('default') ;
16Cin = sparse (4,4) ;
17C10 = sparse (10,10) ;
18desc.mask = 'complement' ;
19
20for k = 1:8
21
22    type = types {k} ;
23    nbits = int_nbits (k) ;
24    fprintf ('\n%s', type) ;
25
26    for trial = 1:4
27        fprintf ('.') ;
28
29        imax = double (intmax (type) / 4) ;
30        A = GB_mex_cast (imax * rand (4), type) ;
31        B = GB_mex_cast ((nbits-1) * rand (4), type) + 1 ;
32        clear A2 ; A2.matrix = sparse (double (A)) ; A2.class = type ;
33        clear B2 ; B2.matrix = sparse (double (B)) ; B2.class = 'int8' ;
34        A2.pattern = logical (spones (A)) ;
35        B2.pattern = logical (spones (B)) ;
36        M = sparse (mod (magic (4), 2)) ;
37        clear M2 ; M2.matrix = M ; M2.class = 'logical' ;
38
39        for A_sparsity = [1 2 4 8]
40        for B_sparsity = [1 2 4 8]
41        for M_sparsity = [1 2 4 8]
42        A2.sparsity = A_sparsity ;
43        B2.sparsity = B_sparsity ;
44        M2.sparsity = M_sparsity ;
45
46        for j = 1:length (ops2)
47            opname = ops2 {j} ;
48            % C1 = bitop (A, B) ;
49            op.opname = opname ; op.optype = type ;
50
51            C1 = GB_spec_Matrix_eWiseMult(Cin, [ ], [ ], op, A2, B2, [ ]) ;
52            C2 = GB_mex_Matrix_eWiseMult (Cin, [ ], [ ], op, A2, B2, [ ]) ;
53            GB_spec_compare (C1, C2) ;
54            C1 = GB_spec_Matrix_eWiseAdd (Cin, [ ], [ ], op, A2, B2, [ ]) ;
55            C2 = GB_mex_Matrix_eWiseAdd  (Cin, [ ], [ ], op, A2, B2, [ ]) ;
56            GB_spec_compare (C1, C2) ;
57
58            C1 = GB_spec_Matrix_eWiseMult(Cin, M2, [ ], op, A2, B2, [ ]) ;
59            C2 = GB_mex_Matrix_eWiseMult (Cin, M2, [ ], op, A2, B2, [ ]) ;
60            GB_spec_compare (C1, C2) ;
61            C1 = GB_spec_Matrix_eWiseAdd (Cin, M2, [ ], op, A2, B2, [ ]) ;
62            C2 = GB_mex_Matrix_eWiseAdd  (Cin, M2, [ ], op, A2, B2, [ ]) ;
63            GB_spec_compare (C1, C2) ;
64
65            C1 = GB_spec_Matrix_eWiseMult(Cin, M2, [ ], op, A2, B2, desc) ;
66            C2 = GB_mex_Matrix_eWiseMult (Cin, M2, [ ], op, A2, B2, desc) ;
67            GB_spec_compare (C1, C2) ;
68            C1 = GB_spec_Matrix_eWiseAdd (Cin, M2, [ ], op, A2, B2, desc) ;
69            C2 = GB_mex_Matrix_eWiseAdd  (Cin, M2, [ ], op, A2, B2, desc) ;
70            GB_spec_compare (C1, C2) ;
71
72        end
73        end
74        end
75        end
76    end
77end
78
79fprintf ('\ntest151b: all tests passed\n') ;
80
81