ravel_multi_index implementation - see add_newdocs.py */
| 1039 | |
| 1040 | /* ravel_multi_index implementation - see add_newdocs.py */ |
| 1041 | NPY_NO_EXPORT PyObject * |
| 1042 | arr_ravel_multi_index(PyObject *self, PyObject *args, PyObject *kwds) |
| 1043 | { |
| 1044 | int i; |
| 1045 | PyObject *mode0=NULL, *coords0=NULL; |
| 1046 | PyArrayObject *ret = NULL; |
| 1047 | PyArray_Dims dimensions={0,0}; |
| 1048 | npy_intp s, ravel_strides[NPY_MAXDIMS]; |
| 1049 | NPY_ORDER order = NPY_CORDER; |
| 1050 | NPY_CLIPMODE modes[NPY_MAXDIMS]; |
| 1051 | |
| 1052 | PyArrayObject *op[NPY_MAXARGS]; |
| 1053 | PyArray_Descr *dtype[NPY_MAXARGS]; |
| 1054 | npy_uint32 op_flags[NPY_MAXARGS]; |
| 1055 | |
| 1056 | NpyIter *iter = NULL; |
| 1057 | |
| 1058 | static char *kwlist[] = {"multi_index", "dims", "mode", "order", NULL}; |
| 1059 | |
| 1060 | memset(op, 0, sizeof(op)); |
| 1061 | dtype[0] = NULL; |
| 1062 | |
| 1063 | if (!PyArg_ParseTupleAndKeywords(args, kwds, |
| 1064 | "OO&|OO&:ravel_multi_index", kwlist, |
| 1065 | &coords0, |
| 1066 | PyArray_IntpConverter, &dimensions, |
| 1067 | &mode0, |
| 1068 | PyArray_OrderConverter, &order)) { |
| 1069 | goto fail; |
| 1070 | } |
| 1071 | |
| 1072 | if (dimensions.len+1 > NPY_MAXARGS) { |
| 1073 | PyErr_SetString(PyExc_ValueError, |
| 1074 | "too many dimensions passed to ravel_multi_index"); |
| 1075 | goto fail; |
| 1076 | } |
| 1077 | |
| 1078 | if (!PyArray_ConvertClipmodeSequence(mode0, modes, dimensions.len)) { |
| 1079 | goto fail; |
| 1080 | } |
| 1081 | |
| 1082 | switch (order) { |
| 1083 | case NPY_CORDER: |
| 1084 | s = 1; |
| 1085 | for (i = dimensions.len-1; i >= 0; --i) { |
| 1086 | ravel_strides[i] = s; |
| 1087 | if (npy_mul_sizes_with_overflow(&s, s, dimensions.ptr[i])) { |
| 1088 | PyErr_SetString(PyExc_ValueError, |
| 1089 | "invalid dims: array size defined by dims is larger " |
| 1090 | "than the maximum possible size."); |
| 1091 | goto fail; |
| 1092 | } |
| 1093 | } |
| 1094 | break; |
| 1095 | case NPY_FORTRANORDER: |
| 1096 | s = 1; |
| 1097 | for (i = 0; i < dimensions.len; ++i) { |
| 1098 | ravel_strides[i] = s; |
nothing calls this directly
no test coverage detected