| 793 | (PyArray_ISSTRING(arr) && PyTypeNum_ISSTRING(type_num))) |
| 794 | |
| 795 | static int |
| 796 | get_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 | |
| 829 | extern PyArrayObject * |
| 830 | ndarray_from_pyobj(const int type_num, |
no test coverage detected