__ufunc_api.h
1 2 #ifdef _UMATHMODULE 3 4 extern NPY_NO_EXPORT PyTypeObject PyUFunc_Type; 5 6 extern NPY_NO_EXPORT PyTypeObject PyUFunc_Type; 7 8 NPY_NO_EXPORT PyObject * PyUFunc_FromFuncAndData \ 9 (PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, int); 10 NPY_NO_EXPORT int PyUFunc_RegisterLoopForType \ 11 (PyUFuncObject *, int, PyUFuncGenericFunction, const int *, void *); 12 NPY_NO_EXPORT int PyUFunc_GenericFunction \ 13 (PyUFuncObject *NPY_UNUSED(ufunc), PyObject *NPY_UNUSED(args), PyObject *NPY_UNUSED(kwds), PyArrayObject **NPY_UNUSED(op)); 14 NPY_NO_EXPORT void PyUFunc_f_f_As_d_d \ 15 (char **, npy_intp const *, npy_intp const *, void *); 16 NPY_NO_EXPORT void PyUFunc_d_d \ 17 (char **, npy_intp const *, npy_intp const *, void *); 18 NPY_NO_EXPORT void PyUFunc_f_f \ 19 (char **, npy_intp const *, npy_intp const *, void *); 20 NPY_NO_EXPORT void PyUFunc_g_g \ 21 (char **, npy_intp const *, npy_intp const *, void *); 22 NPY_NO_EXPORT void PyUFunc_F_F_As_D_D \ 23 (char **, npy_intp const *, npy_intp const *, void *); 24 NPY_NO_EXPORT void PyUFunc_F_F \ 25 (char **, npy_intp const *, npy_intp const *, void *); 26 NPY_NO_EXPORT void PyUFunc_D_D \ 27 (char **, npy_intp const *, npy_intp const *, void *); 28 NPY_NO_EXPORT void PyUFunc_G_G \ 29 (char **, npy_intp const *, npy_intp const *, void *); 30 NPY_NO_EXPORT void PyUFunc_O_O \ 31 (char **, npy_intp const *, npy_intp const *, void *); 32 NPY_NO_EXPORT void PyUFunc_ff_f_As_dd_d \ 33 (char **, npy_intp const *, npy_intp const *, void *); 34 NPY_NO_EXPORT void PyUFunc_ff_f \ 35 (char **, npy_intp const *, npy_intp const *, void *); 36 NPY_NO_EXPORT void PyUFunc_dd_d \ 37 (char **, npy_intp const *, npy_intp const *, void *); 38 NPY_NO_EXPORT void PyUFunc_gg_g \ 39 (char **, npy_intp const *, npy_intp const *, void *); 40 NPY_NO_EXPORT void PyUFunc_FF_F_As_DD_D \ 41 (char **, npy_intp const *, npy_intp const *, void *); 42 NPY_NO_EXPORT void PyUFunc_DD_D \ 43 (char **, npy_intp const *, npy_intp const *, void *); 44 NPY_NO_EXPORT void PyUFunc_FF_F \ 45 (char **, npy_intp const *, npy_intp const *, void *); 46 NPY_NO_EXPORT void PyUFunc_GG_G \ 47 (char **, npy_intp const *, npy_intp const *, void *); 48 NPY_NO_EXPORT void PyUFunc_OO_O \ 49 (char **, npy_intp const *, npy_intp const *, void *); 50 NPY_NO_EXPORT void PyUFunc_O_O_method \ 51 (char **, npy_intp const *, npy_intp const *, void *); 52 NPY_NO_EXPORT void PyUFunc_OO_O_method \ 53 (char **, npy_intp const *, npy_intp const *, void *); 54 NPY_NO_EXPORT void PyUFunc_On_Om \ 55 (char **, npy_intp const *, npy_intp const *, void *); 56 NPY_NO_EXPORT int PyUFunc_GetPyValues \ 57 (char *, int *, int *, PyObject **); 58 NPY_NO_EXPORT int PyUFunc_checkfperr \ 59 (int, PyObject *, int *); 60 NPY_NO_EXPORT void PyUFunc_clearfperr \ 61 (void); 62 NPY_NO_EXPORT int PyUFunc_getfperr \ 63 (void); 64 NPY_NO_EXPORT int PyUFunc_handlefperr \ 65 (int, PyObject *, int, int *); 66 NPY_NO_EXPORT int PyUFunc_ReplaceLoopBySignature \ 67 (PyUFuncObject *, PyUFuncGenericFunction, const int *, PyUFuncGenericFunction *); 68 NPY_NO_EXPORT PyObject * PyUFunc_FromFuncAndDataAndSignature \ 69 (PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, int, const char *); 70 NPY_NO_EXPORT int PyUFunc_SetUsesArraysAsData \ 71 (void **NPY_UNUSED(data), size_t NPY_UNUSED(i)); 72 NPY_NO_EXPORT void PyUFunc_e_e \ 73 (char **, npy_intp const *, npy_intp const *, void *); 74 NPY_NO_EXPORT void PyUFunc_e_e_As_f_f \ 75 (char **, npy_intp const *, npy_intp const *, void *); 76 NPY_NO_EXPORT void PyUFunc_e_e_As_d_d \ 77 (char **, npy_intp const *, npy_intp const *, void *); 78 NPY_NO_EXPORT void PyUFunc_ee_e \ 79 (char **, npy_intp const *, npy_intp const *, void *); 80 NPY_NO_EXPORT void PyUFunc_ee_e_As_ff_f \ 81 (char **, npy_intp const *, npy_intp const *, void *); 82 NPY_NO_EXPORT void PyUFunc_ee_e_As_dd_d \ 83 (char **, npy_intp const *, npy_intp const *, void *); 84 NPY_NO_EXPORT int PyUFunc_DefaultTypeResolver \ 85 (PyUFuncObject *, NPY_CASTING, PyArrayObject **, PyObject *, PyArray_Descr **); 86 NPY_NO_EXPORT int PyUFunc_ValidateCasting \ 87 (PyUFuncObject *, NPY_CASTING, PyArrayObject **, PyArray_Descr **); 88 NPY_NO_EXPORT int PyUFunc_RegisterLoopForDescr \ 89 (PyUFuncObject *, PyArray_Descr *, PyUFuncGenericFunction, PyArray_Descr **, void *); 90 NPY_NO_EXPORT PyObject * PyUFunc_FromFuncAndDataAndSignatureAndIdentity \ 91 (PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, const int, const char *, PyObject *); 92 93 #else 94 95 #if defined(PY_UFUNC_UNIQUE_SYMBOL) 96 #define PyUFunc_API PY_UFUNC_UNIQUE_SYMBOL 97 #endif 98 99 #if defined(NO_IMPORT) || defined(NO_IMPORT_UFUNC) 100 extern void **PyUFunc_API; 101 #else 102 #if defined(PY_UFUNC_UNIQUE_SYMBOL) 103 void **PyUFunc_API; 104 #else 105 static void **PyUFunc_API=NULL; 106 #endif 107 #endif 108 109 #define PyUFunc_Type (*(PyTypeObject *)PyUFunc_API[0]) 110 #define PyUFunc_FromFuncAndData \ 111 (*(PyObject * (*)(PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, int)) \ 112 PyUFunc_API[1]) 113 #define PyUFunc_RegisterLoopForType \ 114 (*(int (*)(PyUFuncObject *, int, PyUFuncGenericFunction, const int *, void *)) \ 115 PyUFunc_API[2]) 116 #define PyUFunc_GenericFunction \ 117 (*(int (*)(PyUFuncObject *NPY_UNUSED(ufunc), PyObject *NPY_UNUSED(args), PyObject *NPY_UNUSED(kwds), PyArrayObject **NPY_UNUSED(op))) \ 118 PyUFunc_API[3]) 119 #define PyUFunc_f_f_As_d_d \ 120 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 121 PyUFunc_API[4]) 122 #define PyUFunc_d_d \ 123 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 124 PyUFunc_API[5]) 125 #define PyUFunc_f_f \ 126 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 127 PyUFunc_API[6]) 128 #define PyUFunc_g_g \ 129 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 130 PyUFunc_API[7]) 131 #define PyUFunc_F_F_As_D_D \ 132 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 133 PyUFunc_API[8]) 134 #define PyUFunc_F_F \ 135 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 136 PyUFunc_API[9]) 137 #define PyUFunc_D_D \ 138 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 139 PyUFunc_API[10]) 140 #define PyUFunc_G_G \ 141 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 142 PyUFunc_API[11]) 143 #define PyUFunc_O_O \ 144 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 145 PyUFunc_API[12]) 146 #define PyUFunc_ff_f_As_dd_d \ 147 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 148 PyUFunc_API[13]) 149 #define PyUFunc_ff_f \ 150 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 151 PyUFunc_API[14]) 152 #define PyUFunc_dd_d \ 153 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 154 PyUFunc_API[15]) 155 #define PyUFunc_gg_g \ 156 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 157 PyUFunc_API[16]) 158 #define PyUFunc_FF_F_As_DD_D \ 159 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 160 PyUFunc_API[17]) 161 #define PyUFunc_DD_D \ 162 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 163 PyUFunc_API[18]) 164 #define PyUFunc_FF_F \ 165 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 166 PyUFunc_API[19]) 167 #define PyUFunc_GG_G \ 168 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 169 PyUFunc_API[20]) 170 #define PyUFunc_OO_O \ 171 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 172 PyUFunc_API[21]) 173 #define PyUFunc_O_O_method \ 174 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 175 PyUFunc_API[22]) 176 #define PyUFunc_OO_O_method \ 177 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 178 PyUFunc_API[23]) 179 #define PyUFunc_On_Om \ 180 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 181 PyUFunc_API[24]) 182 #define PyUFunc_GetPyValues \ 183 (*(int (*)(char *, int *, int *, PyObject **)) \ 184 PyUFunc_API[25]) 185 #define PyUFunc_checkfperr \ 186 (*(int (*)(int, PyObject *, int *)) \ 187 PyUFunc_API[26]) 188 #define PyUFunc_clearfperr \ 189 (*(void (*)(void)) \ 190 PyUFunc_API[27]) 191 #define PyUFunc_getfperr \ 192 (*(int (*)(void)) \ 193 PyUFunc_API[28]) 194 #define PyUFunc_handlefperr \ 195 (*(int (*)(int, PyObject *, int, int *)) \ 196 PyUFunc_API[29]) 197 #define PyUFunc_ReplaceLoopBySignature \ 198 (*(int (*)(PyUFuncObject *, PyUFuncGenericFunction, const int *, PyUFuncGenericFunction *)) \ 199 PyUFunc_API[30]) 200 #define PyUFunc_FromFuncAndDataAndSignature \ 201 (*(PyObject * (*)(PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, int, const char *)) \ 202 PyUFunc_API[31]) 203 #define PyUFunc_SetUsesArraysAsData \ 204 (*(int (*)(void **NPY_UNUSED(data), size_t NPY_UNUSED(i))) \ 205 PyUFunc_API[32]) 206 #define PyUFunc_e_e \ 207 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 208 PyUFunc_API[33]) 209 #define PyUFunc_e_e_As_f_f \ 210 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 211 PyUFunc_API[34]) 212 #define PyUFunc_e_e_As_d_d \ 213 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 214 PyUFunc_API[35]) 215 #define PyUFunc_ee_e \ 216 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 217 PyUFunc_API[36]) 218 #define PyUFunc_ee_e_As_ff_f \ 219 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 220 PyUFunc_API[37]) 221 #define PyUFunc_ee_e_As_dd_d \ 222 (*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \ 223 PyUFunc_API[38]) 224 #define PyUFunc_DefaultTypeResolver \ 225 (*(int (*)(PyUFuncObject *, NPY_CASTING, PyArrayObject **, PyObject *, PyArray_Descr **)) \ 226 PyUFunc_API[39]) 227 #define PyUFunc_ValidateCasting \ 228 (*(int (*)(PyUFuncObject *, NPY_CASTING, PyArrayObject **, PyArray_Descr **)) \ 229 PyUFunc_API[40]) 230 #define PyUFunc_RegisterLoopForDescr \ 231 (*(int (*)(PyUFuncObject *, PyArray_Descr *, PyUFuncGenericFunction, PyArray_Descr **, void *)) \ 232 PyUFunc_API[41]) 233 #define PyUFunc_FromFuncAndDataAndSignatureAndIdentity \ 234 (*(PyObject * (*)(PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, const int, const char *, PyObject *)) \ 235 PyUFunc_API[42]) 236 237 static NPY_INLINE int 238 _import_umath(void) 239 { 240 PyObject *numpy = PyImport_ImportModule("numpy.core._multiarray_umath"); 241 PyObject *c_api = NULL; 242 243 if (numpy == NULL) { 244 PyErr_SetString(PyExc_ImportError, 245 "numpy.core._multiarray_umath failed to import"); 246 return -1; 247 } 248 c_api = PyObject_GetAttrString(numpy, "_UFUNC_API"); 249 Py_DECREF(numpy); 250 if (c_api == NULL) { 251 PyErr_SetString(PyExc_AttributeError, "_UFUNC_API not found"); 252 return -1; 253 } 254 255 if (!PyCapsule_CheckExact(c_api)) { 256 PyErr_SetString(PyExc_RuntimeError, "_UFUNC_API is not PyCapsule object"); 257 Py_DECREF(c_api); 258 return -1; 259 } 260 PyUFunc_API = (void **)PyCapsule_GetPointer(c_api, NULL); 261 Py_DECREF(c_api); 262 if (PyUFunc_API == NULL) { 263 PyErr_SetString(PyExc_RuntimeError, "_UFUNC_API is NULL pointer"); 264 return -1; 265 } 266 return 0; 267 } 268 269 #define import_umath() \ 270 do {\ 271 UFUNC_NOFPE\ 272 if (_import_umath() < 0) {\ 273 PyErr_Print();\ 274 PyErr_SetString(PyExc_ImportError,\ 275 "numpy.core.umath failed to import");\ 276 return NULL;\ 277 }\ 278 } while(0) 279 280 #define import_umath1(ret) \ 281 do {\ 282 UFUNC_NOFPE\ 283 if (_import_umath() < 0) {\ 284 PyErr_Print();\ 285 PyErr_SetString(PyExc_ImportError,\ 286 "numpy.core.umath failed to import");\ 287 return ret;\ 288 }\ 289 } while(0) 290 291 #define import_umath2(ret, msg) \ 292 do {\ 293 UFUNC_NOFPE\ 294 if (_import_umath() < 0) {\ 295 PyErr_Print();\ 296 PyErr_SetString(PyExc_ImportError, msg);\ 297 return ret;\ 298 }\ 299 } while(0) 300 301 #define import_ufunc() \ 302 do {\ 303 UFUNC_NOFPE\ 304 if (_import_umath() < 0) {\ 305 PyErr_Print();\ 306 PyErr_SetString(PyExc_ImportError,\ 307 "numpy.core.umath failed to import");\ 308 }\ 309 } while(0) 310 311 #endif