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

Function PyArray_ResolveWritebackIfCopy

numpy/core/src/multiarray/arrayobject.c:362–392  ·  view source on GitHub ↗

NUMPY_API * * If WRITEBACKIFCOPY and self has data, reset the base WRITEABLE flag, * copy the local data to base, release the local data, and set flags * appropriately. Return 0 if not relevant, 1 if success, < 0 on failure */

Source from the content-addressed store, hash-verified

360 * appropriately. Return 0 if not relevant, 1 if success, < 0 on failure
361 */
362NPY_NO_EXPORT int
363PyArray_ResolveWritebackIfCopy(PyArrayObject * self)
364{
365 PyArrayObject_fields *fa = (PyArrayObject_fields *)self;
366 if (fa && fa->base) {
367 if (fa->flags & NPY_ARRAY_WRITEBACKIFCOPY) {
368 /*
369 * WRITEBACKIFCOPY means that fa->base's data
370 * should be updated with the contents
371 * of self.
372 * fa->base->flags is not WRITEABLE to protect the relationship
373 * unlock it.
374 */
375 int retval = 0;
376 PyArray_ENABLEFLAGS(((PyArrayObject *)fa->base),
377 NPY_ARRAY_WRITEABLE);
378 PyArray_CLEARFLAGS(self, NPY_ARRAY_WRITEBACKIFCOPY);
379 retval = PyArray_CopyAnyInto((PyArrayObject *)fa->base, self);
380 Py_DECREF(fa->base);
381 fa->base = NULL;
382 if (retval < 0) {
383 /* this should never happen, how did the two copies of data
384 * get out of sync?
385 */
386 return retval;
387 }
388 return 1;
389 }
390 }
391 return 0;
392}
393
394/*********************** end C-API functions **********************/
395

Callers 13

PyArray_TakeFromFunction · 0.85
PyArray_PutToFunction · 0.85
PyArray_PutMaskFunction · 0.85
PyArray_ChooseFunction · 0.85
PyArray_MatrixProduct2Function · 0.85
NpyIter_DeallocateFunction · 0.85
iter_richcompareFunction · 0.85
arr_placeFunction · 0.85
arraymapiter_deallocFunction · 0.85
array_deallocFunction · 0.85
_PyArray_ArgMinMaxCommonFunction · 0.85
PyArray_ClipFunction · 0.85

Calls 3

PyArray_ENABLEFLAGSFunction · 0.85
PyArray_CLEARFLAGSFunction · 0.85
PyArray_CopyAnyIntoFunction · 0.85

Tested by

no test coverage detected