diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-01-06 10:14:10 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-01-06 10:14:10 +0000 |
commit | 6315c4c27eaeca7f2080ea585b1901e2b683b3ff (patch) | |
tree | 2777bf768a4fb125ad3ceb1940f46f70ad4e2d51 /numpy/core/src/arraymethods.c | |
parent | 5f5c4b92573a060d20cf9bbf70db00d45cda7268 (diff) | |
download | numpy-6315c4c27eaeca7f2080ea585b1901e2b683b3ff.tar.gz |
Added new feature to .view method so that if the argument is a sub-type of the ndarray, an object is returned with all the information of the array.
Diffstat (limited to 'numpy/core/src/arraymethods.c')
-rw-r--r-- | numpy/core/src/arraymethods.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/numpy/core/src/arraymethods.c b/numpy/core/src/arraymethods.c index 0760e7af1..15d8eb3fe 100644 --- a/numpy/core/src/arraymethods.c +++ b/numpy/core/src/arraymethods.c @@ -157,17 +157,29 @@ array_squeeze(PyArrayObject *self, PyObject *args) -static char doc_view[] = "a.view(<dtype>) return a new view of array with same data."; +static char doc_view[] = "a.view(<type>) return a new view of array with same data. type can be either a new sub-type object or a data-descriptor object"; static PyObject * array_view(PyArrayObject *self, PyObject *args) { + PyObject *otype=NULL; PyArray_Descr *type=NULL; - if (!PyArg_ParseTuple(args, "|O&", - PyArray_DescrConverter, &type)) - return NULL; - return _ARET(PyArray_View(self, type)); + if (!PyArg_ParseTuple(args, "|O", &otype)) return NULL; + + if (otype) { + if (PyType_Check(otype) && \ + PyType_IsSubtype((PyTypeObject *)otype, + &PyBigArray_Type)) { + return _ARET(PyArray_View(self, NULL, + (PyTypeObject *)otype)); + } + else { + if (PyArray_DescrConverter(otype, &type) == PY_FAIL) + return NULL; + } + } + return _ARET(PyArray_View(self, type, NULL)); } static char doc_argmax[] = "a.argmax(axis=None)"; @@ -1522,7 +1534,7 @@ array_newbyteorder(PyArrayObject *self, PyObject *args) new = PyArray_DescrNewByteorder(self->descr, endian); if (!new) return NULL; - return _ARET(PyArray_View(self, new)); + return _ARET(PyArray_View(self, new, NULL)); } |