1function gbtest96
2%GBTEST96 test GrB.optype
3
4fprintf ('Table of types of binary operators when inputs types are\n') ;
5fprintf ('are mixed (the type of C for C=A+B, for example).\n') ;
6fprintf ('\nLegend:\n') ;
7
8types = gbtest_types ;
9order = [ 3:11 2 1 12:13 ] ;
10for k = order
11    type = types {k} ;
12    fprintf ('%2s : %s\n', gbterse (type), type) ;
13end
14
15fprintf ('\n   : ') ;
16for k2 = order
17    btype = types {k2} ;
18    fprintf ('%2s ', gbterse (btype)) ;
19end
20fprintf ('\n') ;
21
22fprintf ('---:---------------------------------------\n') ;
23
24for k1 = order
25    atype = types {k1} ;
26    fprintf ('%2s : ', gbterse (atype)) ;
27    for k2 = order
28        btype = types {k2} ;
29        ctype = GrB.optype (atype, btype) ;
30        fprintf ('%2s ', gbterse (ctype)) ;
31
32        c2 = GrB.optype (btype, atype) ;
33        assert (isequal (c2, ctype)) ;
34
35        A = GrB (1, atype) ;
36        B = GrB (1, btype) ;
37        c2 = GrB.optype (A, B) ;
38        assert (isequal (c2, ctype)) ;
39
40        if (isequal (atype, 'single complex'))
41            A = complex (single (1)) ;
42        elseif (isequal (atype, 'double complex'))
43            A = complex (double (1)) ;
44        else
45            A = cast (1, atype) ;
46        end
47
48        c2 = GrB.optype (A, B) ;
49        assert (isequal (c2, ctype)) ;
50
51        if (isequal (btype, 'single complex'))
52            B = complex (single (1)) ;
53        elseif (isequal (btype, 'double complex'))
54            B = complex (double (1)) ;
55        else
56            B = cast (1, btype) ;
57        end
58
59        c2 = GrB.optype (A, B) ;
60        assert (isequal (c2, ctype)) ;
61
62    end
63    fprintf ('\n') ;
64end
65
66function s = gbterse(type)
67switch (type)
68    case { 'double' }
69        s = 'd ' ;
70    case { 'single' }
71        s = 's ' ;
72    case { 'logical' }
73        s = 'b ' ;
74    case { 'int8' }
75        s = 'i1' ;
76    case { 'int16' }
77        s = 'i2' ;
78    case { 'int32' }
79        s = 'i4' ;
80    case { 'int64' }
81        s = 'i8' ;
82    case { 'uint8' }
83        s = 'u1' ;
84    case { 'uint16' }
85        s = 'u2' ;
86    case { 'uint32' }
87        s = 'u4' ;
88    case { 'uint64' }
89        s = 'u8' ;
90    case { 'single complex' }
91        s = 'c ' ;
92    case { 'double complex' }
93        s = 'z ' ;
94    otherwise
95        error ('invalid type') ;
96end
97
98