unravel_index implementation - see add_newdocs.py */
| 1235 | |
| 1236 | /* unravel_index implementation - see add_newdocs.py */ |
| 1237 | NPY_NO_EXPORT PyObject * |
| 1238 | arr_unravel_index(PyObject *self, PyObject *args, PyObject *kwds) |
| 1239 | { |
| 1240 | PyObject *indices0 = NULL; |
| 1241 | PyObject *ret_tuple = NULL; |
| 1242 | PyArrayObject *ret_arr = NULL; |
| 1243 | PyArrayObject *indices = NULL; |
| 1244 | PyArray_Descr *dtype = NULL; |
| 1245 | PyArray_Dims dimensions = {0, 0}; |
| 1246 | NPY_ORDER order = NPY_CORDER; |
| 1247 | npy_intp unravel_size; |
| 1248 | |
| 1249 | NpyIter *iter = NULL; |
| 1250 | int i, ret_ndim; |
| 1251 | npy_intp ret_dims[NPY_MAXDIMS], ret_strides[NPY_MAXDIMS]; |
| 1252 | |
| 1253 | static char *kwlist[] = {"indices", "shape", "order", NULL}; |
| 1254 | |
| 1255 | if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&|O&:unravel_index", |
| 1256 | kwlist, |
| 1257 | &indices0, |
| 1258 | PyArray_IntpConverter, &dimensions, |
| 1259 | PyArray_OrderConverter, &order)) { |
| 1260 | goto fail; |
| 1261 | } |
| 1262 | |
| 1263 | unravel_size = PyArray_OverflowMultiplyList(dimensions.ptr, dimensions.len); |
| 1264 | if (unravel_size == -1) { |
| 1265 | PyErr_SetString(PyExc_ValueError, |
| 1266 | "dimensions are too large; arrays and shapes with " |
| 1267 | "a total size greater than 'intp' are not supported."); |
| 1268 | goto fail; |
| 1269 | } |
| 1270 | |
| 1271 | indices = astype_anyint(indices0); |
| 1272 | if (indices == NULL) { |
| 1273 | goto fail; |
| 1274 | } |
| 1275 | |
| 1276 | dtype = PyArray_DescrFromType(NPY_INTP); |
| 1277 | if (dtype == NULL) { |
| 1278 | goto fail; |
| 1279 | } |
| 1280 | |
| 1281 | iter = NpyIter_New(indices, NPY_ITER_READONLY| |
| 1282 | NPY_ITER_ALIGNED| |
| 1283 | NPY_ITER_BUFFERED| |
| 1284 | NPY_ITER_ZEROSIZE_OK| |
| 1285 | NPY_ITER_DONT_NEGATE_STRIDES| |
| 1286 | NPY_ITER_MULTI_INDEX, |
| 1287 | NPY_KEEPORDER, NPY_SAME_KIND_CASTING, |
| 1288 | dtype); |
| 1289 | if (iter == NULL) { |
| 1290 | goto fail; |
| 1291 | } |
| 1292 | |
| 1293 | /* |
| 1294 | * Create the return array with a layout compatible with the indices |
nothing calls this directly
no test coverage detected