1 //------------------------------------------------------------------------------
2 // GB_ops_template.c: built-in unary and binary functions and operators
3 //------------------------------------------------------------------------------
4 
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: Apache-2.0
7 
8 //------------------------------------------------------------------------------
9 
10 // This file is #include'd many times in GB_ops.c to define the built-in unary
11 // and binary operators.  In that file, GB_TYPE is a built-in C type (bool,
12 // int8_t, uint64_t, double, etc) for the inputs x and y, and GB_XTYPE is
13 // corresponding GraphBLAS type, without the prefix (BOOL, INT8, etc).
14 
15 //------------------------------------------------------------------------------
16 // unary functions z=f(x) where z and x have the same type
17 //------------------------------------------------------------------------------
18 
19 GXB_OP1 (ONE, "one") ;
20 
21 #if defined ( GB_COMPLEX )
22 
23     // complex types
24     GXB_OP1 (IDENTITY , "identity" ) ;
25     GXB_OP1 (AINV     , "ainv"     ) ;
26     GXB_OP1 (MINV     , "minv"     ) ;
27 
28 #else
29 
30     // real types
31     GRB_OP1 (IDENTITY , "identity" ) ;
32     GRB_OP1 (AINV     , "ainv"     ) ;
33     GRB_OP1 (MINV     , "minv"     ) ;
34 
35     // z=abs(x), z and x have the same type
36     GRB_OP1 (ABS      , "abs"      ) ;
37 
38     // GxB_ABS_* is now GrB_ABS_*, and GxB_ABS_* is historical.
39     // The new name is preferred.  The old name will be kept for historical
40     // compatibility.
41     GXB_OP1_RENAME (ABS) ;
42 
43     // LNOT is only defined for real types, not complex
44     GXB_OP1 (LNOT     , "not"      ) ;
45 
46 #endif
47 
48 #if defined ( GB_FLOATING_POINT )
49 
50     GXB_OP1 (SQRT     , "sqrt"     ) ;
51     GXB_OP1 (LOG      , "log"      ) ;
52     GXB_OP1 (EXP      , "exp"      ) ;
53 
54     GXB_OP1 (SIN      , "sin"      ) ;
55     GXB_OP1 (COS      , "cos"      ) ;
56     GXB_OP1 (TAN      , "tan"      ) ;
57 
58     GXB_OP1 (ASIN     , "asin"     ) ;
59     GXB_OP1 (ACOS     , "acos"     ) ;
60     GXB_OP1 (ATAN     , "atan"     ) ;
61 
62     GXB_OP1 (SINH     , "sinh"     ) ;
63     GXB_OP1 (COSH     , "cosh"     ) ;
64     GXB_OP1 (TANH     , "tanh"     ) ;
65 
66     GXB_OP1 (ASINH    , "asinh"    ) ;
67     GXB_OP1 (ACOSH    , "acosh"    ) ;
68     GXB_OP1 (ATANH    , "atanh"    ) ;
69 
70     GXB_OP1 (SIGNUM   , "signum"   ) ;
71     GXB_OP1 (CEIL     , "ceil"     ) ;
72     GXB_OP1 (FLOOR    , "floor"    ) ;
73     GXB_OP1 (ROUND    , "round"    ) ;
74     GXB_OP1 (TRUNC    , "trunc"    ) ;
75 
76     GXB_OP1 (EXP2     , "exp2"     ) ;
77     GXB_OP1 (EXPM1    , "expm1"    ) ;
78     GXB_OP1 (LOG10    , "log10"    ) ;
79     GXB_OP1 (LOG1P    , "log1p"    ) ;
80     GXB_OP1 (LOG2     , "log2"     ) ;
81 
82     #if defined ( GB_COMPLEX )
83     // complex only
84     GXB_OP1 (CONJ     , "conj"     ) ;
85     #else
86     // real only
87     GXB_OP1 (LGAMMA   , "lgamma"   ) ;
88     GXB_OP1 (TGAMMA   , "tgamma"   ) ;
89     GXB_OP1 (ERF      , "erf"      ) ;
90     GXB_OP1 (ERFC     , "erfc"     ) ;
91     GXB_OP1 (FREXPX   , "frexpx"   ) ;
92     GXB_OP1 (FREXPE   , "frexpe"   ) ;
93     #endif
94 
95 #endif
96 
97 #if defined ( GB_SIGNED_INT ) || defined ( GB_UNSIGNED_INT )
98 
99     // bitwise complement
100     GRB_OP1 (BNOT     , "bnot"     ) ;
101 
102 #endif
103 
104 //------------------------------------------------------------------------------
105 // unary functions z=f(x) where z and x can have different types
106 //------------------------------------------------------------------------------
107 
108 #if defined ( GB_FLOAT )
109 
110     // z = f(x) where x is float, and z is bool
111     GXB_OP1z (ISINF     , "isinf"     , bool   , BOOL ) ;
112     GXB_OP1z (ISNAN     , "isnan"     , bool   , BOOL ) ;
113     GXB_OP1z (ISFINITE  , "isfinite"  , bool   , BOOL ) ;
114 
115 #elif defined ( GB_DOUBLE )
116 
117     // z = f(x) where x is double, and z is bool
118     GXB_OP1z (ISINF     , "isinf"     , bool   , BOOL ) ;
119     GXB_OP1z (ISNAN     , "isnan"     , bool   , BOOL ) ;
120     GXB_OP1z (ISFINITE  , "isfinite"  , bool   , BOOL ) ;
121 
122 #elif defined ( GB_FLOAT_COMPLEX )
123 
124     // z = f(x) where x is float complex, and the type of z is listed below:
125     GXB_OP1z (ABS       , "abs"       , float  , FP32) ;
126     GXB_OP1z (ISINF     , "isinf"     , bool   , BOOL) ;
127     GXB_OP1z (ISNAN     , "isnan"     , bool   , BOOL) ;
128     GXB_OP1z (ISFINITE  , "isfinite"  , bool   , BOOL ) ;
129 
130     GXB_OP1z (CREAL     , "creal"     , float  , FP32) ;
131     GXB_OP1z (CIMAG     , "cimag"     , float  , FP32) ;
132     GXB_OP1z (CARG      , "carg"      , float  , FP32) ;
133 
134 #elif defined ( GB_DOUBLE_COMPLEX )
135 
136     // z = f(x) where x is double complex, and the type of z is listed below:
137     GXB_OP1z (ABS       , "abs"       , double , FP64) ;
138     GXB_OP1z (ISINF     , "isinf"     , bool   , BOOL) ;
139     GXB_OP1z (ISNAN     , "isnan"     , bool   , BOOL) ;
140     GXB_OP1z (ISFINITE  , "isfinite"  , bool   , BOOL ) ;
141 
142     GXB_OP1z (CREAL     , "creal"     , double , FP64) ;
143     GXB_OP1z (CIMAG     , "cimag"     , double , FP64) ;
144     GXB_OP1z (CARG      , "carg"      , double , FP64) ;
145 
146 #endif
147 
148 //------------------------------------------------------------------------------
149 // binary functions z=f(x,y) where z, x, and y all have the same type
150 //------------------------------------------------------------------------------
151 
152 GXB_OP2 (RMINUS , "rminus")
153 GXB_OP2 (RDIV   , "rdiv"  )
154 GXB_OP2 (PAIR   , "pair"  )
155 GXB_OP2 (ANY    , "any"   )
156 GXB_OP2 (ISEQ   , "iseq"  )
157 GXB_OP2 (ISNE   , "isne"  )
158 GXB_OP2 (POW    , "pow"   )
159 
160 #if defined ( GB_COMPLEX )
161 
162     // complex types
163     GXB_OP2 (FIRST  , "first" )
164     GXB_OP2 (SECOND , "second")
165     GXB_OP2 (PLUS   , "plus"  )
166     GXB_OP2 (MINUS  , "minus" )
167     GXB_OP2 (TIMES  , "times" )
168     GXB_OP2 (DIV    , "div"   )
169 
170 #else
171 
172     // real types
173     GRB_OP2 (FIRST  , "first" )
174     GRB_OP2 (SECOND , "second")
175     GRB_OP2 (PLUS   , "plus"  )
176     GRB_OP2 (MINUS  , "minus" )
177     GRB_OP2 (TIMES  , "times" )
178     GRB_OP2 (DIV    , "div"   )
179 
180     GRB_OP2 (MIN    , "min" )
181     GRB_OP2 (MAX    , "max" )
182 
183     GXB_OP2 (LOR    , "or"  )
184     GXB_OP2 (LAND   , "and" )
185     GXB_OP2 (LXOR   , "xor" )
186 
187     GXB_OP2 (ISGT   , "isgt")
188     GXB_OP2 (ISLT   , "islt")
189     GXB_OP2 (ISGE   , "isge")
190     GXB_OP2 (ISLE   , "isle")
191 
192 #endif
193 
194 #if defined (GB_FLOAT) || defined (GB_DOUBLE)
195 
196     // these operators are only defined for float and double
197     GXB_OP2 (ATAN2    , "atan2"    )
198     GXB_OP2 (HYPOT    , "hypot"    )
199     GXB_OP2 (FMOD     , "fmod"     )
200     GXB_OP2 (REMAINDER, "remainder")
201     GXB_OP2 (COPYSIGN , "copysign" )
202     GXB_OP2 (LDEXP    , "ldexp"    )
203 
204 #endif
205 
206 #if defined ( GB_SIGNED_INT ) || defined ( GB_UNSIGNED_INT )
207 
208     // bitwise binary operators
209     GRB_OP2 (BOR      , "bitor"   ) ;
210     GRB_OP2 (BAND     , "bitand"  ) ;
211     GRB_OP2 (BXOR     , "bitxor"  ) ;
212     GRB_OP2 (BXNOR    , "bitxnor" ) ;
213 
214     GXB_OP2 (BGET     , "bitget"   ) ;
215     GXB_OP2 (BSET     , "bitset"   ) ;
216     GXB_OP2 (BCLR     , "bitclear" ) ;
217 
218     GXB_OP2shift (BSHIFT, "bitshift") ;
219 
220 #endif
221 
222 //------------------------------------------------------------------------------
223 // binary functions z=f(x,y) where z, x, and y can have different types
224 //------------------------------------------------------------------------------
225 
226 #if defined ( GB_FLOAT )
227 
228     // z = cmplx(x,y) where z is float complex, x and y are float
229     GXB_OP2z (CMPLX, "cmplx", GxB_FC32_t, FC32)
230 
231 #endif
232 
233 #if defined ( GB_DOUBLE )
234 
235     // z = cmplx(x,y) where z is double complex, x and y are double
236     GXB_OP2z (CMPLX, "cmplx", GxB_FC64_t, FC64)
237 
238 #endif
239 
240 #if defined ( GB_COMPLEX )
241 
242     // complex types
243     GXB_OP2z (EQ, "eq", bool, BOOL)
244     GXB_OP2z (NE, "ne", bool, BOOL)
245 
246 #else
247 
248     // real types
249     GRB_OP2z (EQ, "eq", bool, BOOL)
250     GRB_OP2z (NE, "ne", bool, BOOL)
251     GRB_OP2z (GT, "gt", bool, BOOL)
252     GRB_OP2z (LT, "lt", bool, BOOL)
253     GRB_OP2z (LE, "le", bool, BOOL)
254     GRB_OP2z (GE, "ge", bool, BOOL)
255 
256 #endif
257 
258 //------------------------------------------------------------------------------
259 // clear macros for next use of this file
260 //------------------------------------------------------------------------------
261 
262 #undef GB_TYPE
263 #undef GB_XTYPE
264 #undef GB_FLOATING_POINT
265 #undef GB_COMPLEX
266 #undef GB_FLOAT
267 #undef GB_DOUBLE
268 #undef GB_FLOAT_COMPLEX
269 #undef GB_DOUBLE_COMPLEX
270 #undef GB_SIGNED_INT
271 #undef GB_UNSIGNED_INT
272 
273