1function test153
2%TEST153 list all possible semirings
3%
4% Lists all possible semirings that can be constructed from built-in operators.
5
6% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
7% SPDX-License-Identifier: Apache-2.0
8
9[binops, unary_ops, add_ops, types, semirings, selops] = GB_spec_opsall ;
10
11n = 0 ;
12types = types.all ;
13binops = binops.all ;
14
15for kadd = 1:length (add_ops)
16    for kadd_types = 1:length (types)
17        add.opname = add_ops {kadd} ;
18        add.optype = types {kadd_types} ;
19
20        try
21            [opadd, t, ztype, xtype, ytype] = GB_spec_operator (add) ;
22            id = GB_spec_identity (add) ;
23        catch
24            continue ;
25        end
26
27        if (~isequal (opadd, add.opname))
28            % ignore renames
29            continue ;
30        end
31
32        if (~isequal (ztype, xtype))
33            continue ;
34        end
35
36        if (~isequal (ztype, ytype))
37            continue ;
38        end
39
40        fprintf ('\n======================= monoid %s.%s:\n', opadd, ztype) ;
41
42        n2 = 0 ;
43        for kmult = 1:length (binops)
44            for kmult_types = 1:length (types)
45
46                mult.opname = binops {kmult} ;
47                mult.optype = types {kmult_types} ;
48
49                try
50                    [opmult, t2, z2, xtype, y] = GB_spec_operator (mult) ;
51                catch
52                    continue ;
53                end
54
55                if (~isequal (opmult, mult.opname))
56                    % ignore renames
57                    continue ;
58                end
59
60                if (isequal (z2, ztype))
61                    n2 = n2+1 ;
62                    fprintf ('    %s.%s.%s\n', opadd, opmult, xtype) ;
63                end
64            end
65        end
66
67        fprintf ('    semirings with %s.%s: %d\n', opadd, ztype, n2) ;
68        n = n + n2 ;
69    end
70end
71
72fprintf ('total unique semirings: %d\n', n) ;
73
74