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

Function array_flat_set

numpy/core/src/multiarray/getset.c:856–926  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

854}
855
856static int
857array_flat_set(PyArrayObject *self, PyObject *val, void *NPY_UNUSED(ignored))
858{
859 PyArrayObject *arr = NULL;
860 int retval = -1;
861 PyArrayIterObject *selfit = NULL, *arrit = NULL;
862 PyArray_Descr *typecode;
863 int swap;
864 PyArray_CopySwapFunc *copyswap;
865
866 if (val == NULL) {
867 PyErr_SetString(PyExc_AttributeError,
868 "Cannot delete array flat iterator");
869 return -1;
870 }
871 if (PyArray_FailUnlessWriteable(self, "array") < 0) return -1;
872 typecode = PyArray_DESCR(self);
873 Py_INCREF(typecode);
874 arr = (PyArrayObject *)PyArray_FromAny(val, typecode,
875 0, 0, NPY_ARRAY_FORCECAST | PyArray_FORTRAN_IF(self), NULL);
876 if (arr == NULL) {
877 return -1;
878 }
879 arrit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);
880 if (arrit == NULL) {
881 goto exit;
882 }
883 selfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);
884 if (selfit == NULL) {
885 goto exit;
886 }
887 if (arrit->size == 0) {
888 retval = 0;
889 goto exit;
890 }
891 swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);
892 copyswap = PyArray_DESCR(self)->f->copyswap;
893 if (PyDataType_REFCHK(PyArray_DESCR(self))) {
894 while (selfit->index < selfit->size) {
895 PyArray_Item_XDECREF(selfit->dataptr, PyArray_DESCR(self));
896 PyArray_Item_INCREF(arrit->dataptr, PyArray_DESCR(arr));
897 memmove(selfit->dataptr, arrit->dataptr, sizeof(PyObject **));
898 if (swap) {
899 copyswap(selfit->dataptr, NULL, swap, self);
900 }
901 PyArray_ITER_NEXT(selfit);
902 PyArray_ITER_NEXT(arrit);
903 if (arrit->index == arrit->size) {
904 PyArray_ITER_RESET(arrit);
905 }
906 }
907 retval = 0;
908 goto exit;
909 }
910
911 while(selfit->index < selfit->size) {
912 copyswap(selfit->dataptr, arrit->dataptr, swap, self);
913 PyArray_ITER_NEXT(selfit);

Callers

nothing calls this directly

Calls 6

PyArray_DESCRFunction · 0.85
PyArray_FromAnyFunction · 0.85
PyArray_IterNewFunction · 0.85
PyArray_Item_XDECREFFunction · 0.85
PyArray_Item_INCREFFunction · 0.85

Tested by

no test coverage detected