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

Function ravel_multi_index_loop

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

Inner loop for ravel_multi_index */

Source from the content-addressed store, hash-verified

955
956/* Inner loop for ravel_multi_index */
957static int
958ravel_multi_index_loop(int ravel_ndim, npy_intp *ravel_dims,
959 npy_intp *ravel_strides,
960 npy_intp count,
961 NPY_CLIPMODE *modes,
962 char **coords, npy_intp *coords_strides)
963{
964 int i;
965 char invalid;
966 npy_intp j, m;
967
968 /*
969 * Check for 0-dimensional axes unless there is nothing to do.
970 * An empty array/shape cannot be indexed at all.
971 */
972 if (count != 0) {
973 for (i = 0; i < ravel_ndim; ++i) {
974 if (ravel_dims[i] == 0) {
975 PyErr_SetString(PyExc_ValueError,
976 "cannot unravel if shape has zero entries (is empty).");
977 return NPY_FAIL;
978 }
979 }
980 }
981
982 NPY_BEGIN_ALLOW_THREADS;
983 invalid = 0;
984 while (count--) {
985 npy_intp raveled = 0;
986 for (i = 0; i < ravel_ndim; ++i) {
987 m = ravel_dims[i];
988 j = *(npy_intp *)coords[i];
989 switch (modes[i]) {
990 case NPY_RAISE:
991 if (j < 0 || j >= m) {
992 invalid = 1;
993 goto end_while;
994 }
995 break;
996 case NPY_WRAP:
997 if (j < 0) {
998 j += m;
999 if (j < 0) {
1000 j = j % m;
1001 if (j != 0) {
1002 j += m;
1003 }
1004 }
1005 }
1006 else if (j >= m) {
1007 j -= m;
1008 if (j >= m) {
1009 j = j % m;
1010 }
1011 }
1012 break;
1013 case NPY_CLIP:
1014 if (j < 0) {

Callers 1

arr_ravel_multi_indexFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected