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

Function ndarray_from_pyobj

numpy/f2py/src/fortranobject.c:829–1100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

827}
828
829extern PyArrayObject *
830ndarray_from_pyobj(const int type_num,
831 const int elsize_,
832 npy_intp *dims,
833 const int rank,
834 const int intent,
835 PyObject *obj,
836 const char *errmess) {
837 /*
838 * Return an array with given element type and shape from a Python
839 * object while taking into account the usage intent of the array.
840 *
841 * - element type is defined by type_num and elsize
842 * - shape is defined by dims and rank
843 *
844 * ndarray_from_pyobj is used to convert Python object arguments
845 * to numpy ndarrays with given type and shape that data is passed
846 * to interfaced Fortran or C functions.
847 *
848 * errmess (if not NULL), contains a prefix of an error message
849 * for an exception to be triggered within this function.
850 *
851 * Negative elsize value means that elsize is to be determined
852 * from the Python object in runtime.
853 *
854 * Note on strings
855 * ---------------
856 *
857 * String type (type_num == NPY_STRING) does not have fixed
858 * element size and, by default, the type object sets it to
859 * 0. Therefore, for string types, one has to use elsize
860 * argument. For other types, elsize value is ignored.
861 *
862 * NumPy defines the type of a fixed-width string as
863 * dtype('S<width>'). In addition, there is also dtype('c'), that
864 * appears as dtype('S1') (these have the same type_num value),
865 * but is actually different (.char attribute is either 'S' or
866 * 'c', respecitely).
867 *
868 * In Fortran, character arrays and strings are different
869 * concepts. The relation between Fortran types, NumPy dtypes,
870 * and type_num-elsize pairs, is defined as follows:
871 *
872 * character*5 foo | dtype('S5') | elsize=5, shape=()
873 * character(5) foo | dtype('S1') | elsize=1, shape=(5)
874 * character*5 foo(n) | dtype('S5') | elsize=5, shape=(n,)
875 * character(5) foo(n) | dtype('S1') | elsize=1, shape=(5, n)
876 * character*(*) foo | dtype('S') | elsize=-1, shape=()
877 *
878 * Note about reference counting
879 * -----------------------------
880 *
881 * If the caller returns the array to Python, it must be done with
882 * Py_BuildValue("N",arr). Otherwise, if obj!=arr then the caller
883 * must call Py_DECREF(arr).
884 *
885 * Note on intent(cache,out,..)
886 * ----------------------------

Callers 2

array_from_pyobjFunction · 0.85
f2py_rout_wrap_callFunction · 0.85

Calls 12

PyArray_NewFromDescrFunction · 0.85
PyArray_ITEMSIZEFunction · 0.85
check_and_fix_dimensionsFunction · 0.85
PyArray_DESCRFunction · 0.85
PyArray_NDIMFunction · 0.85
PyArray_DIMSFunction · 0.85
PyArray_CopyIntoFunction · 0.85
swap_arraysFunction · 0.85
PyArray_FromAnyFunction · 0.85
get_elsizeFunction · 0.70

Tested by 1

f2py_rout_wrap_callFunction · 0.68