MCPcopy Create free account
hub / github.com/numpy/numpy / PyArray_INCREF

Function PyArray_INCREF

numpy/core/src/multiarray/refcount.c:242–294  ·  view source on GitHub ↗

Used for arrays of python objects to increment the reference count of */ every python object in the array. */ NUMPY_API For object arrays, increment all internal references. */

Source from the content-addressed store, hash-verified

240 For object arrays, increment all internal references.
241*/
242NPY_NO_EXPORT int
243PyArray_INCREF(PyArrayObject *mp)
244{
245 npy_intp i, n;
246 PyObject **data;
247 PyObject *temp;
248 PyArrayIterObject *it;
249
250 if (!PyDataType_REFCHK(PyArray_DESCR(mp))) {
251 return 0;
252 }
253 if (PyArray_DESCR(mp)->type_num != NPY_OBJECT) {
254 it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);
255 if (it == NULL) {
256 return -1;
257 }
258 while(it->index < it->size) {
259 PyArray_Item_INCREF(it->dataptr, PyArray_DESCR(mp));
260 PyArray_ITER_NEXT(it);
261 }
262 Py_DECREF(it);
263 return 0;
264 }
265
266 if (PyArray_ISONESEGMENT(mp)) {
267 data = (PyObject **)PyArray_DATA(mp);
268 n = PyArray_SIZE(mp);
269 if (PyArray_ISALIGNED(mp)) {
270 for (i = 0; i < n; i++, data++) {
271 Py_XINCREF(*data);
272 }
273 }
274 else {
275 for( i = 0; i < n; i++, data++) {
276 memcpy(&temp, data, sizeof(temp));
277 Py_XINCREF(temp);
278 }
279 }
280 }
281 else { /* handles misaligned data too */
282 it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);
283 if (it == NULL) {
284 return -1;
285 }
286 while(it->index < it->size) {
287 memcpy(&temp, it->dataptr, sizeof(temp));
288 Py_XINCREF(temp);
289 PyArray_ITER_NEXT(it);
290 }
291 Py_DECREF(it);
292 }
293 return 0;
294}
295
296/*NUMPY_API
297 Decrement all internal references for object arrays.

Callers

nothing calls this directly

Calls 4

PyArray_DESCRFunction · 0.85
PyArray_IterNewFunction · 0.85
PyArray_Item_INCREFFunction · 0.85
PyArray_DATAFunction · 0.85

Tested by

no test coverage detected