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

Function array_getarray

numpy/core/src/multiarray/methods.c:1043–1088  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1041
1042
1043static PyObject *
1044array_getarray(PyArrayObject *self, PyObject *args)
1045{
1046 PyArray_Descr *newtype = NULL;
1047 PyObject *ret;
1048
1049 if (!PyArg_ParseTuple(args, "|O&:__array__",
1050 PyArray_DescrConverter, &newtype)) {
1051 Py_XDECREF(newtype);
1052 return NULL;
1053 }
1054
1055 /* convert to PyArray_Type */
1056 if (!PyArray_CheckExact(self)) {
1057 PyArrayObject *new;
1058
1059 Py_INCREF(PyArray_DESCR(self));
1060 new = (PyArrayObject *)PyArray_NewFromDescrAndBase(
1061 &PyArray_Type,
1062 PyArray_DESCR(self),
1063 PyArray_NDIM(self),
1064 PyArray_DIMS(self),
1065 PyArray_STRIDES(self),
1066 PyArray_DATA(self),
1067 PyArray_FLAGS(self),
1068 NULL,
1069 (PyObject *)self
1070 );
1071 if (new == NULL) {
1072 return NULL;
1073 }
1074 self = new;
1075 }
1076 else {
1077 Py_INCREF(self);
1078 }
1079
1080 if ((newtype == NULL) || PyArray_EquivTypes(PyArray_DESCR(self), newtype)) {
1081 return (PyObject *)self;
1082 }
1083 else {
1084 ret = PyArray_CastToType(self, newtype, 0);
1085 Py_DECREF(self);
1086 return ret;
1087 }
1088}
1089
1090/*
1091 * Check whether any of the input and output args have a non-default

Callers

nothing calls this directly

Calls 9

PyArray_DESCRFunction · 0.85
PyArray_NDIMFunction · 0.85
PyArray_DIMSFunction · 0.85
PyArray_STRIDESFunction · 0.85
PyArray_DATAFunction · 0.85
PyArray_FLAGSFunction · 0.85
PyArray_EquivTypesFunction · 0.85
PyArray_CastToTypeFunction · 0.85

Tested by

no test coverage detected