__init__.cython-30.pxd 35 KB

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