Functions are declinated from operations in cases where the name of the function might change with the library and the dtype. Therefore where possible we use simple rules to build functions, but tables are required. cmath.h functions should be overloaded for modern implement
(opsList: List[Operation], C11: bool=True, mkl: bool=False )
| 1070 | |
| 1071 | NUMPY_VML_PRE = { 'd': 'vd', 'f':'vs', 'F':'vz', 'D':'vc' } |
| 1072 | def FunctionFactory(opsList: List[Operation], C11: bool=True, mkl: bool=False ) -> None: |
| 1073 | ''' |
| 1074 | Functions are declinated from operations in cases where the name of the |
| 1075 | function might change with the library and the dtype. Therefore where |
| 1076 | possible we use simple rules to build functions, but tables are required. |
| 1077 | |
| 1078 | cmath.h functions should be overloaded for modern implementations. Some |
| 1079 | pre-C++/11 implementations (e.g. MSVC), have appended 'f's for the |
| 1080 | single-precision version. Cmath funcs return the value, i.e. they are not |
| 1081 | vectorized, but they are usually inlined. |
| 1082 | |
| 1083 | NumExpr complex funtions are prepended by: nc_{function}, |
| 1084 | e.g. nc_conj() |
| 1085 | and the return is the last argument. They are now vectorized, like VML |
| 1086 | functions, so they need the number of iterators as the first argument. |
| 1087 | |
| 1088 | Intel VML functions are prepended by: v{datatype}{Function}, |
| 1089 | e.g. vfSin() |
| 1090 | and the return is the last argument |
| 1091 | |
| 1092 | ''' |
| 1093 | global OP_COUNT |
| 1094 | |
| 1095 | #################### |
| 1096 | opsList += [ Operation( 'abs', '$DEST = $ARG1 < 0 ? -$ARG1 : $ARG1', LIB_STD, |
| 1097 | SIGNED_INT, [SIGNED_INT], vecType=TYPE_LOOP ) ] |
| 1098 | # TODO: test if `fabs()` is faster than ternary |
| 1099 | opsList += [ Operation( 'abs', '$DEST = fabs($ARG1)', LIB_STD, |
| 1100 | DECIMAL, [DECIMAL], vecType=TYPE_LOOP ) ] |
| 1101 | opsList += [ Operation( 'arccos', '$DEST = acos($ARG1)', LIB_STD, |
| 1102 | DECIMAL, [DECIMAL], vecType=TYPE_LOOP ) ] |
| 1103 | opsList += [ Operation( 'arcsin', '$DEST = asin($ARG1)', LIB_STD, |
| 1104 | DECIMAL, [DECIMAL], vecType=TYPE_LOOP ) ] |
| 1105 | opsList += [ Operation( 'arctan', '$DEST = atan($ARG1)', LIB_STD, |
| 1106 | DECIMAL, [DECIMAL], vecType=TYPE_LOOP ) ] |
| 1107 | opsList += [ Operation( 'arctan2', '$DEST = atan2($ARG1, $ARG2)', LIB_STD, |
| 1108 | DECIMAL, [DECIMAL, DECIMAL], vecType=TYPE_LOOP ) ] |
| 1109 | opsList += [ Operation( 'ceil', '$DEST = ceil($ARG1)', LIB_STD, |
| 1110 | DECIMAL, [DECIMAL], vecType=TYPE_LOOP ) ] |
| 1111 | opsList += [ Operation( 'cos', '$DEST = cos($ARG1)', LIB_STD, |
| 1112 | DECIMAL, [DECIMAL], vecType=TYPE_LOOP ) ] |
| 1113 | opsList += [ Operation( 'cosh', '$DEST = cosh($ARG1)', LIB_STD, |
| 1114 | DECIMAL, [DECIMAL], vecType=TYPE_LOOP ) ] |
| 1115 | opsList += [ Operation( 'exp', '$DEST = exp($ARG1)', LIB_STD, |
| 1116 | DECIMAL, [DECIMAL], vecType=TYPE_LOOP ) ] |
| 1117 | |
| 1118 | opsList += [ Operation( 'floor', '$DEST = floor($ARG1)', LIB_STD, |
| 1119 | DECIMAL, [DECIMAL], vecType=TYPE_LOOP ) ] |
| 1120 | |
| 1121 | |
| 1122 | # `scipy.special.factorial`` does _not_ round to the nearest integer |
| 1123 | # Also we force int8 and int16 to be up-cast here, otherwise overflow |
| 1124 | # happens very quickly. |
| 1125 | opsList += [ Operation( 'factorial', '$DEST = $ARG1 >= 0 ? ($DTYPE0)exp(lgamma(($DTYPE0)$ARG1 + 1)) : 0', LIB_STD, |
| 1126 | [np.dtype('float64').char] * 6, [BIG_INT + DECIMAL], vecType=TYPE_LOOP) ] |
| 1127 | |
| 1128 | opsList += [ Operation( 'rad2deg', '$DEST = $ARG1 * ($DTYPE0)57.2957795130823229', LIB_STD, |
| 1129 | DECIMAL, [DECIMAL], vecType=TYPE_LOOP, aliases='degrees' ) ] |