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

Function get_elsize

numpy/f2py/src/fortranobject.c:795–827  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

793 (PyArray_ISSTRING(arr) && PyTypeNum_ISSTRING(type_num)))
794
795static int
796get_elsize(PyObject *obj) {
797 /*
798 get_elsize determines array itemsize from a Python object. Returns
799 elsize if successful, -1 otherwise.
800
801 Supported types of the input are: numpy.ndarray, bytes, str, tuple,
802 list.
803 */
804
805 if (PyArray_Check(obj)) {
806 return PyArray_DESCR((PyArrayObject *)obj)->elsize;
807 } else if (PyBytes_Check(obj)) {
808 return PyBytes_GET_SIZE(obj);
809 } else if (PyUnicode_Check(obj)) {
810 return PyUnicode_GET_LENGTH(obj);
811 } else if (PySequence_Check(obj)) {
812 PyObject* fast = PySequence_Fast(obj, "f2py:fortranobject.c:get_elsize");
813 if (fast != NULL) {
814 Py_ssize_t i, n = PySequence_Fast_GET_SIZE(fast);
815 int sz, elsize = 0;
816 for (i=0; i<n; i++) {
817 sz = get_elsize(PySequence_Fast_GET_ITEM(fast, i) /* borrowed */);
818 if (sz > elsize) {
819 elsize = sz;
820 }
821 }
822 Py_DECREF(fast);
823 return elsize;
824 }
825 }
826 return -1;
827}
828
829extern PyArrayObject *
830ndarray_from_pyobj(const int type_num,

Callers 1

ndarray_from_pyobjFunction · 0.70

Calls 1

PyArray_DESCRFunction · 0.85

Tested by

no test coverage detected