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

Function array_setflags

numpy/core/src/multiarray/methods.c:2698–2794  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2696
2697
2698static PyObject *
2699array_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds)
2700{
2701 static char *kwlist[] = {"write", "align", "uic", NULL};
2702 PyObject *write_flag = Py_None;
2703 PyObject *align_flag = Py_None;
2704 PyObject *uic = Py_None;
2705 int flagback = PyArray_FLAGS(self);
2706
2707 PyArrayObject_fields *fa = (PyArrayObject_fields *)self;
2708
2709 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO:setflags", kwlist,
2710 &write_flag,
2711 &align_flag,
2712 &uic))
2713 return NULL;
2714
2715 if (align_flag != Py_None) {
2716 int isnot = PyObject_Not(align_flag);
2717 if (isnot == -1) {
2718 return NULL;
2719 }
2720 if (isnot) {
2721 PyArray_CLEARFLAGS(self, NPY_ARRAY_ALIGNED);
2722 }
2723 else if (IsAligned(self)) {
2724 PyArray_ENABLEFLAGS(self, NPY_ARRAY_ALIGNED);
2725 }
2726 else {
2727 PyErr_SetString(PyExc_ValueError,
2728 "cannot set aligned flag of mis-"
2729 "aligned array to True");
2730 return NULL;
2731 }
2732 }
2733
2734 if (uic != Py_None) {
2735 int istrue = PyObject_IsTrue(uic);
2736 if (istrue == -1) {
2737 return NULL;
2738 }
2739 if (istrue) {
2740 fa->flags = flagback;
2741 PyErr_SetString(PyExc_ValueError,
2742 "cannot set WRITEBACKIFCOPY "
2743 "flag to True");
2744 return NULL;
2745 }
2746 else {
2747 PyArray_CLEARFLAGS(self, NPY_ARRAY_WRITEBACKIFCOPY);
2748 Py_XDECREF(fa->base);
2749 fa->base = NULL;
2750 }
2751 }
2752
2753 if (write_flag != Py_None) {
2754 int istrue = PyObject_IsTrue(write_flag);
2755 if (istrue == -1) {

Callers

nothing calls this directly

Calls 7

PyArray_FLAGSFunction · 0.85
PyArray_CLEARFLAGSFunction · 0.85
IsAlignedFunction · 0.85
PyArray_ENABLEFLAGSFunction · 0.85
_IsWriteableFunction · 0.85
PyArray_BASEFunction · 0.85
PyArray_CHKFLAGSFunction · 0.85

Tested by

no test coverage detected