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
|
function [binops unary_ops add_ops types semirings selops idxunop] = GB_spec_opsall
%GB_SPEC_OPSALL return a list of all operators, types, and semirings
%
% [binops unary_ops add_ops types semirings select_ops idxunop] = GB_spec_opsall
% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0
%-------------------------------------------------------------------------------
% types
%-------------------------------------------------------------------------------
% all 13 built-in types
types.all = {
'logical', ...
'int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64', ...
'single', 'double', 'single complex', 'double complex' } ;
% all but complex
types.real = {
'logical', ...
'int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64', ...
'single', 'double' } ;
% integer types
types.int = {
'int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64' } ;
% floating-point types
types.float = { 'single', 'double', 'single complex', 'double complex'} ;
% floating-point real
types.fpreal = { 'single', 'double' } ;
% complex
types.complex = { 'single complex', 'double complex'} ;
%-------------------------------------------------------------------------------
% binary ops
%-------------------------------------------------------------------------------
% binary operators for all 13 types
binops.alltypes = {
'first', % z = x
'second', % z = y
'pair', % z = 1
'plus', % z = x + y
'minus', % z = x - y
'rminus', % z = y - x
'times', % z = x * y
'div', % z = x / y
'rdiv', % z = y / x
'iseq', % z = (x == y)
'isne', % z = (x != y)
'eq', % z = (x == y)
'ne', % z = (x != y)
'pow', % z = x.^y
'any', % z = any(x,y)
'oneb'}' ; % z = 1 (same as pair)
% binary operators for 11 types (all but complex)
binops.real = {
'min', % z = min(x,y)
'max', % z = max(x,y)
'isgt', % z = (x > y)
'islt', % z = (x < y)
'isge', % z = (x >= y)
'isle', % z = (x <= y)
'gt', % z = (x > y)
'lt', % z = (x < y)
'ge', % z = (x >= y)
'le', % z = (x <= y)
'or', % z = x || y
'and', % z = x && y
'xor' % z = x != y
}' ;
% binary operators for integer types only
binops.int = {
'bor', 'band', 'bxor', 'bxnor', ...
'bget', 'bset', 'bclr', 'bshift' } ;
% binary operators for floating-point only (FP32, FP64, FC32, FC64)
binops.float = { } ;
% binary ops for FP32 and FP64 only
binops.fpreal = {
'atan2', 'hypot', 'fmod', 'remainder', 'ldexp', 'copysign', 'cmplx' } ;
% binary ops for FC32 and FC64 only
binops.complex = { } ;
% binary positional ops
binops.positional = { 'firsti' , 'firsti1' , 'firstj' , 'firstj1', ...
'secondi', 'secondi1', 'secondj', 'secondj1' } ;
% list of all binary ops
binops.all = [ binops.alltypes, binops.real, binops.int, ...
binops.float, binops.fpreal, binops.complex, binops.positional ] ;
%-------------------------------------------------------------------------------
% unary ops
%-------------------------------------------------------------------------------
% defined for all 13 types
unary_ops.alltypes = {
'one', % z = 1
'identity', % z = x
'ainv', % z = -x
'abs', % z = abs(x) (z is always real)
'minv', % z = 1/x
}' ;
% unary ops for 11 real types only (all but FC32 and FC64)
unary_ops.real = {
'not' % z = ~x
} ;
% unary ops for 8 integer types only (INT* and UINT*)
unary_ops.int = {
'bnot' % z = ~x
} ;
% unary ops for floating-point only (FP32, FP64, FC32, FC64)
unary_ops.float = {
'sqrt', 'log', 'exp', 'log2', ...
'sin', 'cos', 'tan', ...
'acos', 'asin', 'atan', ...
'sinh', 'cosh', 'tanh', ...
'acosh', 'asinh', 'atanh', ...
'ceil', 'floor', 'round', 'trunc', ...
'exp2', 'expm1', 'log10', 'log1p', ...
'isinf', 'isnan', 'isfinite', 'signum' } ;
% unary ops for FP32 and FP64 only
unary_ops.fpreal = {
'lgamma', 'tgamma', 'erf', 'erfc', 'frexpx', 'frexpe', 'cbrt' } ;
% unary ops for FC32 and FC64 only
unary_ops.complex = {
'conj', 'real', 'imag', 'carg' } ;
% unary positional ops
unary_ops.positional = { 'positioni', 'positioni1', 'positionj', 'positionj1' };
% list of all unary ops
unary_ops.all = [ unary_ops.alltypes, unary_ops.real, unary_ops.int, ...
unary_ops.float, unary_ops.fpreal, unary_ops.complex, ...
unary_ops.positional ] ;
%-------------------------------------------------------------------------------
% valid binary ops
%-------------------------------------------------------------------------------
add_ops = { ...
'min', 'max', ... % 11 real types only
'plus', 'times', 'any', ... % all 13 types
'or', 'and', 'xor', 'eq', ... % just boolean
'bor', 'band', 'bxor', 'bxnor' } ; % just integer
nonbool = {
'int8'
'int16'
'int32'
'int64'
'uint8'
'uint16'
'uint32'
'uint64'
'single'
'double'
} ;
%-------------------------------------------------------------------------------
% create all unique semirings using built-in operators
%-------------------------------------------------------------------------------
n = 0 ;
%-------------------------------------------------------------------------------
% 1000: x,y,z all nonboolean: 20*5*10
%-------------------------------------------------------------------------------
for mult = {'first', 'second', 'oneb', 'min', 'max', 'plus', 'minus', ...
'rminus', 'times', 'div', 'rdiv', ...
'iseq', 'isne', 'isgt', 'islt', 'isge', 'isle', ...
'or', 'and', 'xor', }
for add = { 'min', 'max', 'plus', 'times', 'any' }
for c = nonbool'
n = n + 1 ;
s = struct ('multiply', mult{1}, 'add', add{1}, 'class', c{1}) ;
semirings {n} = s ;
% fprintf ('%3d %s-%s-%s\n', n, add{1}, mult{1}, c{1}) ;
end
end
end
%-------------------------------------------------------------------------------
% 300: x,y nonboolean, z boolean: 6 * 5 * 10
%-------------------------------------------------------------------------------
for mult = { 'eq', 'ne', 'gt', 'lt', 'ge', 'le' }
for add = { 'or', 'and', 'xor', 'eq', 'any' }
for c = nonbool'
n = n + 1 ;
s = struct ('multiply', mult{1}, 'add', add{1}, 'class', c{1}) ;
semirings {n} = s ;
% fprintf ('%3d %s-%s-%s\n', n, add{1}, mult{1}, c{1}) ;
end
end
end
%-------------------------------------------------------------------------------
% 55: x,y,z all boolean: 11 * 5
%-------------------------------------------------------------------------------
for mult = { 'first', 'second', 'oneb', 'or', 'and', 'xor', ...
'eq', 'gt', 'lt', 'ge', 'le' }
for add = { 'or', 'and', 'xor', 'eq', 'any' }
n = n + 1 ;
s = struct ('multiply', mult{1}, 'add', add{1}, 'class', c{1}) ;
semirings {n} = s ;
% fprintf ('%3d %s-%s-logical\n', n, add{1}, mult{1}) ;
end
end
%-------------------------------------------------------------------------------
% 64: bitwise
%-------------------------------------------------------------------------------
for mult = { 'bor', 'band', 'bxor', 'bxnor' }
for add = { 'bor', 'band', 'bxor', 'bxnor' }
for c = { 'uint8', 'uint16', 'uint32', 'uint64' } ;
n = n + 1 ;
s = struct ('multiply', mult{1}, 'add', add{1}, 'class', c{1}) ;
semirings {n} = s ;
% fprintf ('%3d %s-%s-logical\n', n, add{1}, mult{1}) ;
end
end
end
%-------------------------------------------------------------------------------
% 54: complex
%-------------------------------------------------------------------------------
for mult = {'first', 'second', 'oneb', 'plus', 'minus', ...
'rminus', 'times', 'div', 'rdiv' }
for add = { 'plus', 'times', 'any' }
for c = { 'single complex', 'double complex' }
n = n + 1 ;
s = struct ('multiply', mult{1}, 'add', add{1}, 'class', c{1}) ;
semirings {n} = s ;
% fprintf ('%3d %s-%s-%s\n', n, add{1}, mult{1}, c{1}) ;
end
end
end
%-------------------------------------------------------------------------------
% 40: positional
%-------------------------------------------------------------------------------
for mult = { 'firsti' , 'firsti1' , 'firstj' , 'firstj1', ...
'secondi', 'secondi1', 'secondj', 'secondj1' } ;
for add = { 'min', 'max', 'plus', 'times', 'any' }
n = n + 1 ;
c = { 'int64' } ;
s = struct ('multiply', mult{1}, 'add', add{1}, 'class', c{1}) ;
semirings {n} = s ;
end
end
%-------------------------------------------------------------------------------
% select operators
%-------------------------------------------------------------------------------
selops = { 'tril', 'triu', 'diag', 'offdiag', ...
'nonzero', 'eq_zero', 'gt_zero', 'ge_zero', 'lt_zero', 'le_zero', ...
'ne_thunk', 'eq_thunk', 'gt_thunk', 'ge_thunk', 'lt_thunk', 'le_thunk' }' ;
% fprintf ('semirings: %d\n', n) ;
%-------------------------------------------------------------------------------
% idxunop
%-------------------------------------------------------------------------------
idxunop = { 'rowindex', 'colindex', 'diagindex', ...
'tril', 'triu', 'diag', 'offdiag', ...
'colle', 'colgt', 'rowle', 'rowgt', ...
'valuene', 'valueeq', 'valuelt', 'valuele', 'valuegt', 'valuege' } ;
|