NUMPY_API * View * steals a reference to type -- accepts NULL */
| 501 | * steals a reference to type -- accepts NULL |
| 502 | */ |
| 503 | NPY_NO_EXPORT PyObject * |
| 504 | PyArray_View(PyArrayObject *self, PyArray_Descr *type, PyTypeObject *pytype) |
| 505 | { |
| 506 | PyArrayObject *ret = NULL; |
| 507 | PyArray_Descr *dtype; |
| 508 | PyTypeObject *subtype; |
| 509 | int flags; |
| 510 | |
| 511 | if (pytype) { |
| 512 | subtype = pytype; |
| 513 | } |
| 514 | else { |
| 515 | subtype = Py_TYPE(self); |
| 516 | } |
| 517 | |
| 518 | dtype = PyArray_DESCR(self); |
| 519 | flags = PyArray_FLAGS(self); |
| 520 | |
| 521 | Py_INCREF(dtype); |
| 522 | ret = (PyArrayObject *)PyArray_NewFromDescr_int( |
| 523 | subtype, dtype, |
| 524 | PyArray_NDIM(self), PyArray_DIMS(self), PyArray_STRIDES(self), |
| 525 | PyArray_DATA(self), |
| 526 | flags, (PyObject *)self, (PyObject *)self, |
| 527 | _NPY_ARRAY_ENSURE_DTYPE_IDENTITY); |
| 528 | if (ret == NULL) { |
| 529 | Py_XDECREF(type); |
| 530 | return NULL; |
| 531 | } |
| 532 | |
| 533 | if (type != NULL) { |
| 534 | if (PyObject_SetAttrString((PyObject *)ret, "dtype", |
| 535 | (PyObject *)type) < 0) { |
| 536 | Py_DECREF(ret); |
| 537 | Py_DECREF(type); |
| 538 | return NULL; |
| 539 | } |
| 540 | Py_DECREF(type); |
| 541 | } |
| 542 | return (PyObject *)ret; |
| 543 | } |
no test coverage detected