multiarray_api.txt 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449
  1. ===========
  2. Numpy C-API
  3. ===========
  4. ::
  5. unsigned int
  6. PyArray_GetNDArrayCVersion(void )
  7. Included at the very first so not auto-grabbed and thus not labeled.
  8. ::
  9. int
  10. PyArray_SetNumericOps(PyObject *dict)
  11. Set internal structure with number functions that all arrays will use
  12. ::
  13. PyObject *
  14. PyArray_GetNumericOps(void )
  15. Get dictionary showing number functions that all arrays will use
  16. ::
  17. int
  18. PyArray_INCREF(PyArrayObject *mp)
  19. For object arrays, increment all internal references.
  20. ::
  21. int
  22. PyArray_XDECREF(PyArrayObject *mp)
  23. Decrement all internal references for object arrays.
  24. (or arrays with object fields)
  25. ::
  26. void
  27. PyArray_SetStringFunction(PyObject *op, int repr)
  28. Set the array print function to be a Python function.
  29. ::
  30. PyArray_Descr *
  31. PyArray_DescrFromType(int type)
  32. Get the PyArray_Descr structure for a type.
  33. ::
  34. PyObject *
  35. PyArray_TypeObjectFromType(int type)
  36. Get a typeobject from a type-number -- can return NULL.
  37. New reference
  38. ::
  39. char *
  40. PyArray_Zero(PyArrayObject *arr)
  41. Get pointer to zero of correct type for array.
  42. ::
  43. char *
  44. PyArray_One(PyArrayObject *arr)
  45. Get pointer to one of correct type for array
  46. ::
  47. PyObject *
  48. PyArray_CastToType(PyArrayObject *arr, PyArray_Descr *dtype, int
  49. is_f_order)
  50. For backward compatibility
  51. Cast an array using typecode structure.
  52. steals reference to dtype --- cannot be NULL
  53. This function always makes a copy of arr, even if the dtype
  54. doesn't change.
  55. ::
  56. int
  57. PyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)
  58. Cast to an already created array.
  59. ::
  60. int
  61. PyArray_CastAnyTo(PyArrayObject *out, PyArrayObject *mp)
  62. Cast to an already created array. Arrays don't have to be "broadcastable"
  63. Only requirement is they have the same number of elements.
  64. ::
  65. int
  66. PyArray_CanCastSafely(int fromtype, int totype)
  67. Check the type coercion rules.
  68. ::
  69. npy_bool
  70. PyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)
  71. leaves reference count alone --- cannot be NULL
  72. PyArray_CanCastTypeTo is equivalent to this, but adds a 'casting'
  73. parameter.
  74. ::
  75. int
  76. PyArray_ObjectType(PyObject *op, int minimum_type)
  77. Return the typecode of the array a Python object would be converted to
  78. Returns the type number the result should have, or NPY_NOTYPE on error.
  79. ::
  80. PyArray_Descr *
  81. PyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)
  82. new reference -- accepts NULL for mintype
  83. ::
  84. PyArrayObject **
  85. PyArray_ConvertToCommonType(PyObject *op, int *retn)
  86. ::
  87. PyArray_Descr *
  88. PyArray_DescrFromScalar(PyObject *sc)
  89. Return descr object from array scalar.
  90. New reference
  91. ::
  92. PyArray_Descr *
  93. PyArray_DescrFromTypeObject(PyObject *type)
  94. ::
  95. npy_intp
  96. PyArray_Size(PyObject *op)
  97. Compute the size of an array (in number of items)
  98. ::
  99. PyObject *
  100. PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)
  101. Get scalar-equivalent to a region of memory described by a descriptor.
  102. ::
  103. PyObject *
  104. PyArray_FromScalar(PyObject *scalar, PyArray_Descr *outcode)
  105. Get 0-dim array from scalar
  106. 0-dim array from array-scalar object
  107. always contains a copy of the data
  108. unless outcode is NULL, it is of void type and the referrer does
  109. not own it either.
  110. steals reference to outcode
  111. ::
  112. void
  113. PyArray_ScalarAsCtype(PyObject *scalar, void *ctypeptr)
  114. Convert to c-type
  115. no error checking is performed -- ctypeptr must be same type as scalar
  116. in case of flexible type, the data is not copied
  117. into ctypeptr which is expected to be a pointer to pointer
  118. ::
  119. int
  120. PyArray_CastScalarToCtype(PyObject *scalar, void
  121. *ctypeptr, PyArray_Descr *outcode)
  122. Cast Scalar to c-type
  123. The output buffer must be large-enough to receive the value
  124. Even for flexible types which is different from ScalarAsCtype
  125. where only a reference for flexible types is returned
  126. This may not work right on narrow builds for NumPy unicode scalars.
  127. ::
  128. int
  129. PyArray_CastScalarDirect(PyObject *scalar, PyArray_Descr
  130. *indescr, void *ctypeptr, int outtype)
  131. Cast Scalar to c-type
  132. ::
  133. PyObject *
  134. PyArray_ScalarFromObject(PyObject *object)
  135. Get an Array Scalar From a Python Object
  136. Returns NULL if unsuccessful but error is only set if another error occurred.
  137. Currently only Numeric-like object supported.
  138. ::
  139. PyArray_VectorUnaryFunc *
  140. PyArray_GetCastFunc(PyArray_Descr *descr, int type_num)
  141. Get a cast function to cast from the input descriptor to the
  142. output type_number (must be a registered data-type).
  143. Returns NULL if un-successful.
  144. ::
  145. PyObject *
  146. PyArray_FromDims(int nd, int *d, int type)
  147. Construct an empty array from dimensions and typenum
  148. ::
  149. PyObject *
  150. PyArray_FromDimsAndDataAndDescr(int nd, int *d, PyArray_Descr
  151. *descr, char *data)
  152. Like FromDimsAndData but uses the Descr structure instead of typecode
  153. as input.
  154. ::
  155. PyObject *
  156. PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int
  157. min_depth, int max_depth, int flags, PyObject
  158. *context)
  159. Does not check for NPY_ARRAY_ENSURECOPY and NPY_ARRAY_NOTSWAPPED in flags
  160. Steals a reference to newtype --- which can be NULL
  161. ::
  162. PyObject *
  163. PyArray_EnsureArray(PyObject *op)
  164. This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, ENSUREARRAY)
  165. that special cases Arrays and PyArray_Scalars up front
  166. It *steals a reference* to the object
  167. It also guarantees that the result is PyArray_Type
  168. Because it decrefs op if any conversion needs to take place
  169. so it can be used like PyArray_EnsureArray(some_function(...))
  170. ::
  171. PyObject *
  172. PyArray_EnsureAnyArray(PyObject *op)
  173. ::
  174. PyObject *
  175. PyArray_FromFile(FILE *fp, PyArray_Descr *dtype, npy_intp num, char
  176. *sep)
  177. Given a ``FILE *`` pointer ``fp``, and a ``PyArray_Descr``, return an
  178. array corresponding to the data encoded in that file.
  179. If the dtype is NULL, the default array type is used (double).
  180. If non-null, the reference is stolen.
  181. The number of elements to read is given as ``num``; if it is < 0, then
  182. then as many as possible are read.
  183. If ``sep`` is NULL or empty, then binary data is assumed, else
  184. text data, with ``sep`` as the separator between elements. Whitespace in
  185. the separator matches any length of whitespace in the text, and a match
  186. for whitespace around the separator is added.
  187. For memory-mapped files, use the buffer interface. No more data than
  188. necessary is read by this routine.
  189. ::
  190. PyObject *
  191. PyArray_FromString(char *data, npy_intp slen, PyArray_Descr
  192. *dtype, npy_intp num, char *sep)
  193. Given a pointer to a string ``data``, a string length ``slen``, and
  194. a ``PyArray_Descr``, return an array corresponding to the data
  195. encoded in that string.
  196. If the dtype is NULL, the default array type is used (double).
  197. If non-null, the reference is stolen.
  198. If ``slen`` is < 0, then the end of string is used for text data.
  199. It is an error for ``slen`` to be < 0 for binary data (since embedded NULLs
  200. would be the norm).
  201. The number of elements to read is given as ``num``; if it is < 0, then
  202. then as many as possible are read.
  203. If ``sep`` is NULL or empty, then binary data is assumed, else
  204. text data, with ``sep`` as the separator between elements. Whitespace in
  205. the separator matches any length of whitespace in the text, and a match
  206. for whitespace around the separator is added.
  207. ::
  208. PyObject *
  209. PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type, npy_intp
  210. count, npy_intp offset)
  211. ::
  212. PyObject *
  213. PyArray_FromIter(PyObject *obj, PyArray_Descr *dtype, npy_intp count)
  214. steals a reference to dtype (which cannot be NULL)
  215. ::
  216. PyObject *
  217. PyArray_Return(PyArrayObject *mp)
  218. Return either an array or the appropriate Python object if the array
  219. is 0d and matches a Python type.
  220. steals reference to mp
  221. ::
  222. PyObject *
  223. PyArray_GetField(PyArrayObject *self, PyArray_Descr *typed, int
  224. offset)
  225. Get a subset of bytes from each element of the array
  226. steals reference to typed, must not be NULL
  227. ::
  228. int
  229. PyArray_SetField(PyArrayObject *self, PyArray_Descr *dtype, int
  230. offset, PyObject *val)
  231. Set a subset of bytes from each element of the array
  232. steals reference to dtype, must not be NULL
  233. ::
  234. PyObject *
  235. PyArray_Byteswap(PyArrayObject *self, npy_bool inplace)
  236. ::
  237. PyObject *
  238. PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int
  239. refcheck, NPY_ORDER order)
  240. Resize (reallocate data). Only works if nothing else is referencing this
  241. array and it is contiguous. If refcheck is 0, then the reference count is
  242. not checked and assumed to be 1. You still must own this data and have no
  243. weak-references and no base object.
  244. ::
  245. int
  246. PyArray_MoveInto(PyArrayObject *dst, PyArrayObject *src)
  247. Move the memory of one array into another, allowing for overlapping data.
  248. Returns 0 on success, negative on failure.
  249. ::
  250. int
  251. PyArray_CopyInto(PyArrayObject *dst, PyArrayObject *src)
  252. Copy an Array into another array.
  253. Broadcast to the destination shape if necessary.
  254. Returns 0 on success, -1 on failure.
  255. ::
  256. int
  257. PyArray_CopyAnyInto(PyArrayObject *dst, PyArrayObject *src)
  258. Copy an Array into another array -- memory must not overlap
  259. Does not require src and dest to have "broadcastable" shapes
  260. (only the same number of elements).
  261. TODO: For NumPy 2.0, this could accept an order parameter which
  262. only allows NPY_CORDER and NPY_FORDER. Could also rename
  263. this to CopyAsFlat to make the name more intuitive.
  264. Returns 0 on success, -1 on error.
  265. ::
  266. int
  267. PyArray_CopyObject(PyArrayObject *dest, PyObject *src_object)
  268. ::
  269. PyObject *
  270. PyArray_NewCopy(PyArrayObject *obj, NPY_ORDER order)
  271. Copy an array.
  272. ::
  273. PyObject *
  274. PyArray_ToList(PyArrayObject *self)
  275. To List
  276. ::
  277. PyObject *
  278. PyArray_ToString(PyArrayObject *self, NPY_ORDER order)
  279. ::
  280. int
  281. PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
  282. To File
  283. ::
  284. int
  285. PyArray_Dump(PyObject *self, PyObject *file, int protocol)
  286. ::
  287. PyObject *
  288. PyArray_Dumps(PyObject *self, int protocol)
  289. ::
  290. int
  291. PyArray_ValidType(int type)
  292. Is the typenum valid?
  293. ::
  294. void
  295. PyArray_UpdateFlags(PyArrayObject *ret, int flagmask)
  296. Update Several Flags at once.
  297. ::
  298. PyObject *
  299. PyArray_New(PyTypeObject *subtype, int nd, npy_intp *dims, int
  300. type_num, npy_intp *strides, void *data, int itemsize, int
  301. flags, PyObject *obj)
  302. Generic new array creation routine.
  303. ::
  304. PyObject *
  305. PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int
  306. nd, npy_intp *dims, npy_intp *strides, void
  307. *data, int flags, PyObject *obj)
  308. Generic new array creation routine.
  309. steals a reference to descr (even on failure)
  310. ::
  311. PyArray_Descr *
  312. PyArray_DescrNew(PyArray_Descr *base)
  313. base cannot be NULL
  314. ::
  315. PyArray_Descr *
  316. PyArray_DescrNewFromType(int type_num)
  317. ::
  318. double
  319. PyArray_GetPriority(PyObject *obj, double default_)
  320. Get Priority from object
  321. ::
  322. PyObject *
  323. PyArray_IterNew(PyObject *obj)
  324. Get Iterator.
  325. ::
  326. PyObject *
  327. PyArray_MultiIterNew(int n, ... )
  328. Get MultiIterator,
  329. ::
  330. int
  331. PyArray_PyIntAsInt(PyObject *o)
  332. ::
  333. npy_intp
  334. PyArray_PyIntAsIntp(PyObject *o)
  335. ::
  336. int
  337. PyArray_Broadcast(PyArrayMultiIterObject *mit)
  338. ::
  339. void
  340. PyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj)
  341. Assumes contiguous
  342. ::
  343. int
  344. PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
  345. ::
  346. npy_bool
  347. PyArray_CheckStrides(int elsize, int nd, npy_intp numbytes, npy_intp
  348. offset, npy_intp *dims, npy_intp *newstrides)
  349. ::
  350. PyArray_Descr *
  351. PyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)
  352. returns a copy of the PyArray_Descr structure with the byteorder
  353. altered:
  354. no arguments: The byteorder is swapped (in all subfields as well)
  355. single argument: The byteorder is forced to the given state
  356. (in all subfields as well)
  357. Valid states: ('big', '>') or ('little' or '<')
  358. ('native', or '=')
  359. If a descr structure with | is encountered it's own
  360. byte-order is not changed but any fields are:
  361. Deep bytorder change of a data-type descriptor
  362. Leaves reference count of self unchanged --- does not DECREF self ***
  363. ::
  364. PyObject *
  365. PyArray_IterAllButAxis(PyObject *obj, int *inaxis)
  366. Get Iterator that iterates over all but one axis (don't use this with
  367. PyArray_ITER_GOTO1D). The axis will be over-written if negative
  368. with the axis having the smallest stride.
  369. ::
  370. PyObject *
  371. PyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int
  372. min_depth, int max_depth, int requires, PyObject
  373. *context)
  374. steals a reference to descr -- accepts NULL
  375. ::
  376. PyObject *
  377. PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int
  378. flags)
  379. steals reference to newtype --- acc. NULL
  380. ::
  381. PyObject *
  382. PyArray_FromInterface(PyObject *origin)
  383. ::
  384. PyObject *
  385. PyArray_FromStructInterface(PyObject *input)
  386. ::
  387. PyObject *
  388. PyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject
  389. *context)
  390. ::
  391. NPY_SCALARKIND
  392. PyArray_ScalarKind(int typenum, PyArrayObject **arr)
  393. ScalarKind
  394. Returns the scalar kind of a type number, with an
  395. optional tweak based on the scalar value itself.
  396. If no scalar is provided, it returns INTPOS_SCALAR
  397. for both signed and unsigned integers, otherwise
  398. it checks the sign of any signed integer to choose
  399. INTNEG_SCALAR when appropriate.
  400. ::
  401. int
  402. PyArray_CanCoerceScalar(int thistype, int neededtype, NPY_SCALARKIND
  403. scalar)
  404. Determines whether the data type 'thistype', with
  405. scalar kind 'scalar', can be coerced into 'neededtype'.
  406. ::
  407. PyObject *
  408. PyArray_NewFlagsObject(PyObject *obj)
  409. Get New ArrayFlagsObject
  410. ::
  411. npy_bool
  412. PyArray_CanCastScalar(PyTypeObject *from, PyTypeObject *to)
  413. See if array scalars can be cast.
  414. TODO: For NumPy 2.0, add a NPY_CASTING parameter.
  415. ::
  416. int
  417. PyArray_CompareUCS4(npy_ucs4 *s1, npy_ucs4 *s2, size_t len)
  418. ::
  419. int
  420. PyArray_RemoveSmallest(PyArrayMultiIterObject *multi)
  421. Adjusts previously broadcasted iterators so that the axis with
  422. the smallest sum of iterator strides is not iterated over.
  423. Returns dimension which is smallest in the range [0,multi->nd).
  424. A -1 is returned if multi->nd == 0.
  425. don't use with PyArray_ITER_GOTO1D because factors are not adjusted
  426. ::
  427. int
  428. PyArray_ElementStrides(PyObject *obj)
  429. ::
  430. void
  431. PyArray_Item_INCREF(char *data, PyArray_Descr *descr)
  432. ::
  433. void
  434. PyArray_Item_XDECREF(char *data, PyArray_Descr *descr)
  435. ::
  436. PyObject *
  437. PyArray_FieldNames(PyObject *fields)
  438. Return the tuple of ordered field names from a dictionary.
  439. ::
  440. PyObject *
  441. PyArray_Transpose(PyArrayObject *ap, PyArray_Dims *permute)
  442. Return Transpose.
  443. ::
  444. PyObject *
  445. PyArray_TakeFrom(PyArrayObject *self0, PyObject *indices0, int
  446. axis, PyArrayObject *out, NPY_CLIPMODE clipmode)
  447. Take
  448. ::
  449. PyObject *
  450. PyArray_PutTo(PyArrayObject *self, PyObject*values0, PyObject
  451. *indices0, NPY_CLIPMODE clipmode)
  452. Put values into an array
  453. ::
  454. PyObject *
  455. PyArray_PutMask(PyArrayObject *self, PyObject*values0, PyObject*mask0)
  456. Put values into an array according to a mask.
  457. ::
  458. PyObject *
  459. PyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis)
  460. Repeat the array.
  461. ::
  462. PyObject *
  463. PyArray_Choose(PyArrayObject *ip, PyObject *op, PyArrayObject
  464. *out, NPY_CLIPMODE clipmode)
  465. ::
  466. int
  467. PyArray_Sort(PyArrayObject *op, int axis, NPY_SORTKIND which)
  468. Sort an array in-place
  469. ::
  470. PyObject *
  471. PyArray_ArgSort(PyArrayObject *op, int axis, NPY_SORTKIND which)
  472. ArgSort an array
  473. ::
  474. PyObject *
  475. PyArray_SearchSorted(PyArrayObject *op1, PyObject *op2, NPY_SEARCHSIDE
  476. side, PyObject *perm)
  477. Search the sorted array op1 for the location of the items in op2. The
  478. result is an array of indexes, one for each element in op2, such that if
  479. the item were to be inserted in op1 just before that index the array
  480. would still be in sorted order.
  481. Parameters
  482. ----------
  483. op1 : PyArrayObject *
  484. Array to be searched, must be 1-D.
  485. op2 : PyObject *
  486. Array of items whose insertion indexes in op1 are wanted
  487. side : {NPY_SEARCHLEFT, NPY_SEARCHRIGHT}
  488. If NPY_SEARCHLEFT, return first valid insertion indexes
  489. If NPY_SEARCHRIGHT, return last valid insertion indexes
  490. perm : PyObject *
  491. Permutation array that sorts op1 (optional)
  492. Returns
  493. -------
  494. ret : PyObject *
  495. New reference to npy_intp array containing indexes where items in op2
  496. could be validly inserted into op1. NULL on error.
  497. Notes
  498. -----
  499. Binary search is used to find the indexes.
  500. ::
  501. PyObject *
  502. PyArray_ArgMax(PyArrayObject *op, int axis, PyArrayObject *out)
  503. ArgMax
  504. ::
  505. PyObject *
  506. PyArray_ArgMin(PyArrayObject *op, int axis, PyArrayObject *out)
  507. ArgMin
  508. ::
  509. PyObject *
  510. PyArray_Reshape(PyArrayObject *self, PyObject *shape)
  511. Reshape
  512. ::
  513. PyObject *
  514. PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims, NPY_ORDER
  515. order)
  516. New shape for an array
  517. ::
  518. PyObject *
  519. PyArray_Squeeze(PyArrayObject *self)
  520. return a new view of the array object with all of its unit-length
  521. dimensions squeezed out if needed, otherwise
  522. return the same array.
  523. ::
  524. PyObject *
  525. PyArray_View(PyArrayObject *self, PyArray_Descr *type, PyTypeObject
  526. *pytype)
  527. View
  528. steals a reference to type -- accepts NULL
  529. ::
  530. PyObject *
  531. PyArray_SwapAxes(PyArrayObject *ap, int a1, int a2)
  532. SwapAxes
  533. ::
  534. PyObject *
  535. PyArray_Max(PyArrayObject *ap, int axis, PyArrayObject *out)
  536. Max
  537. ::
  538. PyObject *
  539. PyArray_Min(PyArrayObject *ap, int axis, PyArrayObject *out)
  540. Min
  541. ::
  542. PyObject *
  543. PyArray_Ptp(PyArrayObject *ap, int axis, PyArrayObject *out)
  544. Ptp
  545. ::
  546. PyObject *
  547. PyArray_Mean(PyArrayObject *self, int axis, int rtype, PyArrayObject
  548. *out)
  549. Mean
  550. ::
  551. PyObject *
  552. PyArray_Trace(PyArrayObject *self, int offset, int axis1, int
  553. axis2, int rtype, PyArrayObject *out)
  554. Trace
  555. ::
  556. PyObject *
  557. PyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int
  558. axis2)
  559. Diagonal
  560. In NumPy versions prior to 1.7, this function always returned a copy of
  561. the diagonal array. In 1.7, the code has been updated to compute a view
  562. onto 'self', but it still copies this array before returning, as well as
  563. setting the internal WARN_ON_WRITE flag. In a future version, it will
  564. simply return a view onto self.
  565. ::
  566. PyObject *
  567. PyArray_Clip(PyArrayObject *self, PyObject *min, PyObject
  568. *max, PyArrayObject *out)
  569. Clip
  570. ::
  571. PyObject *
  572. PyArray_Conjugate(PyArrayObject *self, PyArrayObject *out)
  573. Conjugate
  574. ::
  575. PyObject *
  576. PyArray_Nonzero(PyArrayObject *self)
  577. Nonzero
  578. TODO: In NumPy 2.0, should make the iteration order a parameter.
  579. ::
  580. PyObject *
  581. PyArray_Std(PyArrayObject *self, int axis, int rtype, PyArrayObject
  582. *out, int variance)
  583. Set variance to 1 to by-pass square-root calculation and return variance
  584. Std
  585. ::
  586. PyObject *
  587. PyArray_Sum(PyArrayObject *self, int axis, int rtype, PyArrayObject
  588. *out)
  589. Sum
  590. ::
  591. PyObject *
  592. PyArray_CumSum(PyArrayObject *self, int axis, int rtype, PyArrayObject
  593. *out)
  594. CumSum
  595. ::
  596. PyObject *
  597. PyArray_Prod(PyArrayObject *self, int axis, int rtype, PyArrayObject
  598. *out)
  599. Prod
  600. ::
  601. PyObject *
  602. PyArray_CumProd(PyArrayObject *self, int axis, int
  603. rtype, PyArrayObject *out)
  604. CumProd
  605. ::
  606. PyObject *
  607. PyArray_All(PyArrayObject *self, int axis, PyArrayObject *out)
  608. All
  609. ::
  610. PyObject *
  611. PyArray_Any(PyArrayObject *self, int axis, PyArrayObject *out)
  612. Any
  613. ::
  614. PyObject *
  615. PyArray_Compress(PyArrayObject *self, PyObject *condition, int
  616. axis, PyArrayObject *out)
  617. Compress
  618. ::
  619. PyObject *
  620. PyArray_Flatten(PyArrayObject *a, NPY_ORDER order)
  621. Flatten
  622. ::
  623. PyObject *
  624. PyArray_Ravel(PyArrayObject *arr, NPY_ORDER order)
  625. Ravel
  626. Returns a contiguous array
  627. ::
  628. npy_intp
  629. PyArray_MultiplyList(npy_intp *l1, int n)
  630. Multiply a List
  631. ::
  632. int
  633. PyArray_MultiplyIntList(int *l1, int n)
  634. Multiply a List of ints
  635. ::
  636. void *
  637. PyArray_GetPtr(PyArrayObject *obj, npy_intp*ind)
  638. Produce a pointer into array
  639. ::
  640. int
  641. PyArray_CompareLists(npy_intp *l1, npy_intp *l2, int n)
  642. Compare Lists
  643. ::
  644. int
  645. PyArray_AsCArray(PyObject **op, void *ptr, npy_intp *dims, int
  646. nd, PyArray_Descr*typedescr)
  647. Simulate a C-array
  648. steals a reference to typedescr -- can be NULL
  649. ::
  650. int
  651. PyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode)
  652. Convert to a 1D C-array
  653. ::
  654. int
  655. PyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int
  656. typecode)
  657. Convert to a 2D C-array
  658. ::
  659. int
  660. PyArray_Free(PyObject *op, void *ptr)
  661. Free pointers created if As2D is called
  662. ::
  663. int
  664. PyArray_Converter(PyObject *object, PyObject **address)
  665. Useful to pass as converter function for O& processing in PyArgs_ParseTuple.
  666. This conversion function can be used with the "O&" argument for
  667. PyArg_ParseTuple. It will immediately return an object of array type
  668. or will convert to a NPY_ARRAY_CARRAY any other object.
  669. If you use PyArray_Converter, you must DECREF the array when finished
  670. as you get a new reference to it.
  671. ::
  672. int
  673. PyArray_IntpFromSequence(PyObject *seq, npy_intp *vals, int maxvals)
  674. PyArray_IntpFromSequence
  675. Returns the number of integers converted or -1 if an error occurred.
  676. vals must be large enough to hold maxvals
  677. ::
  678. PyObject *
  679. PyArray_Concatenate(PyObject *op, int axis)
  680. Concatenate
  681. Concatenate an arbitrary Python sequence into an array.
  682. op is a python object supporting the sequence interface.
  683. Its elements will be concatenated together to form a single
  684. multidimensional array. If axis is NPY_MAXDIMS or bigger, then
  685. each sequence object will be flattened before concatenation
  686. ::
  687. PyObject *
  688. PyArray_InnerProduct(PyObject *op1, PyObject *op2)
  689. Numeric.innerproduct(a,v)
  690. ::
  691. PyObject *
  692. PyArray_MatrixProduct(PyObject *op1, PyObject *op2)
  693. Numeric.matrixproduct(a,v)
  694. just like inner product but does the swapaxes stuff on the fly
  695. ::
  696. PyObject *
  697. PyArray_CopyAndTranspose(PyObject *op)
  698. Copy and Transpose
  699. Could deprecate this function, as there isn't a speed benefit over
  700. calling Transpose and then Copy.
  701. ::
  702. PyObject *
  703. PyArray_Correlate(PyObject *op1, PyObject *op2, int mode)
  704. Numeric.correlate(a1,a2,mode)
  705. ::
  706. int
  707. PyArray_TypestrConvert(int itemsize, int gentype)
  708. Typestr converter
  709. ::
  710. int
  711. PyArray_DescrConverter(PyObject *obj, PyArray_Descr **at)
  712. Get typenum from an object -- None goes to NPY_DEFAULT_TYPE
  713. This function takes a Python object representing a type and converts it
  714. to a the correct PyArray_Descr * structure to describe the type.
  715. Many objects can be used to represent a data-type which in NumPy is
  716. quite a flexible concept.
  717. This is the central code that converts Python objects to
  718. Type-descriptor objects that are used throughout numpy.
  719. Returns a new reference in *at, but the returned should not be
  720. modified as it may be one of the canonical immutable objects or
  721. a reference to the input obj.
  722. ::
  723. int
  724. PyArray_DescrConverter2(PyObject *obj, PyArray_Descr **at)
  725. Get typenum from an object -- None goes to NULL
  726. ::
  727. int
  728. PyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq)
  729. Get intp chunk from sequence
  730. This function takes a Python sequence object and allocates and
  731. fills in an intp array with the converted values.
  732. Remember to free the pointer seq.ptr when done using
  733. PyDimMem_FREE(seq.ptr)**
  734. ::
  735. int
  736. PyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf)
  737. Get buffer chunk from object
  738. this function takes a Python object which exposes the (single-segment)
  739. buffer interface and returns a pointer to the data segment
  740. You should increment the reference count by one of buf->base
  741. if you will hang on to a reference
  742. You only get a borrowed reference to the object. Do not free the
  743. memory...
  744. ::
  745. int
  746. PyArray_AxisConverter(PyObject *obj, int *axis)
  747. Get axis from an object (possibly None) -- a converter function,
  748. See also PyArray_ConvertMultiAxis, which also handles a tuple of axes.
  749. ::
  750. int
  751. PyArray_BoolConverter(PyObject *object, npy_bool *val)
  752. Convert an object to true / false
  753. ::
  754. int
  755. PyArray_ByteorderConverter(PyObject *obj, char *endian)
  756. Convert object to endian
  757. ::
  758. int
  759. PyArray_OrderConverter(PyObject *object, NPY_ORDER *val)
  760. Convert an object to FORTRAN / C / ANY / KEEP
  761. ::
  762. unsigned char
  763. PyArray_EquivTypes(PyArray_Descr *type1, PyArray_Descr *type2)
  764. This function returns true if the two typecodes are
  765. equivalent (same basic kind and same itemsize).
  766. ::
  767. PyObject *
  768. PyArray_Zeros(int nd, npy_intp *dims, PyArray_Descr *type, int
  769. is_f_order)
  770. Zeros
  771. steal a reference
  772. accepts NULL type
  773. ::
  774. PyObject *
  775. PyArray_Empty(int nd, npy_intp *dims, PyArray_Descr *type, int
  776. is_f_order)
  777. Empty
  778. accepts NULL type
  779. steals referenct to type
  780. ::
  781. PyObject *
  782. PyArray_Where(PyObject *condition, PyObject *x, PyObject *y)
  783. Where
  784. ::
  785. PyObject *
  786. PyArray_Arange(double start, double stop, double step, int type_num)
  787. Arange,
  788. ::
  789. PyObject *
  790. PyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject
  791. *step, PyArray_Descr *dtype)
  792. ArangeObj,
  793. this doesn't change the references
  794. ::
  795. int
  796. PyArray_SortkindConverter(PyObject *obj, NPY_SORTKIND *sortkind)
  797. Convert object to sort kind
  798. ::
  799. PyObject *
  800. PyArray_LexSort(PyObject *sort_keys, int axis)
  801. LexSort an array providing indices that will sort a collection of arrays
  802. lexicographically. The first key is sorted on first, followed by the second key
  803. -- requires that arg"merge"sort is available for each sort_key
  804. Returns an index array that shows the indexes for the lexicographic sort along
  805. the given axis.
  806. ::
  807. PyObject *
  808. PyArray_Round(PyArrayObject *a, int decimals, PyArrayObject *out)
  809. Round
  810. ::
  811. unsigned char
  812. PyArray_EquivTypenums(int typenum1, int typenum2)
  813. ::
  814. int
  815. PyArray_RegisterDataType(PyArray_Descr *descr)
  816. Register Data type
  817. Does not change the reference count of descr
  818. ::
  819. int
  820. PyArray_RegisterCastFunc(PyArray_Descr *descr, int
  821. totype, PyArray_VectorUnaryFunc *castfunc)
  822. Register Casting Function
  823. Replaces any function currently stored.
  824. ::
  825. int
  826. PyArray_RegisterCanCast(PyArray_Descr *descr, int
  827. totype, NPY_SCALARKIND scalar)
  828. Register a type number indicating that a descriptor can be cast
  829. to it safely
  830. ::
  831. void
  832. PyArray_InitArrFuncs(PyArray_ArrFuncs *f)
  833. Initialize arrfuncs to NULL
  834. ::
  835. PyObject *
  836. PyArray_IntTupleFromIntp(int len, npy_intp *vals)
  837. PyArray_IntTupleFromIntp
  838. ::
  839. int
  840. PyArray_TypeNumFromName(char *str)
  841. ::
  842. int
  843. PyArray_ClipmodeConverter(PyObject *object, NPY_CLIPMODE *val)
  844. Convert an object to NPY_RAISE / NPY_CLIP / NPY_WRAP
  845. ::
  846. int
  847. PyArray_OutputConverter(PyObject *object, PyArrayObject **address)
  848. Useful to pass as converter function for O& processing in
  849. PyArgs_ParseTuple for output arrays
  850. ::
  851. PyObject *
  852. PyArray_BroadcastToShape(PyObject *obj, npy_intp *dims, int nd)
  853. Get Iterator broadcast to a particular shape
  854. ::
  855. void
  856. _PyArray_SigintHandler(int signum)
  857. ::
  858. void*
  859. _PyArray_GetSigintBuf(void )
  860. ::
  861. int
  862. PyArray_DescrAlignConverter(PyObject *obj, PyArray_Descr **at)
  863. Get type-descriptor from an object forcing alignment if possible
  864. None goes to DEFAULT type.
  865. any object with the .fields attribute and/or .itemsize attribute (if the
  866. .fields attribute does not give the total size -- i.e. a partial record
  867. naming). If itemsize is given it must be >= size computed from fields
  868. The .fields attribute must return a convertible dictionary if present.
  869. Result inherits from NPY_VOID.
  870. ::
  871. int
  872. PyArray_DescrAlignConverter2(PyObject *obj, PyArray_Descr **at)
  873. Get type-descriptor from an object forcing alignment if possible
  874. None goes to NULL.
  875. ::
  876. int
  877. PyArray_SearchsideConverter(PyObject *obj, void *addr)
  878. Convert object to searchsorted side
  879. ::
  880. PyObject *
  881. PyArray_CheckAxis(PyArrayObject *arr, int *axis, int flags)
  882. PyArray_CheckAxis
  883. check that axis is valid
  884. convert 0-d arrays to 1-d arrays
  885. ::
  886. npy_intp
  887. PyArray_OverflowMultiplyList(npy_intp *l1, int n)
  888. Multiply a List of Non-negative numbers with over-flow detection.
  889. ::
  890. int
  891. PyArray_CompareString(char *s1, char *s2, size_t len)
  892. ::
  893. PyObject *
  894. PyArray_MultiIterFromObjects(PyObject **mps, int n, int nadd, ... )
  895. Get MultiIterator from array of Python objects and any additional
  896. PyObject **mps -- array of PyObjects
  897. int n - number of PyObjects in the array
  898. int nadd - number of additional arrays to include in the iterator.
  899. Returns a multi-iterator object.
  900. ::
  901. int
  902. PyArray_GetEndianness(void )
  903. ::
  904. unsigned int
  905. PyArray_GetNDArrayCFeatureVersion(void )
  906. Returns the built-in (at compilation time) C API version
  907. ::
  908. PyObject *
  909. PyArray_Correlate2(PyObject *op1, PyObject *op2, int mode)
  910. correlate(a1,a2,mode)
  911. This function computes the usual correlation (correlate(a1, a2) !=
  912. correlate(a2, a1), and conjugate the second argument for complex inputs
  913. ::
  914. PyObject*
  915. PyArray_NeighborhoodIterNew(PyArrayIterObject *x, npy_intp
  916. *bounds, int mode, PyArrayObject*fill)
  917. A Neighborhood Iterator object.
  918. ::
  919. void
  920. PyArray_SetDatetimeParseFunction(PyObject *op)
  921. This function is scheduled to be removed
  922. TO BE REMOVED - NOT USED INTERNALLY.
  923. ::
  924. void
  925. PyArray_DatetimeToDatetimeStruct(npy_datetime val, NPY_DATETIMEUNIT
  926. fr, npy_datetimestruct *result)
  927. Fill the datetime struct from the value and resolution unit.
  928. TO BE REMOVED - NOT USED INTERNALLY.
  929. ::
  930. void
  931. PyArray_TimedeltaToTimedeltaStruct(npy_timedelta val, NPY_DATETIMEUNIT
  932. fr, npy_timedeltastruct *result)
  933. Fill the timedelta struct from the timedelta value and resolution unit.
  934. TO BE REMOVED - NOT USED INTERNALLY.
  935. ::
  936. npy_datetime
  937. PyArray_DatetimeStructToDatetime(NPY_DATETIMEUNIT
  938. fr, npy_datetimestruct *d)
  939. Create a datetime value from a filled datetime struct and resolution unit.
  940. TO BE REMOVED - NOT USED INTERNALLY.
  941. ::
  942. npy_datetime
  943. PyArray_TimedeltaStructToTimedelta(NPY_DATETIMEUNIT
  944. fr, npy_timedeltastruct *d)
  945. Create a timdelta value from a filled timedelta struct and resolution unit.
  946. TO BE REMOVED - NOT USED INTERNALLY.
  947. ::
  948. NpyIter *
  949. NpyIter_New(PyArrayObject *op, npy_uint32 flags, NPY_ORDER
  950. order, NPY_CASTING casting, PyArray_Descr*dtype)
  951. Allocate a new iterator for one array object.
  952. ::
  953. NpyIter *
  954. NpyIter_MultiNew(int nop, PyArrayObject **op_in, npy_uint32
  955. flags, NPY_ORDER order, NPY_CASTING
  956. casting, npy_uint32 *op_flags, PyArray_Descr
  957. **op_request_dtypes)
  958. Allocate a new iterator for more than one array object, using
  959. standard NumPy broadcasting rules and the default buffer size.
  960. ::
  961. NpyIter *
  962. NpyIter_AdvancedNew(int nop, PyArrayObject **op_in, npy_uint32
  963. flags, NPY_ORDER order, NPY_CASTING
  964. casting, npy_uint32 *op_flags, PyArray_Descr
  965. **op_request_dtypes, int oa_ndim, int
  966. **op_axes, npy_intp *itershape, npy_intp
  967. buffersize)
  968. Allocate a new iterator for multiple array objects, and advanced
  969. options for controlling the broadcasting, shape, and buffer size.
  970. ::
  971. NpyIter *
  972. NpyIter_Copy(NpyIter *iter)
  973. Makes a copy of the iterator
  974. ::
  975. int
  976. NpyIter_Deallocate(NpyIter *iter)
  977. Deallocate an iterator
  978. ::
  979. npy_bool
  980. NpyIter_HasDelayedBufAlloc(NpyIter *iter)
  981. Whether the buffer allocation is being delayed
  982. ::
  983. npy_bool
  984. NpyIter_HasExternalLoop(NpyIter *iter)
  985. Whether the iterator handles the inner loop
  986. ::
  987. int
  988. NpyIter_EnableExternalLoop(NpyIter *iter)
  989. Removes the inner loop handling (so HasExternalLoop returns true)
  990. ::
  991. npy_intp *
  992. NpyIter_GetInnerStrideArray(NpyIter *iter)
  993. Get the array of strides for the inner loop (when HasExternalLoop is true)
  994. This function may be safely called without holding the Python GIL.
  995. ::
  996. npy_intp *
  997. NpyIter_GetInnerLoopSizePtr(NpyIter *iter)
  998. Get a pointer to the size of the inner loop (when HasExternalLoop is true)
  999. This function may be safely called without holding the Python GIL.
  1000. ::
  1001. int
  1002. NpyIter_Reset(NpyIter *iter, char **errmsg)
  1003. Resets the iterator to its initial state
  1004. If errmsg is non-NULL, it should point to a variable which will
  1005. receive the error message, and no Python exception will be set.
  1006. This is so that the function can be called from code not holding
  1007. the GIL.
  1008. ::
  1009. int
  1010. NpyIter_ResetBasePointers(NpyIter *iter, char **baseptrs, char
  1011. **errmsg)
  1012. Resets the iterator to its initial state, with new base data pointers.
  1013. This function requires great caution.
  1014. If errmsg is non-NULL, it should point to a variable which will
  1015. receive the error message, and no Python exception will be set.
  1016. This is so that the function can be called from code not holding
  1017. the GIL.
  1018. ::
  1019. int
  1020. NpyIter_ResetToIterIndexRange(NpyIter *iter, npy_intp istart, npy_intp
  1021. iend, char **errmsg)
  1022. Resets the iterator to a new iterator index range
  1023. If errmsg is non-NULL, it should point to a variable which will
  1024. receive the error message, and no Python exception will be set.
  1025. This is so that the function can be called from code not holding
  1026. the GIL.
  1027. ::
  1028. int
  1029. NpyIter_GetNDim(NpyIter *iter)
  1030. Gets the number of dimensions being iterated
  1031. ::
  1032. int
  1033. NpyIter_GetNOp(NpyIter *iter)
  1034. Gets the number of operands being iterated
  1035. ::
  1036. NpyIter_IterNextFunc *
  1037. NpyIter_GetIterNext(NpyIter *iter, char **errmsg)
  1038. Compute the specialized iteration function for an iterator
  1039. If errmsg is non-NULL, it should point to a variable which will
  1040. receive the error message, and no Python exception will be set.
  1041. This is so that the function can be called from code not holding
  1042. the GIL.
  1043. ::
  1044. npy_intp
  1045. NpyIter_GetIterSize(NpyIter *iter)
  1046. Gets the number of elements being iterated
  1047. ::
  1048. void
  1049. NpyIter_GetIterIndexRange(NpyIter *iter, npy_intp *istart, npy_intp
  1050. *iend)
  1051. Gets the range of iteration indices being iterated
  1052. ::
  1053. npy_intp
  1054. NpyIter_GetIterIndex(NpyIter *iter)
  1055. Gets the current iteration index
  1056. ::
  1057. int
  1058. NpyIter_GotoIterIndex(NpyIter *iter, npy_intp iterindex)
  1059. Sets the iterator position to the specified iterindex,
  1060. which matches the iteration order of the iterator.
  1061. Returns NPY_SUCCEED on success, NPY_FAIL on failure.
  1062. ::
  1063. npy_bool
  1064. NpyIter_HasMultiIndex(NpyIter *iter)
  1065. Whether the iterator is tracking a multi-index
  1066. ::
  1067. int
  1068. NpyIter_GetShape(NpyIter *iter, npy_intp *outshape)
  1069. Gets the broadcast shape if a multi-index is being tracked by the iterator,
  1070. otherwise gets the shape of the iteration as Fortran-order
  1071. (fastest-changing index first).
  1072. The reason Fortran-order is returned when a multi-index
  1073. is not enabled is that this is providing a direct view into how
  1074. the iterator traverses the n-dimensional space. The iterator organizes
  1075. its memory from fastest index to slowest index, and when
  1076. a multi-index is enabled, it uses a permutation to recover the original
  1077. order.
  1078. Returns NPY_SUCCEED or NPY_FAIL.
  1079. ::
  1080. NpyIter_GetMultiIndexFunc *
  1081. NpyIter_GetGetMultiIndex(NpyIter *iter, char **errmsg)
  1082. Compute a specialized get_multi_index function for the iterator
  1083. If errmsg is non-NULL, it should point to a variable which will
  1084. receive the error message, and no Python exception will be set.
  1085. This is so that the function can be called from code not holding
  1086. the GIL.
  1087. ::
  1088. int
  1089. NpyIter_GotoMultiIndex(NpyIter *iter, npy_intp *multi_index)
  1090. Sets the iterator to the specified multi-index, which must have the
  1091. correct number of entries for 'ndim'. It is only valid
  1092. when NPY_ITER_MULTI_INDEX was passed to the constructor. This operation
  1093. fails if the multi-index is out of bounds.
  1094. Returns NPY_SUCCEED on success, NPY_FAIL on failure.
  1095. ::
  1096. int
  1097. NpyIter_RemoveMultiIndex(NpyIter *iter)
  1098. Removes multi-index support from an iterator.
  1099. Returns NPY_SUCCEED or NPY_FAIL.
  1100. ::
  1101. npy_bool
  1102. NpyIter_HasIndex(NpyIter *iter)
  1103. Whether the iterator is tracking an index
  1104. ::
  1105. npy_bool
  1106. NpyIter_IsBuffered(NpyIter *iter)
  1107. Whether the iterator is buffered
  1108. ::
  1109. npy_bool
  1110. NpyIter_IsGrowInner(NpyIter *iter)
  1111. Whether the inner loop can grow if buffering is unneeded
  1112. ::
  1113. npy_intp
  1114. NpyIter_GetBufferSize(NpyIter *iter)
  1115. Gets the size of the buffer, or 0 if buffering is not enabled
  1116. ::
  1117. npy_intp *
  1118. NpyIter_GetIndexPtr(NpyIter *iter)
  1119. Get a pointer to the index, if it is being tracked
  1120. ::
  1121. int
  1122. NpyIter_GotoIndex(NpyIter *iter, npy_intp flat_index)
  1123. If the iterator is tracking an index, sets the iterator
  1124. to the specified index.
  1125. Returns NPY_SUCCEED on success, NPY_FAIL on failure.
  1126. ::
  1127. char **
  1128. NpyIter_GetDataPtrArray(NpyIter *iter)
  1129. Get the array of data pointers (1 per object being iterated)
  1130. This function may be safely called without holding the Python GIL.
  1131. ::
  1132. PyArray_Descr **
  1133. NpyIter_GetDescrArray(NpyIter *iter)
  1134. Get the array of data type pointers (1 per object being iterated)
  1135. ::
  1136. PyArrayObject **
  1137. NpyIter_GetOperandArray(NpyIter *iter)
  1138. Get the array of objects being iterated
  1139. ::
  1140. PyArrayObject *
  1141. NpyIter_GetIterView(NpyIter *iter, npy_intp i)
  1142. Returns a view to the i-th object with the iterator's internal axes
  1143. ::
  1144. void
  1145. NpyIter_GetReadFlags(NpyIter *iter, char *outreadflags)
  1146. Gets an array of read flags (1 per object being iterated)
  1147. ::
  1148. void
  1149. NpyIter_GetWriteFlags(NpyIter *iter, char *outwriteflags)
  1150. Gets an array of write flags (1 per object being iterated)
  1151. ::
  1152. void
  1153. NpyIter_DebugPrint(NpyIter *iter)
  1154. For debugging
  1155. ::
  1156. npy_bool
  1157. NpyIter_IterationNeedsAPI(NpyIter *iter)
  1158. Whether the iteration loop, and in particular the iternext()
  1159. function, needs API access. If this is true, the GIL must
  1160. be retained while iterating.
  1161. ::
  1162. void
  1163. NpyIter_GetInnerFixedStrideArray(NpyIter *iter, npy_intp *out_strides)
  1164. Get an array of strides which are fixed. Any strides which may
  1165. change during iteration receive the value NPY_MAX_INTP. Once
  1166. the iterator is ready to iterate, call this to get the strides
  1167. which will always be fixed in the inner loop, then choose optimized
  1168. inner loop functions which take advantage of those fixed strides.
  1169. This function may be safely called without holding the Python GIL.
  1170. ::
  1171. int
  1172. NpyIter_RemoveAxis(NpyIter *iter, int axis)
  1173. Removes an axis from iteration. This requires that NPY_ITER_MULTI_INDEX
  1174. was set for iterator creation, and does not work if buffering is
  1175. enabled. This function also resets the iterator to its initial state.
  1176. Returns NPY_SUCCEED or NPY_FAIL.
  1177. ::
  1178. npy_intp *
  1179. NpyIter_GetAxisStrideArray(NpyIter *iter, int axis)
  1180. Gets the array of strides for the specified axis.
  1181. If the iterator is tracking a multi-index, gets the strides
  1182. for the axis specified, otherwise gets the strides for
  1183. the iteration axis as Fortran order (fastest-changing axis first).
  1184. Returns NULL if an error occurs.
  1185. ::
  1186. npy_bool
  1187. NpyIter_RequiresBuffering(NpyIter *iter)
  1188. Whether the iteration could be done with no buffering.
  1189. ::
  1190. char **
  1191. NpyIter_GetInitialDataPtrArray(NpyIter *iter)
  1192. Get the array of data pointers (1 per object being iterated),
  1193. directly into the arrays (never pointing to a buffer), for starting
  1194. unbuffered iteration. This always returns the addresses for the
  1195. iterator position as reset to iterator index 0.
  1196. These pointers are different from the pointers accepted by
  1197. NpyIter_ResetBasePointers, because the direction along some
  1198. axes may have been reversed, requiring base offsets.
  1199. This function may be safely called without holding the Python GIL.
  1200. ::
  1201. int
  1202. NpyIter_CreateCompatibleStrides(NpyIter *iter, npy_intp
  1203. itemsize, npy_intp *outstrides)
  1204. Builds a set of strides which are the same as the strides of an
  1205. output array created using the NPY_ITER_ALLOCATE flag, where NULL
  1206. was passed for op_axes. This is for data packed contiguously,
  1207. but not necessarily in C or Fortran order. This should be used
  1208. together with NpyIter_GetShape and NpyIter_GetNDim.
  1209. A use case for this function is to match the shape and layout of
  1210. the iterator and tack on one or more dimensions. For example,
  1211. in order to generate a vector per input value for a numerical gradient,
  1212. you pass in ndim*itemsize for itemsize, then add another dimension to
  1213. the end with size ndim and stride itemsize. To do the Hessian matrix,
  1214. you do the same thing but add two dimensions, or take advantage of
  1215. the symmetry and pack it into 1 dimension with a particular encoding.
  1216. This function may only be called if the iterator is tracking a multi-index
  1217. and if NPY_ITER_DONT_NEGATE_STRIDES was used to prevent an axis from
  1218. being iterated in reverse order.
  1219. If an array is created with this method, simply adding 'itemsize'
  1220. for each iteration will traverse the new array matching the
  1221. iterator.
  1222. Returns NPY_SUCCEED or NPY_FAIL.
  1223. ::
  1224. int
  1225. PyArray_CastingConverter(PyObject *obj, NPY_CASTING *casting)
  1226. Convert any Python object, *obj*, to an NPY_CASTING enum.
  1227. ::
  1228. npy_intp
  1229. PyArray_CountNonzero(PyArrayObject *self)
  1230. Counts the number of non-zero elements in the array.
  1231. Returns -1 on error.
  1232. ::
  1233. PyArray_Descr *
  1234. PyArray_PromoteTypes(PyArray_Descr *type1, PyArray_Descr *type2)
  1235. Produces the smallest size and lowest kind type to which both
  1236. input types can be cast.
  1237. ::
  1238. PyArray_Descr *
  1239. PyArray_MinScalarType(PyArrayObject *arr)
  1240. If arr is a scalar (has 0 dimensions) with a built-in number data type,
  1241. finds the smallest type size/kind which can still represent its data.
  1242. Otherwise, returns the array's data type.
  1243. ::
  1244. PyArray_Descr *
  1245. PyArray_ResultType(npy_intp narrs, PyArrayObject **arr, npy_intp
  1246. ndtypes, PyArray_Descr **dtypes)
  1247. Produces the result type of a bunch of inputs, using the UFunc
  1248. type promotion rules. Use this function when you have a set of
  1249. input arrays, and need to determine an output array dtype.
  1250. If all the inputs are scalars (have 0 dimensions) or the maximum "kind"
  1251. of the scalars is greater than the maximum "kind" of the arrays, does
  1252. a regular type promotion.
  1253. Otherwise, does a type promotion on the MinScalarType
  1254. of all the inputs. Data types passed directly are treated as array
  1255. types.
  1256. ::
  1257. npy_bool
  1258. PyArray_CanCastArrayTo(PyArrayObject *arr, PyArray_Descr
  1259. *to, NPY_CASTING casting)
  1260. Returns 1 if the array object may be cast to the given data type using
  1261. the casting rule, 0 otherwise. This differs from PyArray_CanCastTo in
  1262. that it handles scalar arrays (0 dimensions) specially, by checking
  1263. their value.
  1264. ::
  1265. npy_bool
  1266. PyArray_CanCastTypeTo(PyArray_Descr *from, PyArray_Descr
  1267. *to, NPY_CASTING casting)
  1268. Returns true if data of type 'from' may be cast to data of type
  1269. 'to' according to the rule 'casting'.
  1270. ::
  1271. PyArrayObject *
  1272. PyArray_EinsteinSum(char *subscripts, npy_intp nop, PyArrayObject
  1273. **op_in, PyArray_Descr *dtype, NPY_ORDER
  1274. order, NPY_CASTING casting, PyArrayObject *out)
  1275. This function provides summation of array elements according to
  1276. the Einstein summation convention. For example:
  1277. - trace(a) -> einsum("ii", a)
  1278. - transpose(a) -> einsum("ji", a)
  1279. - multiply(a,b) -> einsum(",", a, b)
  1280. - inner(a,b) -> einsum("i,i", a, b)
  1281. - outer(a,b) -> einsum("i,j", a, b)
  1282. - matvec(a,b) -> einsum("ij,j", a, b)
  1283. - matmat(a,b) -> einsum("ij,jk", a, b)
  1284. subscripts: The string of subscripts for einstein summation.
  1285. nop: The number of operands
  1286. op_in: The array of operands
  1287. dtype: Either NULL, or the data type to force the calculation as.
  1288. order: The order for the calculation/the output axes.
  1289. casting: What kind of casts should be permitted.
  1290. out: Either NULL, or an array into which the output should be placed.
  1291. By default, the labels get placed in alphabetical order
  1292. at the end of the output. So, if c = einsum("i,j", a, b)
  1293. then c[i,j] == a[i]*b[j], but if c = einsum("j,i", a, b)
  1294. then c[i,j] = a[j]*b[i].
  1295. Alternatively, you can control the output order or prevent
  1296. an axis from being summed/force an axis to be summed by providing
  1297. indices for the output. This allows us to turn 'trace' into
  1298. 'diag', for example.
  1299. - diag(a) -> einsum("ii->i", a)
  1300. - sum(a, axis=0) -> einsum("i...->", a)
  1301. Subscripts at the beginning and end may be specified by
  1302. putting an ellipsis "..." in the middle. For example,
  1303. the function einsum("i...i", a) takes the diagonal of
  1304. the first and last dimensions of the operand, and
  1305. einsum("ij...,jk...->ik...") takes the matrix product using
  1306. the first two indices of each operand instead of the last two.
  1307. When there is only one operand, no axes being summed, and
  1308. no output parameter, this function returns a view
  1309. into the operand instead of making a copy.
  1310. ::
  1311. PyObject *
  1312. PyArray_NewLikeArray(PyArrayObject *prototype, NPY_ORDER
  1313. order, PyArray_Descr *dtype, int subok)
  1314. Creates a new array with the same shape as the provided one,
  1315. with possible memory layout order and data type changes.
  1316. prototype - The array the new one should be like.
  1317. order - NPY_CORDER - C-contiguous result.
  1318. NPY_FORTRANORDER - Fortran-contiguous result.
  1319. NPY_ANYORDER - Fortran if prototype is Fortran, C otherwise.
  1320. NPY_KEEPORDER - Keeps the axis ordering of prototype.
  1321. dtype - If not NULL, overrides the data type of the result.
  1322. subok - If 1, use the prototype's array subtype, otherwise
  1323. always create a base-class array.
  1324. NOTE: If dtype is not NULL, steals the dtype reference.
  1325. ::
  1326. int
  1327. PyArray_GetArrayParamsFromObject(PyObject *op, PyArray_Descr
  1328. *requested_dtype, npy_bool
  1329. writeable, PyArray_Descr
  1330. **out_dtype, int *out_ndim, npy_intp
  1331. *out_dims, PyArrayObject
  1332. **out_arr, PyObject *context)
  1333. Retrieves the array parameters for viewing/converting an arbitrary
  1334. PyObject* to a NumPy array. This allows the "innate type and shape"
  1335. of Python list-of-lists to be discovered without
  1336. actually converting to an array.
  1337. In some cases, such as structured arrays and the __array__ interface,
  1338. a data type needs to be used to make sense of the object. When
  1339. this is needed, provide a Descr for 'requested_dtype', otherwise
  1340. provide NULL. This reference is not stolen. Also, if the requested
  1341. dtype doesn't modify the interpretation of the input, out_dtype will
  1342. still get the "innate" dtype of the object, not the dtype passed
  1343. in 'requested_dtype'.
  1344. If writing to the value in 'op' is desired, set the boolean
  1345. 'writeable' to 1. This raises an error when 'op' is a scalar, list
  1346. of lists, or other non-writeable 'op'.
  1347. Result: When success (0 return value) is returned, either out_arr
  1348. is filled with a non-NULL PyArrayObject and
  1349. the rest of the parameters are untouched, or out_arr is
  1350. filled with NULL, and the rest of the parameters are
  1351. filled.
  1352. Typical usage:
  1353. PyArrayObject *arr = NULL;
  1354. PyArray_Descr *dtype = NULL;
  1355. int ndim = 0;
  1356. npy_intp dims[NPY_MAXDIMS];
  1357. if (PyArray_GetArrayParamsFromObject(op, NULL, 1, &dtype,
  1358. &ndim, dims, &arr, NULL) < 0) {
  1359. return NULL;
  1360. }
  1361. if (arr == NULL) {
  1362. ... validate/change dtype, validate flags, ndim, etc ...
  1363. // Could make custom strides here too
  1364. arr = PyArray_NewFromDescr(&PyArray_Type, dtype, ndim,
  1365. dims, NULL,
  1366. is_f_order ? NPY_ARRAY_F_CONTIGUOUS : 0,
  1367. NULL);
  1368. if (arr == NULL) {
  1369. return NULL;
  1370. }
  1371. if (PyArray_CopyObject(arr, op) < 0) {
  1372. Py_DECREF(arr);
  1373. return NULL;
  1374. }
  1375. }
  1376. else {
  1377. ... in this case the other parameters weren't filled, just
  1378. validate and possibly copy arr itself ...
  1379. }
  1380. ... use arr ...
  1381. ::
  1382. int
  1383. PyArray_ConvertClipmodeSequence(PyObject *object, NPY_CLIPMODE
  1384. *modes, int n)
  1385. Convert an object to an array of n NPY_CLIPMODE values.
  1386. This is intended to be used in functions where a different mode
  1387. could be applied to each axis, like in ravel_multi_index.
  1388. ::
  1389. PyObject *
  1390. PyArray_MatrixProduct2(PyObject *op1, PyObject
  1391. *op2, PyArrayObject*out)
  1392. Numeric.matrixproduct2(a,v,out)
  1393. just like inner product but does the swapaxes stuff on the fly
  1394. ::
  1395. npy_bool
  1396. NpyIter_IsFirstVisit(NpyIter *iter, int iop)
  1397. Checks to see whether this is the first time the elements
  1398. of the specified reduction operand which the iterator points at are
  1399. being seen for the first time. The function returns
  1400. a reasonable answer for reduction operands and when buffering is
  1401. disabled. The answer may be incorrect for buffered non-reduction
  1402. operands.
  1403. This function is intended to be used in EXTERNAL_LOOP mode only,
  1404. and will produce some wrong answers when that mode is not enabled.
  1405. If this function returns true, the caller should also
  1406. check the inner loop stride of the operand, because if
  1407. that stride is 0, then only the first element of the innermost
  1408. external loop is being visited for the first time.
  1409. WARNING: For performance reasons, 'iop' is not bounds-checked,
  1410. it is not confirmed that 'iop' is actually a reduction
  1411. operand, and it is not confirmed that EXTERNAL_LOOP
  1412. mode is enabled. These checks are the responsibility of
  1413. the caller, and should be done outside of any inner loops.
  1414. ::
  1415. int
  1416. PyArray_SetBaseObject(PyArrayObject *arr, PyObject *obj)
  1417. Sets the 'base' attribute of the array. This steals a reference
  1418. to 'obj'.
  1419. Returns 0 on success, -1 on failure.
  1420. ::
  1421. void
  1422. PyArray_CreateSortedStridePerm(int ndim, npy_intp
  1423. *strides, npy_stride_sort_item
  1424. *out_strideperm)
  1425. This function populates the first ndim elements
  1426. of strideperm with sorted descending by their absolute values.
  1427. For example, the stride array (4, -2, 12) becomes
  1428. [(2, 12), (0, 4), (1, -2)].
  1429. ::
  1430. void
  1431. PyArray_RemoveAxesInPlace(PyArrayObject *arr, npy_bool *flags)
  1432. Removes the axes flagged as True from the array,
  1433. modifying it in place. If an axis flagged for removal
  1434. has a shape entry bigger than one, this effectively selects
  1435. index zero for that axis.
  1436. WARNING: If an axis flagged for removal has a shape equal to zero,
  1437. the array will point to invalid memory. The caller must
  1438. validate this!
  1439. If an axis flagged for removal has a shape larger then one,
  1440. the aligned flag (and in the future the contiguous flags),
  1441. may need explicite update.
  1442. (check also NPY_RELAXED_STRIDES_CHECKING)
  1443. For example, this can be used to remove the reduction axes
  1444. from a reduction result once its computation is complete.
  1445. ::
  1446. void
  1447. PyArray_DebugPrint(PyArrayObject *obj)
  1448. Prints the raw data of the ndarray in a form useful for debugging
  1449. low-level C issues.
  1450. ::
  1451. int
  1452. PyArray_FailUnlessWriteable(PyArrayObject *obj, const char *name)
  1453. This function does nothing if obj is writeable, and raises an exception
  1454. (and returns -1) if obj is not writeable. It may also do other
  1455. house-keeping, such as issuing warnings on arrays which are transitioning
  1456. to become views. Always call this function at some point before writing to
  1457. an array.
  1458. 'name' is a name for the array, used to give better error
  1459. messages. Something like "assignment destination", "output array", or even
  1460. just "array".
  1461. ::
  1462. int
  1463. PyArray_SetUpdateIfCopyBase(PyArrayObject *arr, PyArrayObject *base)
  1464. Precondition: 'arr' is a copy of 'base' (though possibly with different
  1465. strides, ordering, etc.). This function sets the UPDATEIFCOPY flag and the
  1466. ->base pointer on 'arr', so that when 'arr' is destructed, it will copy any
  1467. changes back to 'base'.
  1468. Steals a reference to 'base'.
  1469. Returns 0 on success, -1 on failure.
  1470. ::
  1471. void *
  1472. PyDataMem_NEW(size_t size)
  1473. Allocates memory for array data.
  1474. ::
  1475. void
  1476. PyDataMem_FREE(void *ptr)
  1477. Free memory for array data.
  1478. ::
  1479. void *
  1480. PyDataMem_RENEW(void *ptr, size_t size)
  1481. Reallocate/resize memory for array data.
  1482. ::
  1483. PyDataMem_EventHookFunc *
  1484. PyDataMem_SetEventHook(PyDataMem_EventHookFunc *newhook, void
  1485. *user_data, void **old_data)
  1486. Sets the allocation event hook for numpy array data.
  1487. Takes a PyDataMem_EventHookFunc *, which has the signature:
  1488. void hook(void *old, void *new, size_t size, void *user_data).
  1489. Also takes a void *user_data, and void **old_data.
  1490. Returns a pointer to the previous hook or NULL. If old_data is
  1491. non-NULL, the previous user_data pointer will be copied to it.
  1492. If not NULL, hook will be called at the end of each PyDataMem_NEW/FREE/RENEW:
  1493. result = PyDataMem_NEW(size) -> (*hook)(NULL, result, size, user_data)
  1494. PyDataMem_FREE(ptr) -> (*hook)(ptr, NULL, 0, user_data)
  1495. result = PyDataMem_RENEW(ptr, size) -> (*hook)(ptr, result, size, user_data)
  1496. When the hook is called, the GIL will be held by the calling
  1497. thread. The hook should be written to be reentrant, if it performs
  1498. operations that might cause new allocation events (such as the
  1499. creation/descruction numpy objects, or creating/destroying Python
  1500. objects which might cause a gc)
  1501. ::
  1502. void
  1503. PyArray_MapIterSwapAxes(PyArrayMapIterObject *mit, PyArrayObject
  1504. **ret, int getmap)
  1505. ::
  1506. PyObject *
  1507. PyArray_MapIterArray(PyArrayObject *a, PyObject *index)
  1508. Use advanced indexing to iterate an array. Please note
  1509. that most of this public API is currently not guaranteed
  1510. to stay the same between versions. If you plan on using
  1511. it, please consider adding more utility functions here
  1512. to accommodate new features.
  1513. ::
  1514. void
  1515. PyArray_MapIterNext(PyArrayMapIterObject *mit)
  1516. This function needs to update the state of the map iterator
  1517. and point mit->dataptr to the memory-location of the next object
  1518. Note that this function never handles an extra operand but provides
  1519. compatibility for an old (exposed) API.
  1520. ::
  1521. int
  1522. PyArray_Partition(PyArrayObject *op, PyArrayObject *ktharray, int
  1523. axis, NPY_SELECTKIND which)
  1524. Partition an array in-place
  1525. ::
  1526. PyObject *
  1527. PyArray_ArgPartition(PyArrayObject *op, PyArrayObject *ktharray, int
  1528. axis, NPY_SELECTKIND which)
  1529. ArgPartition an array
  1530. ::
  1531. int
  1532. PyArray_SelectkindConverter(PyObject *obj, NPY_SELECTKIND *selectkind)
  1533. Convert object to select kind
  1534. ::
  1535. void *
  1536. PyDataMem_NEW_ZEROED(size_t size, size_t elsize)
  1537. Allocates zeroed memory for array data.
  1538. ::
  1539. int
  1540. PyArray_CheckAnyScalarExact(PyObject *obj)
  1541. return true an object is exactly a numpy scalar