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

Function arr_ravel_multi_index

numpy/core/src/multiarray/compiled_base.c:1041–1182  ·  view source on GitHub ↗

ravel_multi_index implementation - see add_newdocs.py */

Source from the content-addressed store, hash-verified

1039
1040/* ravel_multi_index implementation - see add_newdocs.py */
1041NPY_NO_EXPORT PyObject *
1042arr_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;

Callers

nothing calls this directly

Calls 12

int_sequence_to_arraysFunction · 0.85
NpyIter_MultiNewFunction · 0.85
NpyIter_GetIterSizeFunction · 0.85
NpyIter_GetDataPtrArrayFunction · 0.85
ravel_multi_index_loopFunction · 0.85
NpyIter_GetOperandArrayFunction · 0.85
npy_free_cache_dim_objFunction · 0.85
NpyIter_DeallocateFunction · 0.85
PyArray_ReturnFunction · 0.85

Tested by

no test coverage detected