MCPcopy Create free account
hub / github.com/numpy/numpy / _get_part

Function _get_part

numpy/core/src/multiarray/getset.c:679–730  ·  view source on GitHub ↗

* Create a view of a complex array with an equivalent data-type * except it is real instead of complex. */

Source from the content-addressed store, hash-verified

677 * except it is real instead of complex.
678 */
679static 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.

Callers 4

array_real_getFunction · 0.85
array_real_setFunction · 0.85
array_imag_getFunction · 0.85
array_imag_setFunction · 0.85

Calls 8

PyArray_DESCRFunction · 0.85
PyArray_DescrNewFunction · 0.85
PyArray_NDIMFunction · 0.85
PyArray_DIMSFunction · 0.85
PyArray_STRIDESFunction · 0.85
PyArray_BYTESFunction · 0.85
PyArray_FLAGSFunction · 0.85

Tested by

no test coverage detected