diff options
author | David Cournapeau <cournape@gmail.com> | 2009-04-30 08:39:44 +0000 |
---|---|---|
committer | David Cournapeau <cournape@gmail.com> | 2009-04-30 08:39:44 +0000 |
commit | 32a5fe9739bf34b1d6ff071dbb12968666831718 (patch) | |
tree | ac2244ef8bcb10c4f2aff42764de456803a3ff8f /numpy/core/src/arrayconvert.c | |
parent | 96a1f08f4f92f8a3dc39979f440c41e0f4fa018a (diff) | |
download | numpy-32a5fe9739bf34b1d6ff071dbb12968666831718.tar.gz |
Put shape manipulation code into separate file.
Diffstat (limited to 'numpy/core/src/arrayconvert.c')
-rw-r--r-- | numpy/core/src/arrayconvert.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/numpy/core/src/arrayconvert.c b/numpy/core/src/arrayconvert.c index 17cb9aad0..9321a05cb 100644 --- a/numpy/core/src/arrayconvert.c +++ b/numpy/core/src/arrayconvert.c @@ -344,3 +344,43 @@ PyArray_NewCopy(PyArrayObject *m1, NPY_ORDER fortran) return (PyObject *)ret; } +/*NUMPY_API + * View + * steals a reference to type -- accepts NULL + */ +NPY_NO_EXPORT PyObject * +PyArray_View(PyArrayObject *self, PyArray_Descr *type, PyTypeObject *pytype) +{ + PyObject *new = NULL; + PyTypeObject *subtype; + + if (pytype) { + subtype = pytype; + } + else { + subtype = self->ob_type; + } + Py_INCREF(self->descr); + new = PyArray_NewFromDescr(subtype, + self->descr, + self->nd, self->dimensions, + self->strides, + self->data, + self->flags, (PyObject *)self); + if (new == NULL) { + return NULL; + } + Py_INCREF(self); + PyArray_BASE(new) = (PyObject *)self; + + if (type != NULL) { + if (PyObject_SetAttrString(new, "dtype", + (PyObject *)type) < 0) { + Py_DECREF(new); + Py_DECREF(type); + return NULL; + } + Py_DECREF(type); + } + return new; +} |