diff options
author | Travis Oliphant <oliphant@enthought.com> | 2005-09-29 00:52:06 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2005-09-29 00:52:06 +0000 |
commit | 4742ef06a5888264488fc250d40d7ad47b718cb2 (patch) | |
tree | e3134ef2977e4d191b8b0672757367235b5d0871 /scipy/base/src | |
parent | a8240d84ad9317a8c6e08e45c5cabdb7b562b6f5 (diff) | |
download | numpy-4742ef06a5888264488fc250d40d7ad47b718cb2.tar.gz |
a.flags returns fancy array-connected dictionary.
Diffstat (limited to 'scipy/base/src')
-rw-r--r-- | scipy/base/src/arrayobject.c | 30 | ||||
-rw-r--r-- | scipy/base/src/multiarraymodule.c | 40 |
2 files changed, 44 insertions, 26 deletions
diff --git a/scipy/base/src/arrayobject.c b/scipy/base/src/arrayobject.c index e07f2f08c..17a9914a8 100644 --- a/scipy/base/src/arrayobject.c +++ b/scipy/base/src/arrayobject.c @@ -3530,26 +3530,17 @@ array_ndim_get(PyArrayObject *self) static PyObject * array_flags_get(PyArrayObject *self) { - PyObject *dict; - - dict = PyDict_New(); - -#define ADDFLAG(flag) \ - PyDict_SetItemString(dict, #flag, \ - self->flags & flag ? Py_True : Py_False) + static PyObject *module=NULL; - ADDFLAG(CONTIGUOUS); - ADDFLAG(OWNDATA); - ADDFLAG(FORTRAN); - ADDFLAG(ALIGNED); - ADDFLAG(NOTSWAPPED); - ADDFLAG(WRITEABLE); - ADDFLAG(UPDATEIFCOPY); - return dict; - /* return PyInt_FromLong(self->flags);*/ -#undef ADDFLAG + if (module==NULL) { + module = PyImport_ImportModule("scipy.base._internal"); + if (module == NULL) return NULL; + } + return PyObject_CallMethod(module, "flagsobj", "Oi", + self, self->flags); } +/* static int array_flags_set(PyArrayObject *self, PyObject *obj) { @@ -3616,6 +3607,7 @@ array_flags_set(PyArrayObject *self, PyObject *obj) "Object must be a dictionary"); return -1; } +*/ static PyObject * @@ -4173,8 +4165,8 @@ static PyGetSetDef array_getsetlist[] = { "number of array dimensions"}, {"flags", (getter)array_flags_get, - (setter)array_flags_set, - "integer value of flags"}, + NULL, + "special dictionary of flags"}, {"shape", (getter)array_shape_get, (setter)array_shape_set, diff --git a/scipy/base/src/multiarraymodule.c b/scipy/base/src/multiarraymodule.c index 532f60ba0..ebb719d38 100644 --- a/scipy/base/src/multiarraymodule.c +++ b/scipy/base/src/multiarraymodule.c @@ -3979,6 +3979,37 @@ setup_scalartypes(PyObject *dict) */ } +/* place a flag dictionary in d */ + +static void +set_flaginfo(PyObject *d) +{ + PyObject *s; + PyObject *newd; + + newd = PyDict_New(); + + PyDict_SetItemString(newd, "OWNDATA", s=PyInt_FromLong(OWNDATA)); + Py_DECREF(s); + PyDict_SetItemString(newd, "FORTRAN", s=PyInt_FromLong(FORTRAN)); + Py_DECREF(s); + PyDict_SetItemString(newd, "CONTIGUOUS", s=PyInt_FromLong(CONTIGUOUS)); + Py_DECREF(s); + PyDict_SetItemString(newd, "ALIGNED", s=PyInt_FromLong(ALIGNED)); + Py_DECREF(s); + + PyDict_SetItemString(newd, "NOTSWAPPED", s=PyInt_FromLong(NOTSWAPPED)); + Py_DECREF(s); + PyDict_SetItemString(newd, "UPDATEIFCOPY", s=PyInt_FromLong(UPDATEIFCOPY)); + Py_DECREF(s); + PyDict_SetItemString(newd, "WRITEABLE", s=PyInt_FromLong(WRITEABLE)); + Py_DECREF(s); + + PyDict_SetItemString(d, "_flagdict", newd); + Py_DECREF(newd); + return; +} + /* Initialization function for the module */ @@ -4038,13 +4069,8 @@ DL_EXPORT(void) initmultiarray(void) { Py_INCREF(&PyArrayMapIter_Type); PyDict_SetItemString(d, "mapiter", (PyObject *)&PyArrayMapIter_Type); - PyDict_SetItemString(d, "NOTSWAPPED", s=PyInt_FromLong(NOTSWAPPED)); - Py_DECREF(s); - PyDict_SetItemString(d, "UPDATEIFCOPY", s=PyInt_FromLong(UPDATEIFCOPY)); - Py_DECREF(s); - PyDict_SetItemString(d, "WRITEABLE", s=PyInt_FromLong(WRITEABLE)); - Py_DECREF(s); - + set_flaginfo(d); + if (set_typeinfo(d) == 0) return; /* otherwise there is an error */ |