* Create a view of a complex array with an equivalent data-type * except it is real instead of complex. */
| 677 | * except it is real instead of complex. |
| 678 | */ |
| 679 | static PyArrayObject * |
| 680 | _get_part(PyArrayObject *self, int imag) |
| 681 | { |
| 682 | int float_type_num; |
| 683 | PyArray_Descr *type; |
| 684 | PyArrayObject *ret; |
| 685 | int offset; |
| 686 | |
| 687 | switch (PyArray_DESCR(self)->type_num) { |
| 688 | case NPY_CFLOAT: |
| 689 | float_type_num = NPY_FLOAT; |
| 690 | break; |
| 691 | case NPY_CDOUBLE: |
| 692 | float_type_num = NPY_DOUBLE; |
| 693 | break; |
| 694 | case NPY_CLONGDOUBLE: |
| 695 | float_type_num = NPY_LONGDOUBLE; |
| 696 | break; |
| 697 | default: |
| 698 | PyErr_Format(PyExc_ValueError, |
| 699 | "Cannot convert complex type number %d to float", |
| 700 | PyArray_DESCR(self)->type_num); |
| 701 | return NULL; |
| 702 | |
| 703 | } |
| 704 | type = PyArray_DescrFromType(float_type_num); |
| 705 | if (type == NULL) { |
| 706 | return NULL; |
| 707 | } |
| 708 | |
| 709 | offset = (imag ? type->elsize : 0); |
| 710 | |
| 711 | if (!PyArray_ISNBO(PyArray_DESCR(self)->byteorder)) { |
| 712 | Py_SETREF(type, PyArray_DescrNew(type)); |
| 713 | if (type == NULL) { |
| 714 | return NULL; |
| 715 | } |
| 716 | type->byteorder = PyArray_DESCR(self)->byteorder; |
| 717 | } |
| 718 | ret = (PyArrayObject *)PyArray_NewFromDescrAndBase( |
| 719 | Py_TYPE(self), |
| 720 | type, |
| 721 | PyArray_NDIM(self), |
| 722 | PyArray_DIMS(self), |
| 723 | PyArray_STRIDES(self), |
| 724 | PyArray_BYTES(self) + offset, |
| 725 | PyArray_FLAGS(self), (PyObject *)self, (PyObject *)self); |
| 726 | if (ret == NULL) { |
| 727 | return NULL; |
| 728 | } |
| 729 | return ret; |
| 730 | } |
| 731 | |
| 732 | /* For Object arrays, we need to get and set the |
| 733 | real part of each element. |
no test coverage detected