__ufunc_api.h 11 KB

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