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

Function PyArray_XDECREF

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

NUMPY_API Decrement all internal references for object arrays. (or arrays with object fields) The use of this function is strongly discouraged, within NumPy use PyArray_Clear, which DECREF's and sets everything to NULL and can work with any dtype. */

Source from the content-addressed store, hash-verified

302 work with any dtype.
303*/
304NPY_NO_EXPORT int
305PyArray_XDECREF(PyArrayObject *mp)
306{
307 npy_intp i, n;
308 PyObject **data;
309 PyObject *temp;
310 /*
311 * statically allocating it allows this function to not modify the
312 * reference count of the array for use during dealloc.
313 * (statically is not necessary as such)
314 */
315 PyArrayIterObject it;
316
317 if (!PyDataType_REFCHK(PyArray_DESCR(mp))) {
318 return 0;
319 }
320 if (PyArray_DESCR(mp)->type_num != NPY_OBJECT) {
321 PyArray_RawIterBaseInit(&it, mp);
322 while(it.index < it.size) {
323 PyArray_Item_XDECREF(it.dataptr, PyArray_DESCR(mp));
324 PyArray_ITER_NEXT(&it);
325 }
326 return 0;
327 }
328
329 if (PyArray_ISONESEGMENT(mp)) {
330 data = (PyObject **)PyArray_DATA(mp);
331 n = PyArray_SIZE(mp);
332 if (PyArray_ISALIGNED(mp)) {
333 for (i = 0; i < n; i++, data++) Py_XDECREF(*data);
334 }
335 else {
336 for (i = 0; i < n; i++, data++) {
337 memcpy(&temp, data, sizeof(temp));
338 Py_XDECREF(temp);
339 }
340 }
341 }
342 else { /* handles misaligned data too */
343 PyArray_RawIterBaseInit(&it, mp);
344 while(it.index < it.size) {
345 memcpy(&temp, it.dataptr, sizeof(temp));
346 Py_XDECREF(temp);
347 PyArray_ITER_NEXT(&it);
348 }
349 }
350 return 0;
351}
352
353
354static void

Callers 1

array_data_setFunction · 0.85

Calls 4

PyArray_DESCRFunction · 0.85
PyArray_RawIterBaseInitFunction · 0.85
PyArray_Item_XDECREFFunction · 0.85
PyArray_DATAFunction · 0.85

Tested by

no test coverage detected