File: test151.m

package info (click to toggle)
suitesparse 1%3A5.8.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 152,716 kB
  • sloc: ansic: 774,385; cpp: 24,213; makefile: 6,310; fortran: 1,927; java: 1,826; csh: 1,686; ruby: 725; sh: 535; perl: 225; python: 209; sed: 164; awk: 60
file content (104 lines) | stat: -rw-r--r-- 3,450 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
function test151
%TEST151 test bitwise operators

% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2020, All Rights
% Reserved. http://suitesparse.com.  See GraphBLAS/Doc/License.txt.

fprintf ('test151: test bitwise operators\n') ;

[binops, ~, ~, types, ~, ~,] = GB_spec_opsall ;
types = types.int ;
ops2 = binops.int ;

int_nbits = [ 8, 16, 32, 64, 8, 16, 32, 64 ] ;

rng ('default') ;
Cin = sparse (4,4) ;
C10 = sparse (10,10) ;

for k = 1:8

    type = types {k} ;
    nbits = int_nbits (k) ;
    fprintf ('\n%s', type) ;

    for trial = 1:40
        fprintf ('.') ;

        % dense case

        imax = double (intmax (type) / 4) ;
        A = GB_mex_cast (imax * rand (4), type) ;
        B = GB_mex_cast ((nbits-1) * rand (4), type) + 1 ;
        clear A2 ; A2.matrix = sparse (double (A)) ; A2.class = type ;
        clear B2 ; B2.matrix = sparse (double (B)) ; B2.class = type ;
        A2.pattern = logical (spones (A)) ;
        B2.pattern = logical (spones (B)) ;

        for j = 1:length (ops2)
            opname = ops2 {j} ;
            % C1 = bitop (A, B) ;
            op.opname = opname ; op.optype = type ;

            if (isequal (opname, 'bitshift') || isequal (opname, 'bshift'))
                B2.class = 'int8' ;
            else
                B2.class = type ;
            end

            C1 = GB_spec_Matrix_eWiseMult(Cin, [ ], [ ], op, A2, B2, [ ]) ;
            C2 = GB_mex_Matrix_eWiseMult (Cin, [ ], [ ], op, A2, B2, [ ]) ;
            GB_spec_compare (C1, C2) ;
            C1 = GB_spec_Matrix_eWiseAdd (Cin, [ ], [ ], op, A2, B2, [ ]) ;
            C2 = GB_mex_Matrix_eWiseAdd  (Cin, [ ], [ ], op, A2, B2, [ ]) ;
            GB_spec_compare (C1, C2) ;
        end

        % C1 = bitcmp (A) ;
        op.opname = 'bitnot' ; op.optype = type ;
        C1 = GB_spec_apply(Cin, [ ], [ ], op, A2, [ ]) ;
        C2 = GB_mex_apply (Cin, [ ], [ ], op, A2, [ ]) ;
        GB_spec_compare (C1, C2) ;

        % sparse case

        A = sprand (10, 10, 0.5) * imax ;
        Afull = GB_mex_cast (full (A), type) ;
        % B ranges in value from 0 to 8
        B = round (sprand (10, 10, 0.5) * nbits) ;
        Bfull = GB_mex_cast (full (B), type) ;
        clear A2 ; A2.matrix = sparse (double (Afull)) ; A2.class = type ;
        clear B2 ; B2.matrix = sparse (double (Bfull)) ; B2.class = type ;
        A2.pattern = logical (spones (Afull)) ;
        B2.pattern = logical (spones (Bfull)) ;

        for j = 1:length (ops2)
            opname = ops2 {j} ;
            % C1 = bitop (A, B) ;
            op.opname = opname ; op.optype = type ;

            if (isequal (opname, 'bitshift') || isequal (opname, 'bshift'))
                B2.class = 'int8' ;
            else
                B2.class = type ;
            end

            C1 = GB_spec_Matrix_eWiseMult(C10, [ ], [ ], op, A2, B2, [ ]) ;
            C2 = GB_mex_Matrix_eWiseMult (C10, [ ], [ ], op, A2, B2, [ ]) ;
            GB_spec_compare (C1, C2) ;
            C1 = GB_spec_Matrix_eWiseAdd (C10, [ ], [ ], op, A2, B2, [ ]) ;
            C2 = GB_mex_Matrix_eWiseAdd  (C10, [ ], [ ], op, A2, B2, [ ]) ;
            GB_spec_compare (C1, C2) ;
        end

        % C1 = bitcmp (Afull) ;
        op.opname = 'bitnot' ; op.optype = type ;
        C1 = GB_spec_apply(C10, [ ], [ ], op, A2, [ ]) ;
        C2 = GB_mex_apply (C10, [ ], [ ], op, A2, [ ]) ;
        GB_spec_compare (C1, C2) ;

    end
end

fprintf ('\ntest151: all tests passed\n') ;