numpy.pxd 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  1. # NumPy static imports for Cython
  2. #
  3. # If any of the PyArray_* functions are called, import_array must be
  4. # called first.
  5. #
  6. # This also defines backwards-compatibility buffer acquisition
  7. # code for use in Python 2.x (or Python <= 2.5 when NumPy starts
  8. # implementing PEP-3118 directly).
  9. #
  10. # Because of laziness, the format string of the buffer is statically
  11. # allocated. Increase the size if this is not enough, or submit a
  12. # patch to do this properly.
  13. #
  14. # Author: Dag Sverre Seljebotn
  15. #
  16. DEF _buffer_format_string_len = 255
  17. cimport cpython.buffer as pybuf
  18. from cpython.ref cimport Py_INCREF
  19. from cpython.mem cimport PyObject_Malloc, PyObject_Free
  20. from cpython.object cimport PyObject, PyTypeObject
  21. from cpython.type cimport type
  22. cimport libc.stdio as stdio
  23. cdef extern from "Python.h":
  24. ctypedef int Py_intptr_t
  25. cdef extern from "numpy/arrayobject.h":
  26. ctypedef Py_intptr_t npy_intp
  27. ctypedef size_t npy_uintp
  28. cdef enum NPY_TYPES:
  29. NPY_BOOL
  30. NPY_BYTE
  31. NPY_UBYTE
  32. NPY_SHORT
  33. NPY_USHORT
  34. NPY_INT
  35. NPY_UINT
  36. NPY_LONG
  37. NPY_ULONG
  38. NPY_LONGLONG
  39. NPY_ULONGLONG
  40. NPY_FLOAT
  41. NPY_DOUBLE
  42. NPY_LONGDOUBLE
  43. NPY_CFLOAT
  44. NPY_CDOUBLE
  45. NPY_CLONGDOUBLE
  46. NPY_OBJECT
  47. NPY_STRING
  48. NPY_UNICODE
  49. NPY_VOID
  50. NPY_DATETIME
  51. NPY_TIMEDELTA
  52. NPY_NTYPES
  53. NPY_NOTYPE
  54. NPY_INT8
  55. NPY_INT16
  56. NPY_INT32
  57. NPY_INT64
  58. NPY_INT128
  59. NPY_INT256
  60. NPY_UINT8
  61. NPY_UINT16
  62. NPY_UINT32
  63. NPY_UINT64
  64. NPY_UINT128
  65. NPY_UINT256
  66. NPY_FLOAT16
  67. NPY_FLOAT32
  68. NPY_FLOAT64
  69. NPY_FLOAT80
  70. NPY_FLOAT96
  71. NPY_FLOAT128
  72. NPY_FLOAT256
  73. NPY_COMPLEX32
  74. NPY_COMPLEX64
  75. NPY_COMPLEX128
  76. NPY_COMPLEX160
  77. NPY_COMPLEX192
  78. NPY_COMPLEX256
  79. NPY_COMPLEX512
  80. NPY_INTP
  81. ctypedef enum NPY_ORDER:
  82. NPY_ANYORDER
  83. NPY_CORDER
  84. NPY_FORTRANORDER
  85. NPY_KEEPORDER
  86. ctypedef enum NPY_CASTING:
  87. NPY_NO_CASTING
  88. NPY_EQUIV_CASTING
  89. NPY_SAFE_CASTING
  90. NPY_SAME_KIND_CASTING
  91. NPY_UNSAFE_CASTING
  92. ctypedef enum NPY_CLIPMODE:
  93. NPY_CLIP
  94. NPY_WRAP
  95. NPY_RAISE
  96. ctypedef enum NPY_SCALARKIND:
  97. NPY_NOSCALAR,
  98. NPY_BOOL_SCALAR,
  99. NPY_INTPOS_SCALAR,
  100. NPY_INTNEG_SCALAR,
  101. NPY_FLOAT_SCALAR,
  102. NPY_COMPLEX_SCALAR,
  103. NPY_OBJECT_SCALAR
  104. ctypedef enum NPY_SORTKIND:
  105. NPY_QUICKSORT
  106. NPY_HEAPSORT
  107. NPY_MERGESORT
  108. ctypedef enum NPY_SEARCHSIDE:
  109. NPY_SEARCHLEFT
  110. NPY_SEARCHRIGHT
  111. enum:
  112. # DEPRECATED since NumPy 1.7 ! Do not use in new code!
  113. NPY_C_CONTIGUOUS
  114. NPY_F_CONTIGUOUS
  115. NPY_CONTIGUOUS
  116. NPY_FORTRAN
  117. NPY_OWNDATA
  118. NPY_FORCECAST
  119. NPY_ENSURECOPY
  120. NPY_ENSUREARRAY
  121. NPY_ELEMENTSTRIDES
  122. NPY_ALIGNED
  123. NPY_NOTSWAPPED
  124. NPY_WRITEABLE
  125. NPY_UPDATEIFCOPY
  126. NPY_ARR_HAS_DESCR
  127. NPY_BEHAVED
  128. NPY_BEHAVED_NS
  129. NPY_CARRAY
  130. NPY_CARRAY_RO
  131. NPY_FARRAY
  132. NPY_FARRAY_RO
  133. NPY_DEFAULT
  134. NPY_IN_ARRAY
  135. NPY_OUT_ARRAY
  136. NPY_INOUT_ARRAY
  137. NPY_IN_FARRAY
  138. NPY_OUT_FARRAY
  139. NPY_INOUT_FARRAY
  140. NPY_UPDATE_ALL
  141. enum:
  142. # Added in NumPy 1.7 to replace the deprecated enums above.
  143. NPY_ARRAY_C_CONTIGUOUS
  144. NPY_ARRAY_F_CONTIGUOUS
  145. NPY_ARRAY_OWNDATA
  146. NPY_ARRAY_FORCECAST
  147. NPY_ARRAY_ENSURECOPY
  148. NPY_ARRAY_ENSUREARRAY
  149. NPY_ARRAY_ELEMENTSTRIDES
  150. NPY_ARRAY_ALIGNED
  151. NPY_ARRAY_NOTSWAPPED
  152. NPY_ARRAY_WRITEABLE
  153. NPY_ARRAY_UPDATEIFCOPY
  154. NPY_ARRAY_BEHAVED
  155. NPY_ARRAY_BEHAVED_NS
  156. NPY_ARRAY_CARRAY
  157. NPY_ARRAY_CARRAY_RO
  158. NPY_ARRAY_FARRAY
  159. NPY_ARRAY_FARRAY_RO
  160. NPY_ARRAY_DEFAULT
  161. NPY_ARRAY_IN_ARRAY
  162. NPY_ARRAY_OUT_ARRAY
  163. NPY_ARRAY_INOUT_ARRAY
  164. NPY_ARRAY_IN_FARRAY
  165. NPY_ARRAY_OUT_FARRAY
  166. NPY_ARRAY_INOUT_FARRAY
  167. NPY_ARRAY_UPDATE_ALL
  168. cdef enum:
  169. NPY_MAXDIMS
  170. npy_intp NPY_MAX_ELSIZE
  171. ctypedef void (*PyArray_VectorUnaryFunc)(void *, void *, npy_intp, void *, void *)
  172. ctypedef struct PyArray_ArrayDescr:
  173. # shape is a tuple, but Cython doesn't support "tuple shape"
  174. # inside a non-PyObject declaration, so we have to declare it
  175. # as just a PyObject*.
  176. PyObject* shape
  177. ctypedef struct PyArray_Descr:
  178. pass
  179. ctypedef class numpy.dtype [object PyArray_Descr, check_size ignore]:
  180. # Use PyDataType_* macros when possible, however there are no macros
  181. # for accessing some of the fields, so some are defined.
  182. cdef PyTypeObject* typeobj
  183. cdef char kind
  184. cdef char type
  185. # Numpy sometimes mutates this without warning (e.g. it'll
  186. # sometimes change "|" to "<" in shared dtype objects on
  187. # little-endian machines). If this matters to you, use
  188. # PyArray_IsNativeByteOrder(dtype.byteorder) instead of
  189. # directly accessing this field.
  190. cdef char byteorder
  191. cdef char flags
  192. cdef int type_num
  193. cdef int itemsize "elsize"
  194. cdef int alignment
  195. cdef dict fields
  196. cdef tuple names
  197. # Use PyDataType_HASSUBARRAY to test whether this field is
  198. # valid (the pointer can be NULL). Most users should access
  199. # this field via the inline helper method PyDataType_SHAPE.
  200. cdef PyArray_ArrayDescr* subarray
  201. ctypedef extern class numpy.flatiter [object PyArrayIterObject]:
  202. # Use through macros
  203. pass
  204. ctypedef extern class numpy.broadcast [object PyArrayMultiIterObject]:
  205. # Use through macros
  206. pass
  207. ctypedef struct PyArrayObject:
  208. # For use in situations where ndarray can't replace PyArrayObject*,
  209. # like PyArrayObject**.
  210. pass
  211. ctypedef class numpy.ndarray [object PyArrayObject, check_size ignore]:
  212. cdef __cythonbufferdefaults__ = {"mode": "strided"}
  213. cdef:
  214. # Only taking a few of the most commonly used and stable fields.
  215. # One should use PyArray_* macros instead to access the C fields.
  216. char *data
  217. int ndim "nd"
  218. npy_intp *shape "dimensions"
  219. npy_intp *strides
  220. dtype descr # deprecated since NumPy 1.7 !
  221. PyObject* base
  222. # Note: This syntax (function definition in pxd files) is an
  223. # experimental exception made for __getbuffer__ and __releasebuffer__
  224. # -- the details of this may change.
  225. def __getbuffer__(ndarray self, Py_buffer* info, int flags):
  226. # This implementation of getbuffer is geared towards Cython
  227. # requirements, and does not yet fulfill the PEP.
  228. # In particular strided access is always provided regardless
  229. # of flags
  230. cdef int i, ndim
  231. cdef int endian_detector = 1
  232. cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
  233. ndim = PyArray_NDIM(self)
  234. if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
  235. and not PyArray_CHKFLAGS(self, NPY_ARRAY_C_CONTIGUOUS)):
  236. raise ValueError(u"ndarray is not C contiguous")
  237. if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
  238. and not PyArray_CHKFLAGS(self, NPY_ARRAY_F_CONTIGUOUS)):
  239. raise ValueError(u"ndarray is not Fortran contiguous")
  240. info.buf = PyArray_DATA(self)
  241. info.ndim = ndim
  242. if sizeof(npy_intp) != sizeof(Py_ssize_t):
  243. # Allocate new buffer for strides and shape info.
  244. # This is allocated as one block, strides first.
  245. info.strides = <Py_ssize_t*>PyObject_Malloc(sizeof(Py_ssize_t) * 2 * <size_t>ndim)
  246. info.shape = info.strides + ndim
  247. for i in range(ndim):
  248. info.strides[i] = PyArray_STRIDES(self)[i]
  249. info.shape[i] = PyArray_DIMS(self)[i]
  250. else:
  251. info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
  252. info.shape = <Py_ssize_t*>PyArray_DIMS(self)
  253. info.suboffsets = NULL
  254. info.itemsize = PyArray_ITEMSIZE(self)
  255. info.readonly = not PyArray_ISWRITEABLE(self)
  256. cdef int t
  257. cdef char* f = NULL
  258. cdef dtype descr = <dtype>PyArray_DESCR(self)
  259. cdef int offset
  260. info.obj = self
  261. if not PyDataType_HASFIELDS(descr):
  262. t = descr.type_num
  263. if ((descr.byteorder == c'>' and little_endian) or
  264. (descr.byteorder == c'<' and not little_endian)):
  265. raise ValueError(u"Non-native byte order not supported")
  266. if t == NPY_BYTE: f = "b"
  267. elif t == NPY_UBYTE: f = "B"
  268. elif t == NPY_SHORT: f = "h"
  269. elif t == NPY_USHORT: f = "H"
  270. elif t == NPY_INT: f = "i"
  271. elif t == NPY_UINT: f = "I"
  272. elif t == NPY_LONG: f = "l"
  273. elif t == NPY_ULONG: f = "L"
  274. elif t == NPY_LONGLONG: f = "q"
  275. elif t == NPY_ULONGLONG: f = "Q"
  276. elif t == NPY_FLOAT: f = "f"
  277. elif t == NPY_DOUBLE: f = "d"
  278. elif t == NPY_LONGDOUBLE: f = "g"
  279. elif t == NPY_CFLOAT: f = "Zf"
  280. elif t == NPY_CDOUBLE: f = "Zd"
  281. elif t == NPY_CLONGDOUBLE: f = "Zg"
  282. elif t == NPY_OBJECT: f = "O"
  283. else:
  284. raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
  285. info.format = f
  286. return
  287. else:
  288. info.format = <char*>PyObject_Malloc(_buffer_format_string_len)
  289. info.format[0] = c'^' # Native data types, manual alignment
  290. offset = 0
  291. f = _util_dtypestring(descr, info.format + 1,
  292. info.format + _buffer_format_string_len,
  293. &offset)
  294. f[0] = c'\0' # Terminate format string
  295. def __releasebuffer__(ndarray self, Py_buffer* info):
  296. if PyArray_HASFIELDS(self):
  297. PyObject_Free(info.format)
  298. if sizeof(npy_intp) != sizeof(Py_ssize_t):
  299. PyObject_Free(info.strides)
  300. # info.shape was stored after info.strides in the same block
  301. ctypedef unsigned char npy_bool
  302. ctypedef signed char npy_byte
  303. ctypedef signed short npy_short
  304. ctypedef signed int npy_int
  305. ctypedef signed long npy_long
  306. ctypedef signed long long npy_longlong
  307. ctypedef unsigned char npy_ubyte
  308. ctypedef unsigned short npy_ushort
  309. ctypedef unsigned int npy_uint
  310. ctypedef unsigned long npy_ulong
  311. ctypedef unsigned long long npy_ulonglong
  312. ctypedef float npy_float
  313. ctypedef double npy_double
  314. ctypedef long double npy_longdouble
  315. ctypedef signed char npy_int8
  316. ctypedef signed short npy_int16
  317. ctypedef signed int npy_int32
  318. ctypedef signed long long npy_int64
  319. ctypedef signed long long npy_int96
  320. ctypedef signed long long npy_int128
  321. ctypedef unsigned char npy_uint8
  322. ctypedef unsigned short npy_uint16
  323. ctypedef unsigned int npy_uint32
  324. ctypedef unsigned long long npy_uint64
  325. ctypedef unsigned long long npy_uint96
  326. ctypedef unsigned long long npy_uint128
  327. ctypedef float npy_float32
  328. ctypedef double npy_float64
  329. ctypedef long double npy_float80
  330. ctypedef long double npy_float96
  331. ctypedef long double npy_float128
  332. ctypedef struct npy_cfloat:
  333. double real
  334. double imag
  335. ctypedef struct npy_cdouble:
  336. double real
  337. double imag
  338. ctypedef struct npy_clongdouble:
  339. long double real
  340. long double imag
  341. ctypedef struct npy_complex64:
  342. float real
  343. float imag
  344. ctypedef struct npy_complex128:
  345. double real
  346. double imag
  347. ctypedef struct npy_complex160:
  348. long double real
  349. long double imag
  350. ctypedef struct npy_complex192:
  351. long double real
  352. long double imag
  353. ctypedef struct npy_complex256:
  354. long double real
  355. long double imag
  356. ctypedef struct PyArray_Dims:
  357. npy_intp *ptr
  358. int len
  359. int _import_array() except -1
  360. #
  361. # Macros from ndarrayobject.h
  362. #
  363. bint PyArray_CHKFLAGS(ndarray m, int flags)
  364. bint PyArray_IS_C_CONTIGUOUS(ndarray arr)
  365. bint PyArray_IS_F_CONTIGUOUS(ndarray arr)
  366. bint PyArray_ISCONTIGUOUS(ndarray m)
  367. bint PyArray_ISWRITEABLE(ndarray m)
  368. bint PyArray_ISALIGNED(ndarray m)
  369. int PyArray_NDIM(ndarray)
  370. bint PyArray_ISONESEGMENT(ndarray)
  371. bint PyArray_ISFORTRAN(ndarray)
  372. int PyArray_FORTRANIF(ndarray)
  373. void* PyArray_DATA(ndarray)
  374. char* PyArray_BYTES(ndarray)
  375. npy_intp* PyArray_DIMS(ndarray)
  376. npy_intp* PyArray_STRIDES(ndarray)
  377. npy_intp PyArray_DIM(ndarray, size_t)
  378. npy_intp PyArray_STRIDE(ndarray, size_t)
  379. PyObject *PyArray_BASE(ndarray) # returns borrowed reference!
  380. PyArray_Descr *PyArray_DESCR(ndarray) # returns borrowed reference to dtype!
  381. int PyArray_FLAGS(ndarray)
  382. npy_intp PyArray_ITEMSIZE(ndarray)
  383. int PyArray_TYPE(ndarray arr)
  384. object PyArray_GETITEM(ndarray arr, void *itemptr)
  385. int PyArray_SETITEM(ndarray arr, void *itemptr, object obj)
  386. bint PyTypeNum_ISBOOL(int)
  387. bint PyTypeNum_ISUNSIGNED(int)
  388. bint PyTypeNum_ISSIGNED(int)
  389. bint PyTypeNum_ISINTEGER(int)
  390. bint PyTypeNum_ISFLOAT(int)
  391. bint PyTypeNum_ISNUMBER(int)
  392. bint PyTypeNum_ISSTRING(int)
  393. bint PyTypeNum_ISCOMPLEX(int)
  394. bint PyTypeNum_ISPYTHON(int)
  395. bint PyTypeNum_ISFLEXIBLE(int)
  396. bint PyTypeNum_ISUSERDEF(int)
  397. bint PyTypeNum_ISEXTENDED(int)
  398. bint PyTypeNum_ISOBJECT(int)
  399. bint PyDataType_ISBOOL(dtype)
  400. bint PyDataType_ISUNSIGNED(dtype)
  401. bint PyDataType_ISSIGNED(dtype)
  402. bint PyDataType_ISINTEGER(dtype)
  403. bint PyDataType_ISFLOAT(dtype)
  404. bint PyDataType_ISNUMBER(dtype)
  405. bint PyDataType_ISSTRING(dtype)
  406. bint PyDataType_ISCOMPLEX(dtype)
  407. bint PyDataType_ISPYTHON(dtype)
  408. bint PyDataType_ISFLEXIBLE(dtype)
  409. bint PyDataType_ISUSERDEF(dtype)
  410. bint PyDataType_ISEXTENDED(dtype)
  411. bint PyDataType_ISOBJECT(dtype)
  412. bint PyDataType_HASFIELDS(dtype)
  413. bint PyDataType_HASSUBARRAY(dtype)
  414. bint PyArray_ISBOOL(ndarray)
  415. bint PyArray_ISUNSIGNED(ndarray)
  416. bint PyArray_ISSIGNED(ndarray)
  417. bint PyArray_ISINTEGER(ndarray)
  418. bint PyArray_ISFLOAT(ndarray)
  419. bint PyArray_ISNUMBER(ndarray)
  420. bint PyArray_ISSTRING(ndarray)
  421. bint PyArray_ISCOMPLEX(ndarray)
  422. bint PyArray_ISPYTHON(ndarray)
  423. bint PyArray_ISFLEXIBLE(ndarray)
  424. bint PyArray_ISUSERDEF(ndarray)
  425. bint PyArray_ISEXTENDED(ndarray)
  426. bint PyArray_ISOBJECT(ndarray)
  427. bint PyArray_HASFIELDS(ndarray)
  428. bint PyArray_ISVARIABLE(ndarray)
  429. bint PyArray_SAFEALIGNEDCOPY(ndarray)
  430. bint PyArray_ISNBO(char) # works on ndarray.byteorder
  431. bint PyArray_IsNativeByteOrder(char) # works on ndarray.byteorder
  432. bint PyArray_ISNOTSWAPPED(ndarray)
  433. bint PyArray_ISBYTESWAPPED(ndarray)
  434. bint PyArray_FLAGSWAP(ndarray, int)
  435. bint PyArray_ISCARRAY(ndarray)
  436. bint PyArray_ISCARRAY_RO(ndarray)
  437. bint PyArray_ISFARRAY(ndarray)
  438. bint PyArray_ISFARRAY_RO(ndarray)
  439. bint PyArray_ISBEHAVED(ndarray)
  440. bint PyArray_ISBEHAVED_RO(ndarray)
  441. bint PyDataType_ISNOTSWAPPED(dtype)
  442. bint PyDataType_ISBYTESWAPPED(dtype)
  443. bint PyArray_DescrCheck(object)
  444. bint PyArray_Check(object)
  445. bint PyArray_CheckExact(object)
  446. # Cannot be supported due to out arg:
  447. # bint PyArray_HasArrayInterfaceType(object, dtype, object, object&)
  448. # bint PyArray_HasArrayInterface(op, out)
  449. bint PyArray_IsZeroDim(object)
  450. # Cannot be supported due to ## ## in macro:
  451. # bint PyArray_IsScalar(object, verbatim work)
  452. bint PyArray_CheckScalar(object)
  453. bint PyArray_IsPythonNumber(object)
  454. bint PyArray_IsPythonScalar(object)
  455. bint PyArray_IsAnyScalar(object)
  456. bint PyArray_CheckAnyScalar(object)
  457. ndarray PyArray_GETCONTIGUOUS(ndarray)
  458. bint PyArray_SAMESHAPE(ndarray, ndarray)
  459. npy_intp PyArray_SIZE(ndarray)
  460. npy_intp PyArray_NBYTES(ndarray)
  461. object PyArray_FROM_O(object)
  462. object PyArray_FROM_OF(object m, int flags)
  463. object PyArray_FROM_OT(object m, int type)
  464. object PyArray_FROM_OTF(object m, int type, int flags)
  465. object PyArray_FROMANY(object m, int type, int min, int max, int flags)
  466. object PyArray_ZEROS(int nd, npy_intp* dims, int type, int fortran)
  467. object PyArray_EMPTY(int nd, npy_intp* dims, int type, int fortran)
  468. void PyArray_FILLWBYTE(object, int val)
  469. npy_intp PyArray_REFCOUNT(object)
  470. object PyArray_ContiguousFromAny(op, int, int min_depth, int max_depth)
  471. unsigned char PyArray_EquivArrTypes(ndarray a1, ndarray a2)
  472. bint PyArray_EquivByteorders(int b1, int b2)
  473. object PyArray_SimpleNew(int nd, npy_intp* dims, int typenum)
  474. object PyArray_SimpleNewFromData(int nd, npy_intp* dims, int typenum, void* data)
  475. #object PyArray_SimpleNewFromDescr(int nd, npy_intp* dims, dtype descr)
  476. object PyArray_ToScalar(void* data, ndarray arr)
  477. void* PyArray_GETPTR1(ndarray m, npy_intp i)
  478. void* PyArray_GETPTR2(ndarray m, npy_intp i, npy_intp j)
  479. void* PyArray_GETPTR3(ndarray m, npy_intp i, npy_intp j, npy_intp k)
  480. void* PyArray_GETPTR4(ndarray m, npy_intp i, npy_intp j, npy_intp k, npy_intp l)
  481. void PyArray_XDECREF_ERR(ndarray)
  482. # Cannot be supported due to out arg
  483. # void PyArray_DESCR_REPLACE(descr)
  484. object PyArray_Copy(ndarray)
  485. object PyArray_FromObject(object op, int type, int min_depth, int max_depth)
  486. object PyArray_ContiguousFromObject(object op, int type, int min_depth, int max_depth)
  487. object PyArray_CopyFromObject(object op, int type, int min_depth, int max_depth)
  488. object PyArray_Cast(ndarray mp, int type_num)
  489. object PyArray_Take(ndarray ap, object items, int axis)
  490. object PyArray_Put(ndarray ap, object items, object values)
  491. void PyArray_ITER_RESET(flatiter it) nogil
  492. void PyArray_ITER_NEXT(flatiter it) nogil
  493. void PyArray_ITER_GOTO(flatiter it, npy_intp* destination) nogil
  494. void PyArray_ITER_GOTO1D(flatiter it, npy_intp ind) nogil
  495. void* PyArray_ITER_DATA(flatiter it) nogil
  496. bint PyArray_ITER_NOTDONE(flatiter it) nogil
  497. void PyArray_MultiIter_RESET(broadcast multi) nogil
  498. void PyArray_MultiIter_NEXT(broadcast multi) nogil
  499. void PyArray_MultiIter_GOTO(broadcast multi, npy_intp dest) nogil
  500. void PyArray_MultiIter_GOTO1D(broadcast multi, npy_intp ind) nogil
  501. void* PyArray_MultiIter_DATA(broadcast multi, npy_intp i) nogil
  502. void PyArray_MultiIter_NEXTi(broadcast multi, npy_intp i) nogil
  503. bint PyArray_MultiIter_NOTDONE(broadcast multi) nogil
  504. # Functions from __multiarray_api.h
  505. # Functions taking dtype and returning object/ndarray are disabled
  506. # for now as they steal dtype references. I'm conservative and disable
  507. # more than is probably needed until it can be checked further.
  508. int PyArray_SetNumericOps (object)
  509. object PyArray_GetNumericOps ()
  510. int PyArray_INCREF (ndarray)
  511. int PyArray_XDECREF (ndarray)
  512. void PyArray_SetStringFunction (object, int)
  513. dtype PyArray_DescrFromType (int)
  514. object PyArray_TypeObjectFromType (int)
  515. char * PyArray_Zero (ndarray)
  516. char * PyArray_One (ndarray)
  517. #object PyArray_CastToType (ndarray, dtype, int)
  518. int PyArray_CastTo (ndarray, ndarray)
  519. int PyArray_CastAnyTo (ndarray, ndarray)
  520. int PyArray_CanCastSafely (int, int)
  521. npy_bool PyArray_CanCastTo (dtype, dtype)
  522. int PyArray_ObjectType (object, int)
  523. dtype PyArray_DescrFromObject (object, dtype)
  524. #ndarray* PyArray_ConvertToCommonType (object, int *)
  525. dtype PyArray_DescrFromScalar (object)
  526. dtype PyArray_DescrFromTypeObject (object)
  527. npy_intp PyArray_Size (object)
  528. #object PyArray_Scalar (void *, dtype, object)
  529. #object PyArray_FromScalar (object, dtype)
  530. void PyArray_ScalarAsCtype (object, void *)
  531. #int PyArray_CastScalarToCtype (object, void *, dtype)
  532. #int PyArray_CastScalarDirect (object, dtype, void *, int)
  533. object PyArray_ScalarFromObject (object)
  534. #PyArray_VectorUnaryFunc * PyArray_GetCastFunc (dtype, int)
  535. object PyArray_FromDims (int, int *, int)
  536. #object PyArray_FromDimsAndDataAndDescr (int, int *, dtype, char *)
  537. #object PyArray_FromAny (object, dtype, int, int, int, object)
  538. object PyArray_EnsureArray (object)
  539. object PyArray_EnsureAnyArray (object)
  540. #object PyArray_FromFile (stdio.FILE *, dtype, npy_intp, char *)
  541. #object PyArray_FromString (char *, npy_intp, dtype, npy_intp, char *)
  542. #object PyArray_FromBuffer (object, dtype, npy_intp, npy_intp)
  543. #object PyArray_FromIter (object, dtype, npy_intp)
  544. object PyArray_Return (ndarray)
  545. #object PyArray_GetField (ndarray, dtype, int)
  546. #int PyArray_SetField (ndarray, dtype, int, object)
  547. object PyArray_Byteswap (ndarray, npy_bool)
  548. object PyArray_Resize (ndarray, PyArray_Dims *, int, NPY_ORDER)
  549. int PyArray_MoveInto (ndarray, ndarray)
  550. int PyArray_CopyInto (ndarray, ndarray)
  551. int PyArray_CopyAnyInto (ndarray, ndarray)
  552. int PyArray_CopyObject (ndarray, object)
  553. object PyArray_NewCopy (ndarray, NPY_ORDER)
  554. object PyArray_ToList (ndarray)
  555. object PyArray_ToString (ndarray, NPY_ORDER)
  556. int PyArray_ToFile (ndarray, stdio.FILE *, char *, char *)
  557. int PyArray_Dump (object, object, int)
  558. object PyArray_Dumps (object, int)
  559. int PyArray_ValidType (int)
  560. void PyArray_UpdateFlags (ndarray, int)
  561. object PyArray_New (type, int, npy_intp *, int, npy_intp *, void *, int, int, object)
  562. #object PyArray_NewFromDescr (type, dtype, int, npy_intp *, npy_intp *, void *, int, object)
  563. #dtype PyArray_DescrNew (dtype)
  564. dtype PyArray_DescrNewFromType (int)
  565. double PyArray_GetPriority (object, double)
  566. object PyArray_IterNew (object)
  567. object PyArray_MultiIterNew (int, ...)
  568. int PyArray_PyIntAsInt (object)
  569. npy_intp PyArray_PyIntAsIntp (object)
  570. int PyArray_Broadcast (broadcast)
  571. void PyArray_FillObjectArray (ndarray, object)
  572. int PyArray_FillWithScalar (ndarray, object)
  573. npy_bool PyArray_CheckStrides (int, int, npy_intp, npy_intp, npy_intp *, npy_intp *)
  574. dtype PyArray_DescrNewByteorder (dtype, char)
  575. object PyArray_IterAllButAxis (object, int *)
  576. #object PyArray_CheckFromAny (object, dtype, int, int, int, object)
  577. #object PyArray_FromArray (ndarray, dtype, int)
  578. object PyArray_FromInterface (object)
  579. object PyArray_FromStructInterface (object)
  580. #object PyArray_FromArrayAttr (object, dtype, object)
  581. #NPY_SCALARKIND PyArray_ScalarKind (int, ndarray*)
  582. int PyArray_CanCoerceScalar (int, int, NPY_SCALARKIND)
  583. object PyArray_NewFlagsObject (object)
  584. npy_bool PyArray_CanCastScalar (type, type)
  585. #int PyArray_CompareUCS4 (npy_ucs4 *, npy_ucs4 *, register size_t)
  586. int PyArray_RemoveSmallest (broadcast)
  587. int PyArray_ElementStrides (object)
  588. void PyArray_Item_INCREF (char *, dtype)
  589. void PyArray_Item_XDECREF (char *, dtype)
  590. object PyArray_FieldNames (object)
  591. object PyArray_Transpose (ndarray, PyArray_Dims *)
  592. object PyArray_TakeFrom (ndarray, object, int, ndarray, NPY_CLIPMODE)
  593. object PyArray_PutTo (ndarray, object, object, NPY_CLIPMODE)
  594. object PyArray_PutMask (ndarray, object, object)
  595. object PyArray_Repeat (ndarray, object, int)
  596. object PyArray_Choose (ndarray, object, ndarray, NPY_CLIPMODE)
  597. int PyArray_Sort (ndarray, int, NPY_SORTKIND)
  598. object PyArray_ArgSort (ndarray, int, NPY_SORTKIND)
  599. object PyArray_SearchSorted (ndarray, object, NPY_SEARCHSIDE)
  600. object PyArray_ArgMax (ndarray, int, ndarray)
  601. object PyArray_ArgMin (ndarray, int, ndarray)
  602. object PyArray_Reshape (ndarray, object)
  603. object PyArray_Newshape (ndarray, PyArray_Dims *, NPY_ORDER)
  604. object PyArray_Squeeze (ndarray)
  605. #object PyArray_View (ndarray, dtype, type)
  606. object PyArray_SwapAxes (ndarray, int, int)
  607. object PyArray_Max (ndarray, int, ndarray)
  608. object PyArray_Min (ndarray, int, ndarray)
  609. object PyArray_Ptp (ndarray, int, ndarray)
  610. object PyArray_Mean (ndarray, int, int, ndarray)
  611. object PyArray_Trace (ndarray, int, int, int, int, ndarray)
  612. object PyArray_Diagonal (ndarray, int, int, int)
  613. object PyArray_Clip (ndarray, object, object, ndarray)
  614. object PyArray_Conjugate (ndarray, ndarray)
  615. object PyArray_Nonzero (ndarray)
  616. object PyArray_Std (ndarray, int, int, ndarray, int)
  617. object PyArray_Sum (ndarray, int, int, ndarray)
  618. object PyArray_CumSum (ndarray, int, int, ndarray)
  619. object PyArray_Prod (ndarray, int, int, ndarray)
  620. object PyArray_CumProd (ndarray, int, int, ndarray)
  621. object PyArray_All (ndarray, int, ndarray)
  622. object PyArray_Any (ndarray, int, ndarray)
  623. object PyArray_Compress (ndarray, object, int, ndarray)
  624. object PyArray_Flatten (ndarray, NPY_ORDER)
  625. object PyArray_Ravel (ndarray, NPY_ORDER)
  626. npy_intp PyArray_MultiplyList (npy_intp *, int)
  627. int PyArray_MultiplyIntList (int *, int)
  628. void * PyArray_GetPtr (ndarray, npy_intp*)
  629. int PyArray_CompareLists (npy_intp *, npy_intp *, int)
  630. #int PyArray_AsCArray (object*, void *, npy_intp *, int, dtype)
  631. #int PyArray_As1D (object*, char **, int *, int)
  632. #int PyArray_As2D (object*, char ***, int *, int *, int)
  633. int PyArray_Free (object, void *)
  634. #int PyArray_Converter (object, object*)
  635. int PyArray_IntpFromSequence (object, npy_intp *, int)
  636. object PyArray_Concatenate (object, int)
  637. object PyArray_InnerProduct (object, object)
  638. object PyArray_MatrixProduct (object, object)
  639. object PyArray_CopyAndTranspose (object)
  640. object PyArray_Correlate (object, object, int)
  641. int PyArray_TypestrConvert (int, int)
  642. #int PyArray_DescrConverter (object, dtype*)
  643. #int PyArray_DescrConverter2 (object, dtype*)
  644. int PyArray_IntpConverter (object, PyArray_Dims *)
  645. #int PyArray_BufferConverter (object, chunk)
  646. int PyArray_AxisConverter (object, int *)
  647. int PyArray_BoolConverter (object, npy_bool *)
  648. int PyArray_ByteorderConverter (object, char *)
  649. int PyArray_OrderConverter (object, NPY_ORDER *)
  650. unsigned char PyArray_EquivTypes (dtype, dtype)
  651. #object PyArray_Zeros (int, npy_intp *, dtype, int)
  652. #object PyArray_Empty (int, npy_intp *, dtype, int)
  653. object PyArray_Where (object, object, object)
  654. object PyArray_Arange (double, double, double, int)
  655. #object PyArray_ArangeObj (object, object, object, dtype)
  656. int PyArray_SortkindConverter (object, NPY_SORTKIND *)
  657. object PyArray_LexSort (object, int)
  658. object PyArray_Round (ndarray, int, ndarray)
  659. unsigned char PyArray_EquivTypenums (int, int)
  660. int PyArray_RegisterDataType (dtype)
  661. int PyArray_RegisterCastFunc (dtype, int, PyArray_VectorUnaryFunc *)
  662. int PyArray_RegisterCanCast (dtype, int, NPY_SCALARKIND)
  663. #void PyArray_InitArrFuncs (PyArray_ArrFuncs *)
  664. object PyArray_IntTupleFromIntp (int, npy_intp *)
  665. int PyArray_TypeNumFromName (char *)
  666. int PyArray_ClipmodeConverter (object, NPY_CLIPMODE *)
  667. #int PyArray_OutputConverter (object, ndarray*)
  668. object PyArray_BroadcastToShape (object, npy_intp *, int)
  669. void _PyArray_SigintHandler (int)
  670. void* _PyArray_GetSigintBuf ()
  671. #int PyArray_DescrAlignConverter (object, dtype*)
  672. #int PyArray_DescrAlignConverter2 (object, dtype*)
  673. int PyArray_SearchsideConverter (object, void *)
  674. object PyArray_CheckAxis (ndarray, int *, int)
  675. npy_intp PyArray_OverflowMultiplyList (npy_intp *, int)
  676. int PyArray_CompareString (char *, char *, size_t)
  677. int PyArray_SetBaseObject(ndarray, base) # NOTE: steals a reference to base! Use "set_array_base()" instead.
  678. # Typedefs that matches the runtime dtype objects in
  679. # the numpy module.
  680. # The ones that are commented out needs an IFDEF function
  681. # in Cython to enable them only on the right systems.
  682. ctypedef npy_int8 int8_t
  683. ctypedef npy_int16 int16_t
  684. ctypedef npy_int32 int32_t
  685. ctypedef npy_int64 int64_t
  686. #ctypedef npy_int96 int96_t
  687. #ctypedef npy_int128 int128_t
  688. ctypedef npy_uint8 uint8_t
  689. ctypedef npy_uint16 uint16_t
  690. ctypedef npy_uint32 uint32_t
  691. ctypedef npy_uint64 uint64_t
  692. #ctypedef npy_uint96 uint96_t
  693. #ctypedef npy_uint128 uint128_t
  694. ctypedef npy_float32 float32_t
  695. ctypedef npy_float64 float64_t
  696. #ctypedef npy_float80 float80_t
  697. #ctypedef npy_float128 float128_t
  698. ctypedef float complex complex64_t
  699. ctypedef double complex complex128_t
  700. # The int types are mapped a bit surprising --
  701. # numpy.int corresponds to 'l' and numpy.long to 'q'
  702. ctypedef npy_long int_t
  703. ctypedef npy_longlong long_t
  704. ctypedef npy_longlong longlong_t
  705. ctypedef npy_ulong uint_t
  706. ctypedef npy_ulonglong ulong_t
  707. ctypedef npy_ulonglong ulonglong_t
  708. ctypedef npy_intp intp_t
  709. ctypedef npy_uintp uintp_t
  710. ctypedef npy_double float_t
  711. ctypedef npy_double double_t
  712. ctypedef npy_longdouble longdouble_t
  713. ctypedef npy_cfloat cfloat_t
  714. ctypedef npy_cdouble cdouble_t
  715. ctypedef npy_clongdouble clongdouble_t
  716. ctypedef npy_cdouble complex_t
  717. cdef inline object PyArray_MultiIterNew1(a):
  718. return PyArray_MultiIterNew(1, <void*>a)
  719. cdef inline object PyArray_MultiIterNew2(a, b):
  720. return PyArray_MultiIterNew(2, <void*>a, <void*>b)
  721. cdef inline object PyArray_MultiIterNew3(a, b, c):
  722. return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
  723. cdef inline object PyArray_MultiIterNew4(a, b, c, d):
  724. return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
  725. cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):
  726. return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
  727. cdef inline tuple PyDataType_SHAPE(dtype d):
  728. if PyDataType_HASSUBARRAY(d):
  729. return <tuple>d.subarray.shape
  730. else:
  731. return ()
  732. cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL:
  733. # Recursive utility function used in __getbuffer__ to get format
  734. # string. The new location in the format string is returned.
  735. cdef dtype child
  736. cdef int endian_detector = 1
  737. cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
  738. cdef tuple fields
  739. for childname in descr.names:
  740. fields = descr.fields[childname]
  741. child, new_offset = fields
  742. if (end - f) - <int>(new_offset - offset[0]) < 15:
  743. raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
  744. if ((child.byteorder == c'>' and little_endian) or
  745. (child.byteorder == c'<' and not little_endian)):
  746. raise ValueError(u"Non-native byte order not supported")
  747. # One could encode it in the format string and have Cython
  748. # complain instead, BUT: < and > in format strings also imply
  749. # standardized sizes for datatypes, and we rely on native in
  750. # order to avoid reencoding data types based on their size.
  751. #
  752. # A proper PEP 3118 exporter for other clients than Cython
  753. # must deal properly with this!
  754. # Output padding bytes
  755. while offset[0] < new_offset:
  756. f[0] = 120 # "x"; pad byte
  757. f += 1
  758. offset[0] += 1
  759. offset[0] += child.itemsize
  760. if not PyDataType_HASFIELDS(child):
  761. t = child.type_num
  762. if end - f < 5:
  763. raise RuntimeError(u"Format string allocated too short.")
  764. # Until ticket #99 is fixed, use integers to avoid warnings
  765. if t == NPY_BYTE: f[0] = 98 #"b"
  766. elif t == NPY_UBYTE: f[0] = 66 #"B"
  767. elif t == NPY_SHORT: f[0] = 104 #"h"
  768. elif t == NPY_USHORT: f[0] = 72 #"H"
  769. elif t == NPY_INT: f[0] = 105 #"i"
  770. elif t == NPY_UINT: f[0] = 73 #"I"
  771. elif t == NPY_LONG: f[0] = 108 #"l"
  772. elif t == NPY_ULONG: f[0] = 76 #"L"
  773. elif t == NPY_LONGLONG: f[0] = 113 #"q"
  774. elif t == NPY_ULONGLONG: f[0] = 81 #"Q"
  775. elif t == NPY_FLOAT: f[0] = 102 #"f"
  776. elif t == NPY_DOUBLE: f[0] = 100 #"d"
  777. elif t == NPY_LONGDOUBLE: f[0] = 103 #"g"
  778. elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf
  779. elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd
  780. elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg
  781. elif t == NPY_OBJECT: f[0] = 79 #"O"
  782. else:
  783. raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
  784. f += 1
  785. else:
  786. # Cython ignores struct boundary information ("T{...}"),
  787. # so don't output it
  788. f = _util_dtypestring(child, f, end, offset)
  789. return f
  790. #
  791. # ufunc API
  792. #
  793. cdef extern from "numpy/ufuncobject.h":
  794. ctypedef void (*PyUFuncGenericFunction) (char **, npy_intp *, npy_intp *, void *)
  795. ctypedef extern class numpy.ufunc [object PyUFuncObject]:
  796. cdef:
  797. int nin, nout, nargs
  798. int identity
  799. PyUFuncGenericFunction *functions
  800. void **data
  801. int ntypes
  802. int check_return
  803. char *name
  804. char *types
  805. char *doc
  806. void *ptr
  807. PyObject *obj
  808. PyObject *userloops
  809. cdef enum:
  810. PyUFunc_Zero
  811. PyUFunc_One
  812. PyUFunc_None
  813. UFUNC_ERR_IGNORE
  814. UFUNC_ERR_WARN
  815. UFUNC_ERR_RAISE
  816. UFUNC_ERR_CALL
  817. UFUNC_ERR_PRINT
  818. UFUNC_ERR_LOG
  819. UFUNC_MASK_DIVIDEBYZERO
  820. UFUNC_MASK_OVERFLOW
  821. UFUNC_MASK_UNDERFLOW
  822. UFUNC_MASK_INVALID
  823. UFUNC_SHIFT_DIVIDEBYZERO
  824. UFUNC_SHIFT_OVERFLOW
  825. UFUNC_SHIFT_UNDERFLOW
  826. UFUNC_SHIFT_INVALID
  827. UFUNC_FPE_DIVIDEBYZERO
  828. UFUNC_FPE_OVERFLOW
  829. UFUNC_FPE_UNDERFLOW
  830. UFUNC_FPE_INVALID
  831. UFUNC_ERR_DEFAULT
  832. UFUNC_ERR_DEFAULT2
  833. object PyUFunc_FromFuncAndData(PyUFuncGenericFunction *,
  834. void **, char *, int, int, int, int, char *, char *, int)
  835. int PyUFunc_RegisterLoopForType(ufunc, int,
  836. PyUFuncGenericFunction, int *, void *)
  837. int PyUFunc_GenericFunction \
  838. (ufunc, PyObject *, PyObject *, PyArrayObject **)
  839. void PyUFunc_f_f_As_d_d \
  840. (char **, npy_intp *, npy_intp *, void *)
  841. void PyUFunc_d_d \
  842. (char **, npy_intp *, npy_intp *, void *)
  843. void PyUFunc_f_f \
  844. (char **, npy_intp *, npy_intp *, void *)
  845. void PyUFunc_g_g \
  846. (char **, npy_intp *, npy_intp *, void *)
  847. void PyUFunc_F_F_As_D_D \
  848. (char **, npy_intp *, npy_intp *, void *)
  849. void PyUFunc_F_F \
  850. (char **, npy_intp *, npy_intp *, void *)
  851. void PyUFunc_D_D \
  852. (char **, npy_intp *, npy_intp *, void *)
  853. void PyUFunc_G_G \
  854. (char **, npy_intp *, npy_intp *, void *)
  855. void PyUFunc_O_O \
  856. (char **, npy_intp *, npy_intp *, void *)
  857. void PyUFunc_ff_f_As_dd_d \
  858. (char **, npy_intp *, npy_intp *, void *)
  859. void PyUFunc_ff_f \
  860. (char **, npy_intp *, npy_intp *, void *)
  861. void PyUFunc_dd_d \
  862. (char **, npy_intp *, npy_intp *, void *)
  863. void PyUFunc_gg_g \
  864. (char **, npy_intp *, npy_intp *, void *)
  865. void PyUFunc_FF_F_As_DD_D \
  866. (char **, npy_intp *, npy_intp *, void *)
  867. void PyUFunc_DD_D \
  868. (char **, npy_intp *, npy_intp *, void *)
  869. void PyUFunc_FF_F \
  870. (char **, npy_intp *, npy_intp *, void *)
  871. void PyUFunc_GG_G \
  872. (char **, npy_intp *, npy_intp *, void *)
  873. void PyUFunc_OO_O \
  874. (char **, npy_intp *, npy_intp *, void *)
  875. void PyUFunc_O_O_method \
  876. (char **, npy_intp *, npy_intp *, void *)
  877. void PyUFunc_OO_O_method \
  878. (char **, npy_intp *, npy_intp *, void *)
  879. void PyUFunc_On_Om \
  880. (char **, npy_intp *, npy_intp *, void *)
  881. int PyUFunc_GetPyValues \
  882. (char *, int *, int *, PyObject **)
  883. int PyUFunc_checkfperr \
  884. (int, PyObject *, int *)
  885. void PyUFunc_clearfperr()
  886. int PyUFunc_getfperr()
  887. int PyUFunc_handlefperr \
  888. (int, PyObject *, int, int *)
  889. int PyUFunc_ReplaceLoopBySignature \
  890. (ufunc, PyUFuncGenericFunction, int *, PyUFuncGenericFunction *)
  891. object PyUFunc_FromFuncAndDataAndSignature \
  892. (PyUFuncGenericFunction *, void **, char *, int, int, int,
  893. int, char *, char *, int, char *)
  894. int _import_umath() except -1
  895. cdef inline void set_array_base(ndarray arr, object base):
  896. Py_INCREF(base) # important to do this before stealing the reference below!
  897. PyArray_SetBaseObject(arr, base)
  898. cdef inline object get_array_base(ndarray arr):
  899. base = PyArray_BASE(arr)
  900. if base is NULL:
  901. return None
  902. return <object>base
  903. # Versions of the import_* functions which are more suitable for
  904. # Cython code.
  905. cdef inline int import_array() except -1:
  906. try:
  907. _import_array()
  908. except Exception:
  909. raise ImportError("numpy.core.multiarray failed to import")
  910. cdef inline int import_umath() except -1:
  911. try:
  912. _import_umath()
  913. except Exception:
  914. raise ImportError("numpy.core.umath failed to import")
  915. cdef inline int import_ufunc() except -1:
  916. try:
  917. _import_umath()
  918. except Exception:
  919. raise ImportError("numpy.core.umath failed to import")