File: GB_AxB_factory.c

package info (click to toggle)
suitesparse-graphblas 7.4.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 67,112 kB
  • sloc: ansic: 1,072,243; cpp: 8,081; sh: 512; makefile: 503; asm: 369; python: 125; awk: 10
file content (377 lines) | stat: -rw-r--r-- 16,394 bytes parent folder | download | duplicates (3)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
//------------------------------------------------------------------------------
// GB_AxB_factory: switch factory for C=A*B
//------------------------------------------------------------------------------

// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

//------------------------------------------------------------------------------

// This is used by GB_AxB_saxpy3.c and GB_AxB_dot[234].c to create the built-in
// versions of sparse matrix-matrix multiplication.  The #include'ing file
// defines the GB_AxB_WORKER macro, and mult_binop_code, add_binop_code, xcode,
// ycode, and zcode.

// Three 2nd level switch factories are used:

//      GB_AxB_type_factory: handles all semirings where the multiply operator
//          is TxT->T (as is the monoid).

//      GB_AxB_compare_factory: handles all semirings where the multiply
//          operator is TxT -> bool (for the comparators, LT, GT,
//          etc), and where the monoid is bool x bool -> bool.

//      GB_AxB_bitwise_factory: handles all semirings for bitwise operators.

//      GxB_AxB_positional_factory: handles all semirings for positional
//          multiply operators.  Those operators are of the for XxX -> int64,
//          where "X" denotes any type.  No typecasting is needed from the
//          types of A and B.

// If the multiplicative operator is ANY, then it has already been renamed to
// SECOND, prior to using this factory, since that is faster for the
// saxpy-based methods (y is the value of B(k,j), which is loaded less
// frequently from memory than A(i,k)).

// This switch factory is not used to call the ANY_PAIR iso semiring.

ASSERT (mult_binop_code != GB_ANY_binop_code) ;

{
    //--------------------------------------------------------------------------
    // launch the switch factory
    //--------------------------------------------------------------------------

    switch (mult_binop_code)
    {

        //----------------------------------------------------------------------
        case GB_FIRST_binop_code   :    // z = x
        //----------------------------------------------------------------------

            // 61 semirings with FIRST:
            // 50: (min,max,plus,times,any) for 10 non-boolean real
            // 5: (or,and,xor,eq,any) for boolean
            // 6: (plus,times,any) for 2 complex
            #define GB_MNAME _first
            #define GB_COMPLEX
            #include "GB_AxB_type_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_SECOND_binop_code  :    // z = y
        //----------------------------------------------------------------------

            // 61 semirings with SECOND:
            // 50: (min,max,plus,times,any) for 10 real non-boolean
            // 5: (or,and,xor,eq,any) for boolean
            // 6: (plus,times,any) for 2 complex
            #define GB_MNAME _second
            #define GB_COMPLEX
            #include "GB_AxB_type_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_MIN_binop_code     :    // z = min(x,y)
        //----------------------------------------------------------------------

            // 50 semirings: (min,max,plus,times,any) for 10 real non-boolean
            // MIN == TIMES == AND for boolean
            #define GB_NO_BOOLEAN
            #define GB_MNAME _min
            #include "GB_AxB_type_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_MAX_binop_code     :    // z = max(x,y)
        //----------------------------------------------------------------------

            // 50 semirings: (min,max,plus,times,any) for 10 real non-boolean
            // MAX == PLUS == OR for boolean
            #define GB_NO_BOOLEAN
            #define GB_MNAME _max
            #include "GB_AxB_type_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_PLUS_binop_code    :    // z = x + y
        //----------------------------------------------------------------------

            // 56 semirings:
            // 50: (min,max,plus,times,any) for 10 real non-boolean
            // 6: (plus,times,any) for 2 complex types
            // MAX == PLUS == OR for boolean
            #define GB_NO_BOOLEAN
            #define GB_MNAME _plus
            #define GB_COMPLEX
            #include "GB_AxB_type_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_MINUS_binop_code   :    // z = x - y
        //----------------------------------------------------------------------

            // 56 semirings:
            // 50 semirings: (min,max,plus,times,any) for 10 real non-boolean
            // 6: (plus,times,any) for 2 complex types
            // MINUS == RMINUS == NE == ISNE == XOR for boolean
            #define GB_NO_BOOLEAN
            #define GB_MNAME _minus
            #define GB_COMPLEX
            #include "GB_AxB_type_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_RMINUS_binop_code   :    // z = y - x (reverse minus)
        //----------------------------------------------------------------------

            // 56 semirings:
            // 50 semirings: (min,max,plus,times,any) for 10 real non-boolean
            // 6: (plus,times,any) for 2 complex types
            #define GB_NO_BOOLEAN
            #define GB_MNAME _rminus
            #define GB_COMPLEX
            #include "GB_AxB_type_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_TIMES_binop_code   :    // z = x * y
        //----------------------------------------------------------------------

            // 56 semirings:
            // 50 semirings: (min,max,plus,times,any) for 10 real non-boolean
            // 6: (plus,times,any) for 2 complex types
            #define GB_NO_BOOLEAN
            #define GB_MNAME _times
            #define GB_COMPLEX
            #include "GB_AxB_type_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_DIV_binop_code   :      // z = x / y
        //----------------------------------------------------------------------

            // 56 semirings:
            // 50 semirings: (min,max,plus,times,any) for 10 real non-boolean
            // 6: (plus,times,any) for 2 complex types
            // FIRST == DIV for boolean
            #define GB_NO_BOOLEAN
            #define GB_MNAME _div
            #define GB_COMPLEX
            #include "GB_AxB_type_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_RDIV_binop_code   :     // z = y / x (reverse division)
        //----------------------------------------------------------------------

            // 56 semirings:
            // 50 semirings: (min,max,plus,times,any) for 10 real non-boolean
            // 6: (plus,times,any) for 2 complex types
            // SECOND == RDIV for boolean
            #define GB_NO_BOOLEAN
            #define GB_MNAME _rdiv
            #define GB_COMPLEX
            #include "GB_AxB_type_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_EQ_binop_code      :    // z = (x == y)
        //----------------------------------------------------------------------

            // 55 semirings: (and,or,xor,eq,any) * 11 types (all but complex)
            #define GB_MNAME _eq
            #include "GB_AxB_compare_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_NE_binop_code      :    // z = (x != y)
        //----------------------------------------------------------------------

            // 50 semirings: (and,or,xor,eq,any) * (10 real non-boolean types)
            // MINUS == RMINUS == NE == ISNE == XOR for boolean
            #define GB_NO_BOOLEAN
            #define GB_MNAME _ne
            #include "GB_AxB_compare_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_GT_binop_code      :    // z = (x >  y)
        //----------------------------------------------------------------------

            // 55 semirings: (and,or,xor,eq,any) * 11 types (all but complex)
            #define GB_MNAME _gt
            #include "GB_AxB_compare_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_LT_binop_code      :    // z = (x <  y)
        //----------------------------------------------------------------------

            // 55 semirings: (and,or,xor,eq,any) * 11 types (all but complex)
            #define GB_MNAME _lt
            #include "GB_AxB_compare_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_GE_binop_code      :    // z = (x >= y)
        //----------------------------------------------------------------------

            // 55 semirings: (and,or,xor,eq,any) * 11 types (all but complex)
            #define GB_MNAME _ge
            #include "GB_AxB_compare_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_LE_binop_code      :    // z = (x <= y)
        //----------------------------------------------------------------------

            // 55 semirings: (and,or,xor,eq,any) * 11 types (all but complex)
            #define GB_MNAME _le
            #include "GB_AxB_compare_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_PAIR_binop_code   :    // z = 1
        //----------------------------------------------------------------------

            // 13 semirings with PAIR: (not including ANY_PAIR)
            // 12: (plus) for 10 real non-boolean and 2 complex
            // 1: (xor) for boolean
            #define GB_NO_MIN_MAX_ANY_TIMES_MONOIDS
            #define GB_MULT_IS_PAIR_OPERATOR
            #define GB_MNAME _pair
            #define GB_COMPLEX
            #include "GB_AxB_type_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_LOR_binop_code     :    // z = x || y
        //----------------------------------------------------------------------

            // 15 semirings:
            // 10 semirings: plus_lor for 10 real non-boolean types
            // 5 semirings: (lor,land,eq,lxor,any) for boolean
            #define GB_NO_MIN_MAX_ANY_TIMES_MONOIDS
            #define GB_MNAME _lor
            #include "GB_AxB_type_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_LAND_binop_code    :    // z = x && y
        //----------------------------------------------------------------------

            // 15 semirings: same as LOR
            #define GB_NO_MIN_MAX_ANY_TIMES_MONOIDS
            #define GB_MNAME _land
            #include "GB_AxB_type_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_LXOR_binop_code    :    // z = x != y
        //----------------------------------------------------------------------

            // 15 semirings: same as LOR
            #define GB_NO_MIN_MAX_ANY_TIMES_MONOIDS
            #define GB_MNAME _lxor
            #include "GB_AxB_type_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_BOR_binop_code :     // z = (x | y), bitwise or
        //----------------------------------------------------------------------

            // 16 semirings: (bor,band,bxor,bxnor) * (uint8,16,32,64)
            #define GB_MNAME _bor
            #include "GB_AxB_bitwise_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_BAND_binop_code :    // z = (x & y), bitwise and
        //----------------------------------------------------------------------

            // 16 semirings: (bor,band,bxor,bxnor) * (uint8,16,32,64)
            #define GB_MNAME _band
            #include "GB_AxB_bitwise_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_BXOR_binop_code :    // z = (x ^ y), bitwise xor
        //----------------------------------------------------------------------

            // 16 semirings: (bor,band,bxor,bxnor) * (uint8,16,32,64)
            #define GB_MNAME _bxor
            #include "GB_AxB_bitwise_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_BXNOR_binop_code :   // z = ~(x ^ y), bitwise xnor
        //----------------------------------------------------------------------

            // 16 semirings: (bor,band,bxor,bxnor) * (uint8,16,32,64)
            #define GB_MNAME _bxnor
            #include "GB_AxB_bitwise_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_FIRSTI_binop_code   :   // z = first_i(A(i,k),y) == i
        //----------------------------------------------------------------------

            // 10 semirings: (min,max,times,plus,any) * (int32,int64)
            #define GB_MNAME _firsti
            #include "GB_AxB_positional_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_FIRSTI1_binop_code  :   // z = first_i1(A(i,k),y) == i+1
        //----------------------------------------------------------------------

            // 10 semirings: (min,max,times,plus,any) * (int32,int64)
            #define GB_MNAME _firsti1
            #include "GB_AxB_positional_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_FIRSTJ_binop_code   :   // z = first_j(A(i,k),y) == k
        case GB_SECONDI_binop_code  :   // z = second_i(x,B(k,j)) == k
        //----------------------------------------------------------------------

            // 10 semirings: (min,max,times,plus,any) * (int32,int64)
            // FIRSTJ and SECONDI are identical when used in a semiring
            #define GB_MNAME _firstj
            #include "GB_AxB_positional_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_FIRSTJ1_binop_code  :   // z = first_j1(A(i,k),y) == k+1
        case GB_SECONDI1_binop_code :   // z = second_i1(x,B(k,j)) == k+1
        //----------------------------------------------------------------------

            // 10 semirings: (min,max,times,plus,any) * (int32,int64)
            // FIRSTJ1 and SECONDI1 are identical when used in a semiring
            #define GB_MNAME _firstj1
            #include "GB_AxB_positional_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_SECONDJ_binop_code  :   // z = second_j(x,B(i,j)) == j
        //----------------------------------------------------------------------

            // 10 semirings: (min,max,times,plus,any) * (int32,int64)
            #define GB_MNAME _secondj
            #include "GB_AxB_positional_factory.c"
            break ;

        //----------------------------------------------------------------------
        case GB_SECONDJ1_binop_code :   // z = second_j1(x,B(i,j)) == j+1
        //----------------------------------------------------------------------

            // 10 semirings: (min,max,times,plus,any) * (int32,int64)
            #define GB_MNAME _secondj1
            #include "GB_AxB_positional_factory.c"
            break ;

        default: ;
    }
}