1function [binops unary_ops add_ops types semirings selops] = GB_spec_opsall 2%GB_SPEC_OPSALL return a list of all operators, types, and semirings 3% 4% [binops unary_ops add_ops types semirings select_ops] = GB_spec_opsall 5 6% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 7% SPDX-License-Identifier: Apache-2.0 8 9%------------------------------------------------------------------------------- 10% types 11%------------------------------------------------------------------------------- 12 13% all 13 built-in types 14types.all = { 15'logical', ... 16'int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64', ... 17'single', 'double', 'single complex', 'double complex' } ; 18 19% all but complex 20types.real = { 21'logical', ... 22'int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64', ... 23'single', 'double' } ; 24 25% integer types 26types.int = { 27'int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64' } ; 28 29% floating-point types 30types.float = { 'single', 'double', 'single complex', 'double complex'} ; 31 32% floating-point real 33types.fpreal = { 'single', 'double' } ; 34 35% complex 36types.complex = { 'single complex', 'double complex'} ; 37 38%------------------------------------------------------------------------------- 39% binary ops 40%------------------------------------------------------------------------------- 41 42% binary operators for all 13 types 43binops.alltypes = { 44'first', % z = x 45'second', % z = y 46'pair', % z = 1 47'plus', % z = x + y 48'minus', % z = x - y 49'rminus', % z = y - x 50'times', % z = x * y 51'div', % z = x / y 52'rdiv', % z = y / x 53'iseq', % z = (x == y) 54'isne', % z = (x != y) 55'eq', % z = (x == y) 56'ne', % z = (x != y) 57'pow', % z = x.^y 58'any'}' ; % z = any(x,y) 59 60% binary operators for 11 types (all but complex) 61binops.real = { 62'min', % z = min(x,y) 63'max', % z = max(x,y) 64'isgt', % z = (x > y) 65'islt', % z = (x < y) 66'isge', % z = (x >= y) 67'isle', % z = (x <= y) 68'gt', % z = (x > y) 69'lt', % z = (x < y) 70'ge', % z = (x >= y) 71'le', % z = (x <= y) 72'or', % z = x || y 73'and', % z = x && y 74'xor' % z = x != y 75}' ; 76 77% binary operators for integer types only 78binops.int = { 79 'bor', 'band', 'bxor', 'bxnor', ... 80 'bget', 'bset', 'bclr', 'bshift' } ; 81 82% binary operators for floating-point only (FP32, FP64, FC32, FC64) 83binops.float = { } ; 84 85% binary ops for FP32 and FP64 only 86binops.fpreal = { 87 'atan2', 'hypot', 'fmod', 'remainder', 'ldexp', 'copysign', 'cmplx' } ; 88 89% binary ops for FC32 and FC64 only 90binops.complex = { } ; 91 92% binary positional ops 93binops.positional = { 'firsti' , 'firsti1' , 'firstj' , 'firstj1', ... 94 'secondi', 'secondi1', 'secondj', 'secondj1' } ; 95 96% list of all binary ops 97binops.all = [ binops.alltypes, binops.real, binops.int, ... 98 binops.float, binops.fpreal, binops.complex, binops.positional ] ; 99 100%------------------------------------------------------------------------------- 101% unary ops 102%------------------------------------------------------------------------------- 103 104% defined for all 13 types 105unary_ops.alltypes = { 106'one', % z = 1 107'identity', % z = x 108'ainv', % z = -x 109'abs', % z = abs(x) (z is always real) 110'minv', % z = 1/x 111}' ; 112 113% unary ops for 11 real types only (all but FC32 and FC64) 114unary_ops.real = { 115'not' % z = ~x 116} ; 117 118% unary ops for 8 integer types only (INT* and UINT*) 119unary_ops.int = { 120'bnot' % z = ~x 121} ; 122 123% unary ops for floating-point only (FP32, FP64, FC32, FC64) 124unary_ops.float = { 125 'sqrt', 'log', 'exp', 'log2', ... 126 'sin', 'cos', 'tan', ... 127 'acos', 'asin', 'atan', ... 128 'sinh', 'cosh', 'tanh', ... 129 'acosh', 'asinh', 'atanh', ... 130 'ceil', 'floor', 'round', 'trunc', ... 131 'exp2', 'expm1', 'log10', 'log1p', ... 132 'isinf', 'isnan', 'isfinite', 'signum' } ; 133 134% unary ops for FP32 and FP64 only 135unary_ops.fpreal = { 136'lgamma', 'tgamma', 'erf', 'erfc', 'frexpx', 'frexpe' } ; 137 138% unary ops for FC32 and FC64 only 139unary_ops.complex = { 140 'conj', 'real', 'imag', 'carg' } ; 141 142% unary positional ops 143unary_ops.positional = { 'positioni', 'positioni1', 'positionj', 'positionj1' }; 144 145% list of all unary ops 146unary_ops.all = [ unary_ops.alltypes, unary_ops.real, unary_ops.int, ... 147 unary_ops.float, unary_ops.fpreal, unary_ops.complex, ... 148 unary_ops.positional ] ; 149 150%------------------------------------------------------------------------------- 151% valid binary ops 152%------------------------------------------------------------------------------- 153 154add_ops = { ... 155 'min', 'max', ... % 11 real types only 156 'plus', 'times', 'any', ... % all 13 types 157 'or', 'and', 'xor', 'eq', ... % just boolean 158 'bor', 'band', 'bxor', 'bxnor' } ; % just integer 159 160nonbool = { 161'int8' 162'int16' 163'int32' 164'int64' 165'uint8' 166'uint16' 167'uint32' 168'uint64' 169'single' 170'double' 171} ; 172 173%------------------------------------------------------------------------------- 174% create all unique semirings using built-in operators 175%------------------------------------------------------------------------------- 176 177n = 0 ; 178 179%------------------------------------------------------------------------------- 180% 1000: x,y,z all nonboolean: 20*5*10 181%------------------------------------------------------------------------------- 182 183for mult = {'first', 'second', 'pair', 'min', 'max', 'plus', 'minus', ... 184 'rminus', 'times', 'div', 'rdiv', ... 185 'iseq', 'isne', 'isgt', 'islt', 'isge', 'isle', ... 186 'or', 'and', 'xor', } 187 for add = { 'min', 'max', 'plus', 'times', 'any' } 188 for c = nonbool' 189 n = n + 1 ; 190 s = struct ('multiply', mult{1}, 'add', add{1}, 'class', c{1}) ; 191 semirings {n} = s ; 192 % fprintf ('%3d %s-%s-%s\n', n, add{1}, mult{1}, c{1}) ; 193 end 194 end 195end 196 197%------------------------------------------------------------------------------- 198% 300: x,y nonboolean, z boolean: 6 * 5 * 10 199%------------------------------------------------------------------------------- 200 201for mult = { 'eq', 'ne', 'gt', 'lt', 'ge', 'le' } 202 for add = { 'or', 'and', 'xor', 'eq', 'any' } 203 for c = nonbool' 204 n = n + 1 ; 205 s = struct ('multiply', mult{1}, 'add', add{1}, 'class', c{1}) ; 206 semirings {n} = s ; 207 % fprintf ('%3d %s-%s-%s\n', n, add{1}, mult{1}, c{1}) ; 208 end 209 end 210end 211 212%------------------------------------------------------------------------------- 213% 55: x,y,z all boolean: 11 * 5 214%------------------------------------------------------------------------------- 215 216for mult = { 'first', 'second', 'pair', 'or', 'and', 'xor', ... 217 'eq', 'gt', 'lt', 'ge', 'le' } 218 for add = { 'or', 'and', 'xor', 'eq', 'any' } 219 n = n + 1 ; 220 s = struct ('multiply', mult{1}, 'add', add{1}, 'class', c{1}) ; 221 semirings {n} = s ; 222 % fprintf ('%3d %s-%s-logical\n', n, add{1}, mult{1}) ; 223 end 224end 225 226%------------------------------------------------------------------------------- 227% 64: bitwise 228%------------------------------------------------------------------------------- 229 230for mult = { 'bor', 'band', 'bxor', 'bxnor' } 231 for add = { 'bor', 'band', 'bxor', 'bxnor' } 232 for c = { 'uint8', 'uint16', 'uint32', 'uint64' } ; 233 n = n + 1 ; 234 s = struct ('multiply', mult{1}, 'add', add{1}, 'class', c{1}) ; 235 semirings {n} = s ; 236 % fprintf ('%3d %s-%s-logical\n', n, add{1}, mult{1}) ; 237 end 238 end 239end 240 241%------------------------------------------------------------------------------- 242% 54: complex 243%------------------------------------------------------------------------------- 244 245for mult = {'first', 'second', 'pair', 'plus', 'minus', ... 246 'rminus', 'times', 'div', 'rdiv' } 247 for add = { 'plus', 'times', 'any' } 248 for c = { 'single complex', 'double complex' } 249 n = n + 1 ; 250 s = struct ('multiply', mult{1}, 'add', add{1}, 'class', c{1}) ; 251 semirings {n} = s ; 252 % fprintf ('%3d %s-%s-%s\n', n, add{1}, mult{1}, c{1}) ; 253 end 254 end 255end 256 257%------------------------------------------------------------------------------- 258% 40: positional 259%------------------------------------------------------------------------------- 260 261for mult = { 'firsti' , 'firsti1' , 'firstj' , 'firstj1', ... 262 'secondi', 'secondi1', 'secondj', 'secondj1' } ; 263 for add = { 'min', 'max', 'plus', 'times', 'any' } 264 n = n + 1 ; 265 c = { 'int64' } ; 266 s = struct ('multiply', mult{1}, 'add', add{1}, 'class', c{1}) ; 267 semirings {n} = s ; 268 end 269end 270 271%------------------------------------------------------------------------------- 272% select operators 273%------------------------------------------------------------------------------- 274 275selops = { 'tril', 'triu', 'diag', 'offdiag', ... 276 'nonzero', 'eq_zero', 'gt_zero', 'ge_zero', 'lt_zero', 'le_zero', ... 277 'ne_thunk', 'eq_thunk', 'gt_thunk', 'ge_thunk', 'lt_thunk', 'le_thunk' }' ; 278 279% fprintf ('semirings: %d\n', n) ; 280 281