diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/add_newdocs.py | 26 | ||||
-rw-r--r-- | numpy/core/code_generators/numpy_api.py | 8 | ||||
-rw-r--r-- | numpy/core/include/numpy/ndarraytypes.h | 6 | ||||
-rw-r--r-- | numpy/core/src/multiarray/item_selection.c | 24 | ||||
-rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.c | 2 | ||||
-rw-r--r-- | numpy/core/src/multiarray/nditer.c.src | 318 | ||||
-rw-r--r-- | numpy/core/src/multiarray/nditer_pywrap.c | 99 | ||||
-rw-r--r-- | numpy/core/src/umath/ufunc_object.c | 12 | ||||
-rw-r--r-- | numpy/core/tests/test_iterator.py | 164 | ||||
-rw-r--r-- | numpy/lib/index_tricks.py | 4 | ||||
-rw-r--r-- | numpy/lib/src/_compiled_base.c | 31 | ||||
-rw-r--r-- | numpy/lib/tests/test_index_tricks.py | 44 |
12 files changed, 372 insertions, 366 deletions
diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py index c62fcd186..8499b3d9d 100644 --- a/numpy/add_newdocs.py +++ b/numpy/add_newdocs.py @@ -4429,19 +4429,19 @@ add_newdoc('numpy.lib._compiled_base', 'bincount', """) -add_newdoc('numpy.lib._compiled_base', 'ravel_coords', +add_newdoc('numpy.lib._compiled_base', 'ravel_multi_index', """ - ravel_coords(coords, dims, mode='raise', order='C') + ravel_multi_index(multi_index, dims, mode='raise', order='C') - Converts a tuple of coordinate arrays into an array of flat - indices, applying boundary modes to the coordinates. + Converts a tuple of index arrays into an array of flat + indices, applying boundary modes to the multi-index. Parameters ---------- - coords : tuple of array_like + multi_index : tuple of array_like A tuple of integer arrays, one array for each dimension. dims : tuple of ints - The shape of array into which the indices from ``coords`` apply. + The shape of array into which the indices from ``multi_index`` apply. mode : {'raise', 'wrap', 'clip'}, optional Specifies how out-of-bounds indices are handled. Can specify either one mode or a tuple of modes, one mode per index. @@ -4453,7 +4453,7 @@ add_newdoc('numpy.lib._compiled_base', 'ravel_coords', In 'clip' mode, a negative index which would normally wrap will clip to 0 instead. order : {'C', 'F'}, optional - Determines whether the coords should be viewed as indexing in + Determines whether the multi-index should be viewed as indexing in C (row-major) order or FORTRAN (column-major) order. Returns @@ -4473,16 +4473,16 @@ add_newdoc('numpy.lib._compiled_base', 'ravel_coords', Examples -------- >>> arr = np.array([[3,6,6],[4,5,1]]) - >>> np.ravel_coords(arr, (7,6)) + >>> np.ravel_multi_index(arr, (7,6)) array([22, 41, 37]) - >>> np.ravel_coords(arr, (7,6), order='F') + >>> np.ravel_multi_index(arr, (7,6), order='F') array([31, 41, 13]) - >>> np.ravel_coords(arr, (4,6), mode='clip') + >>> np.ravel_multi_index(arr, (4,6), mode='clip') array([22, 23, 19]) - >>> np.ravel_coords(arr, (4,4), mode=('clip','wrap')) + >>> np.ravel_multi_index(arr, (4,4), mode=('clip','wrap')) array([12, 13, 13]) - >>> np.ravel_coords((3,1,4,1), (6,7,8,9)) + >>> np.ravel_multi_index((3,1,4,1), (6,7,8,9)) 1621 """) @@ -4515,7 +4515,7 @@ add_newdoc('numpy.lib._compiled_base', 'unravel_index', See Also -------- - ravel_coords + ravel_multi_index Examples -------- diff --git a/numpy/core/code_generators/numpy_api.py b/numpy/core/code_generators/numpy_api.py index 4aef212bf..b314f9f84 100644 --- a/numpy/core/code_generators/numpy_api.py +++ b/numpy/core/code_generators/numpy_api.py @@ -277,11 +277,11 @@ multiarray_funcs_api = { 'NpyIter_GetIterIndexRange': 241, 'NpyIter_GetIterIndex': 242, 'NpyIter_GotoIterIndex': 243, - 'NpyIter_HasCoords': 244, + 'NpyIter_HasMultiIndex': 244, 'NpyIter_GetShape': 245, - 'NpyIter_GetGetCoords': 246, - 'NpyIter_GotoCoords': 247, - 'NpyIter_RemoveCoords': 248, + 'NpyIter_GetGetMultiIndex': 246, + 'NpyIter_GotoMultiIndex': 247, + 'NpyIter_RemoveMultiIndex': 248, 'NpyIter_HasIndex': 249, 'NpyIter_IsBuffered': 250, 'NpyIter_IsGrowInner': 251, diff --git a/numpy/core/include/numpy/ndarraytypes.h b/numpy/core/include/numpy/ndarraytypes.h index 26077ba59..4cd2de70e 100644 --- a/numpy/core/include/numpy/ndarraytypes.h +++ b/numpy/core/include/numpy/ndarraytypes.h @@ -868,7 +868,7 @@ typedef struct NpyIter_InternalOnly NpyIter; /* Iterator function pointers that may be specialized */ typedef int (NpyIter_IterNextFunc)(NpyIter *iter); -typedef void (NpyIter_GetCoordsFunc)(NpyIter *iter, +typedef void (NpyIter_GetMultiIndexFunc)(NpyIter *iter, npy_intp *outcoords); /*** Global flags that may be passed to the iterator constructors ***/ @@ -877,8 +877,8 @@ typedef void (NpyIter_GetCoordsFunc)(NpyIter *iter, #define NPY_ITER_C_INDEX 0x00000001 /* Track an index representing Fortran order */ #define NPY_ITER_F_INDEX 0x00000002 -/* Track coordinates */ -#define NPY_ITER_COORDS 0x00000004 +/* Track a multi-index */ +#define NPY_ITER_MULTI_INDEX 0x00000004 /* User code external to the iterator does the 1-dimensional innermost loop */ #define NPY_ITER_EXTERNAL_LOOP 0x00000008 /* Convert all the operands to a common data type */ diff --git a/numpy/core/src/multiarray/item_selection.c b/numpy/core/src/multiarray/item_selection.c index 91d5f1f4e..3b3a0a5ae 100644 --- a/numpy/core/src/multiarray/item_selection.c +++ b/numpy/core/src/multiarray/item_selection.c @@ -1780,11 +1780,11 @@ PyArray_Nonzero(PyArrayObject *self) char *data; npy_intp stride, count; npy_intp nonzero_count = PyArray_CountNonzero(self); - npy_intp *coords; + npy_intp *multi_index; NpyIter *iter; NpyIter_IterNextFunc *iternext; - NpyIter_GetCoordsFunc *getcoords; + NpyIter_GetMultiIndexFunc *get_multi_index; char **dataptr; npy_intp *innersizeptr; @@ -1802,14 +1802,14 @@ PyArray_Nonzero(PyArrayObject *self) if (ndim <= 1) { npy_intp j; - coords = (npy_intp *)PyArray_DATA(ret); + multi_index = (npy_intp *)PyArray_DATA(ret); data = PyArray_BYTES(self); stride = (ndim == 0) ? 0 : PyArray_STRIDE(self, 0); count = (ndim == 0) ? 1 : PyArray_DIM(self, 0); for (j = 0; j < count; ++j) { if (nonzero(data, self)) { - *coords++ = j; + *multi_index++ = j; } data += stride; } @@ -1817,9 +1817,9 @@ PyArray_Nonzero(PyArrayObject *self) goto finish; } - /* Build an iterator with coordinates, in C order */ + /* Build an iterator tracking a multi-index, in C order */ iter = NpyIter_New(self, NPY_ITER_READONLY| - NPY_ITER_COORDS| + NPY_ITER_MULTI_INDEX| NPY_ITER_ZEROSIZE_OK| NPY_ITER_REFS_OK, NPY_CORDER, NPY_NO_CASTING, @@ -1838,8 +1838,8 @@ PyArray_Nonzero(PyArrayObject *self) Py_DECREF(ret); return NULL; } - getcoords = NpyIter_GetGetCoords(iter, NULL); - if (getcoords == NULL) { + get_multi_index = NpyIter_GetGetMultiIndex(iter, NULL); + if (get_multi_index == NULL) { NpyIter_Deallocate(iter); Py_DECREF(ret); return NULL; @@ -1847,13 +1847,13 @@ PyArray_Nonzero(PyArrayObject *self) dataptr = NpyIter_GetDataPtrArray(iter); innersizeptr = NpyIter_GetInnerLoopSizePtr(iter); - coords = (npy_intp *)PyArray_DATA(ret); + multi_index = (npy_intp *)PyArray_DATA(ret); - /* Get the coordinates for each non-zero element */ + /* Get the multi-index for each non-zero element */ do { if (nonzero(*dataptr, self)) { - getcoords(iter, coords); - coords += ndim; + get_multi_index(iter, multi_index); + multi_index += ndim; } } while(iternext(iter)); } diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index db381cc84..ba31b0be7 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -1345,7 +1345,7 @@ PyArray_ClipmodeConverter(PyObject *object, NPY_CLIPMODE *val) /*NUMPY_API * Convert an object to an array of n NPY_CLIPMODE values. * This is intended to be used in functions where a different mode - * could be applied to each axis, like in ravel_coords. + * could be applied to each axis, like in ravel_multi_index. */ NPY_NO_EXPORT int PyArray_ConvertClipmodeSequence(PyObject *object, NPY_CLIPMODE *modes, int n) diff --git a/numpy/core/src/multiarray/nditer.c.src b/numpy/core/src/multiarray/nditer.c.src index 648d32a33..e12767fbb 100644 --- a/numpy/core/src/multiarray/nditer.c.src +++ b/numpy/core/src/multiarray/nditer.c.src @@ -1,5 +1,5 @@ /* - * This file implements the new, highly flexible iterator for NumPy. + * This file implements a highly flexible iterator for NumPy. * * Copyright (c) 2010-2011 by Mark Wiebe (mwwiebe@gmail.com) * The Univerity of British Columbia @@ -75,8 +75,8 @@ #define NPY_ITFLAG_NEGPERM 0x0002 /* The iterator is tracking an index */ #define NPY_ITFLAG_HASINDEX 0x0004 -/* The iterator is tracking coordinates */ -#define NPY_ITFLAG_HASCOORDS 0x0008 +/* The iterator is tracking a multi-index */ +#define NPY_ITFLAG_HASMULTIINDEX 0x0008 /* The iteration order was forced on construction */ #define NPY_ITFLAG_FORCEDORDER 0x0010 /* The inner loop is handled outside the iterator */ @@ -242,11 +242,11 @@ struct NpyIter_BD { /* Internal-only AXISDATA MEMBER ACCESS. */ struct NpyIter_AD { - npy_intp shape, coord; + npy_intp shape, index; npy_intp ad_flexdata; }; #define NAD_SHAPE(axisdata) ((axisdata)->shape) -#define NAD_COORD(axisdata) ((axisdata)->coord) +#define NAD_INDEX(axisdata) ((axisdata)->index) #define NAD_STRIDES(axisdata) ( \ &(axisdata)->ad_flexdata + 0) #define NAD_PTRS(axisdata) ((char **) \ @@ -259,7 +259,7 @@ struct NpyIter_AD { #define NIT_AXISDATA_SIZEOF(itflags, ndim, niter) (( \ /* intp shape */ \ 1 + \ - /* intp coord */ \ + /* intp index */ \ 1 + \ /* intp stride[niter+1] AND char* ptr[niter+1] */ \ 2*((niter)+1) \ @@ -672,10 +672,10 @@ NpyIter_AdvancedNew(int niter, PyArrayObject **op_in, npy_uint32 flags, NPY_IT_TIME_POINT(c_allocate_arrays); /* - * Finally, if coords weren't requested, + * Finally, if a multi-index wasn't requested, * it may be possible to coalesce some axes together. */ - if (ndim > 1 && !(itflags&NPY_ITFLAG_HASCOORDS)) { + if (ndim > 1 && !(itflags&NPY_ITFLAG_HASMULTIINDEX)) { npyiter_coalesce_axes(iter); /* * The operation may have changed the layout, so we have to @@ -962,7 +962,7 @@ NpyIter_Deallocate(NpyIter *iter) } /*NUMPY_API - * Removes an axis from iteration. This requires that NPY_ITER_COORDS + * Removes an axis from iteration. This requires that NPY_ITER_MULTI_INDEX * was set for iterator creation, and does not work if buffering is * enabled. This function also resets the iterator to its initial state. * @@ -983,10 +983,10 @@ NpyIter_RemoveAxis(NpyIter *iter, int axis) npy_intp *baseoffsets = NIT_BASEOFFSETS(iter); char **resetdataptr = NIT_RESETDATAPTR(iter); - if (!(itflags&NPY_ITFLAG_HASCOORDS)) { + if (!(itflags&NPY_ITFLAG_HASMULTIINDEX)) { PyErr_SetString(PyExc_RuntimeError, "Iterator RemoveAxis may only be called " - "if coordinates are being tracked"); + "if a multi-index is being tracked"); return NPY_FAIL; } else if (itflags&NPY_ITFLAG_HASINDEX) { @@ -1092,12 +1092,12 @@ NpyIter_RemoveAxis(NpyIter *iter, int axis) } /*NUMPY_API - * Removes coords support from an iterator. + * Removes multi-index support from an iterator. * * Returns NPY_SUCCEED or NPY_FAIL. */ NPY_NO_EXPORT int -NpyIter_RemoveCoords(NpyIter *iter) +NpyIter_RemoveMultiIndex(NpyIter *iter) { npy_uint32 itflags; @@ -1107,8 +1107,8 @@ NpyIter_RemoveCoords(NpyIter *iter) } itflags = NIT_ITFLAGS(iter); - if (itflags&NPY_ITFLAG_HASCOORDS) { - NIT_ITFLAGS(iter) = itflags & ~NPY_ITFLAG_HASCOORDS; + if (itflags&NPY_ITFLAG_HASMULTIINDEX) { + NIT_ITFLAGS(iter) = itflags & ~NPY_ITFLAG_HASMULTIINDEX; npyiter_coalesce_axes(iter); } @@ -1126,10 +1126,10 @@ NpyIter_EnableExternalLoop(NpyIter *iter) int niter = NIT_NITER(iter); /* Check conditions under which this can be done */ - if (itflags&(NPY_ITFLAG_HASINDEX|NPY_ITFLAG_HASCOORDS)) { + if (itflags&(NPY_ITFLAG_HASINDEX|NPY_ITFLAG_HASMULTIINDEX)) { PyErr_SetString(PyExc_ValueError, "Iterator flag EXTERNAL_LOOP cannot be used " - "if coords or an index is being tracked"); + "if an index or multi-index is being tracked"); return NPY_FAIL; } if ((itflags&(NPY_ITFLAG_BUFFER|NPY_ITFLAG_RANGE|NPY_ITFLAG_EXLOOP)) @@ -1319,15 +1319,15 @@ NpyIter_ResetToIterIndexRange(NpyIter *iter, } /*NUMPY_API - * Sets the iterator to the specified coordinates, which must have the + * Sets the iterator to the specified multi-index, which must have the * correct number of entries for 'ndim'. It is only valid - * when NPY_ITER_COORDS was passed to the constructor. This operation - * fails if the coordinates are out of bounds. + * when NPY_ITER_MULTI_INDEX was passed to the constructor. This operation + * fails if the multi-index is out of bounds. * * Returns NPY_SUCCEED on success, NPY_FAIL on failure. */ NPY_NO_EXPORT int -NpyIter_GotoCoords(NpyIter *iter, npy_intp *coords) +NpyIter_GotoMultiIndex(NpyIter *iter, npy_intp *multi_index) { npy_uint32 itflags = NIT_ITFLAGS(iter); int idim, ndim = NIT_NDIM(iter); @@ -1338,23 +1338,23 @@ NpyIter_GotoCoords(NpyIter *iter, npy_intp *coords) npy_intp sizeof_axisdata; char *perm; - if (!(itflags&NPY_ITFLAG_HASCOORDS)) { + if (!(itflags&NPY_ITFLAG_HASMULTIINDEX)) { PyErr_SetString(PyExc_ValueError, - "Cannot call GotoCoords on an iterator without " - "requesting coordinates in the constructor"); + "Cannot call GotoMultiIndex on an iterator without " + "requesting a multi-index in the constructor"); return NPY_FAIL; } if (itflags&NPY_ITFLAG_BUFFER) { PyErr_SetString(PyExc_ValueError, - "Cannot call GotoCoords on an iterator which " + "Cannot call GotoMultiIndex on an iterator which " "is buffered"); return NPY_FAIL; } if (itflags&NPY_ITFLAG_EXLOOP) { PyErr_SetString(PyExc_ValueError, - "Cannot call GotoCoords on an iterator which " + "Cannot call GotoMultiIndex on an iterator which " "has the flag EXTERNAL_LOOP"); return NPY_FAIL; } @@ -1363,7 +1363,7 @@ NpyIter_GotoCoords(NpyIter *iter, npy_intp *coords) axisdata = NIT_AXISDATA(iter); sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter); - /* Compute the iterindex corresponding to the coordinates */ + /* Compute the iterindex corresponding to the multi-index */ iterindex = 0; factor = 1; for (idim = 0; idim < ndim; ++idim) { @@ -1372,22 +1372,22 @@ NpyIter_GotoCoords(NpyIter *iter, npy_intp *coords) shape = NAD_SHAPE(axisdata); if (p < 0) { - /* If the perm entry is negative, reverse the coordinate */ - i = shape - coords[ndim+p] - 1; + /* If the perm entry is negative, reverse the index */ + i = shape - multi_index[ndim+p] - 1; } else { - i = coords[ndim-p-1]; + i = multi_index[ndim-p-1]; } - /* Bounds-check this coordinate */ + /* Bounds-check this index */ if (i >= 0 && i < shape) { iterindex += factor * i; factor *= shape; } else { PyErr_SetString(PyExc_IndexError, - "Iterator GotoCoords called with out-of-bounds " - "coordinates."); + "Iterator GotoMultiIndex called with an out-of-bounds " + "multi-index"); return NPY_FAIL; } @@ -1396,8 +1396,8 @@ NpyIter_GotoCoords(NpyIter *iter, npy_intp *coords) if (iterindex < NIT_ITERSTART(iter) || iterindex >= NIT_ITEREND(iter)) { PyErr_SetString(PyExc_IndexError, - "Iterator GotoCoords called with coordinates outside the " - "iteration range."); + "Iterator GotoMultiIndex called with a multi-index outside the " + "restricted iteration range"); return NPY_FAIL; } @@ -1413,7 +1413,7 @@ NpyIter_GotoCoords(NpyIter *iter, npy_intp *coords) * Returns NPY_SUCCEED on success, NPY_FAIL on failure. */ NPY_NO_EXPORT int -NpyIter_GotoIndex(NpyIter *iter, npy_intp index) +NpyIter_GotoIndex(NpyIter *iter, npy_intp flat_index) { npy_uint32 itflags = NIT_ITFLAGS(iter); int idim, ndim = NIT_NDIM(iter); @@ -1426,7 +1426,7 @@ NpyIter_GotoIndex(NpyIter *iter, npy_intp index) if (!(itflags&NPY_ITFLAG_HASINDEX)) { PyErr_SetString(PyExc_ValueError, "Cannot call GotoIndex on an iterator without " - "requesting an index in the constructor"); + "requesting a C or Fortran index in the constructor"); return NPY_FAIL; } @@ -1444,17 +1444,17 @@ NpyIter_GotoIndex(NpyIter *iter, npy_intp index) return NPY_FAIL; } - if (index < 0 || index >= NIT_ITERSIZE(iter)) { + if (flat_index < 0 || flat_index >= NIT_ITERSIZE(iter)) { PyErr_SetString(PyExc_IndexError, "Iterator GotoIndex called with an out-of-bounds " - "index."); + "index"); return NPY_FAIL; } axisdata = NIT_AXISDATA(iter); sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter); - /* Compute the iterindex corresponding to the index */ + /* Compute the iterindex corresponding to the flat_index */ iterindex = 0; factor = 1; for (idim = 0; idim < ndim; ++idim) { @@ -1463,15 +1463,15 @@ NpyIter_GotoIndex(NpyIter *iter, npy_intp index) iterstride = NAD_STRIDES(axisdata)[niter]; shape = NAD_SHAPE(axisdata); - /* Extract the coordinate from the index */ + /* Extract the index from the flat_index */ if (iterstride == 0) { i = 0; } else if (iterstride < 0) { - i = shape - (index/(-iterstride))%shape - 1; + i = shape - (flat_index/(-iterstride))%shape - 1; } else { - i = (index/iterstride)%shape; + i = (flat_index/iterstride)%shape; } /* Add its contribution to iterindex */ @@ -1485,7 +1485,7 @@ NpyIter_GotoIndex(NpyIter *iter, npy_intp index) if (iterindex < NIT_ITERSTART(iter) || iterindex >= NIT_ITEREND(iter)) { PyErr_SetString(PyExc_IndexError, "Iterator GotoIndex called with an index outside the " - "iteration range."); + "restricted iteration range."); return NPY_FAIL; } @@ -1585,11 +1585,11 @@ NpyIter_GetIterIndex(NpyIter *iter) axisdata = NIT_INDEX_AXISDATA(NIT_AXISDATA(iter), ndim-1); for (idim = ndim-2; idim >= 0; --idim) { - iterindex += NAD_COORD(axisdata); + iterindex += NAD_INDEX(axisdata); NIT_ADVANCE_AXISDATA(axisdata, -1); iterindex *= NAD_SHAPE(axisdata); } - iterindex += NAD_COORD(axisdata); + iterindex += NAD_INDEX(axisdata); return iterindex; } @@ -1652,8 +1652,8 @@ npyiter_iternext_itflags@tag_itflags@_dims@tag_ndim@_iters@tag_niter@( axisdata0 = NIT_AXISDATA(iter); # if !(@const_itflags@&NPY_ITFLAG_EXLOOP) - /* Increment coordinate 0 */ - NAD_COORD(axisdata0)++; + /* Increment index 0 */ + NAD_INDEX(axisdata0)++; /* Increment pointer 0 */ for (istrides = 0; istrides < nstrides; ++istrides) { NAD_PTRS(axisdata0)[istrides] += NAD_STRIDES(axisdata0)[istrides]; @@ -1663,8 +1663,8 @@ npyiter_iternext_itflags@tag_itflags@_dims@tag_ndim@_iters@tag_niter@( #if @const_ndim@ == 1 # if !(@const_itflags@&NPY_ITFLAG_EXLOOP) - /* Finished when the coordinate equals the shape */ - return NAD_COORD(axisdata0) < NAD_SHAPE(axisdata0); + /* Finished when the index equals the shape */ + return NAD_INDEX(axisdata0) < NAD_SHAPE(axisdata0); # else /* Get rid of unused variable warning */ istrides = 0; @@ -1675,22 +1675,22 @@ npyiter_iternext_itflags@tag_itflags@_dims@tag_ndim@_iters@tag_niter@( #else # if !(@const_itflags@&NPY_ITFLAG_EXLOOP) - if (NAD_COORD(axisdata0) < NAD_SHAPE(axisdata0)) { + if (NAD_INDEX(axisdata0) < NAD_SHAPE(axisdata0)) { return 1; } # endif axisdata1 = NIT_INDEX_AXISDATA(axisdata0, 1); - /* Increment coordinate 1 */ - NAD_COORD(axisdata1)++; + /* Increment index 1 */ + NAD_INDEX(axisdata1)++; /* Increment pointer 1 */ for (istrides = 0; istrides < nstrides; ++istrides) { NAD_PTRS(axisdata1)[istrides] += NAD_STRIDES(axisdata1)[istrides]; } - if (NAD_COORD(axisdata1) < NAD_SHAPE(axisdata1)) { - /* Reset the 1st coordinate to 0 */ - NAD_COORD(axisdata0) = 0; + if (NAD_INDEX(axisdata1) < NAD_SHAPE(axisdata1)) { + /* Reset the 1st index to 0 */ + NAD_INDEX(axisdata0) = 0; /* Reset the 1st pointer to the value of the 2nd */ for (istrides = 0; istrides < nstrides; ++istrides) { NAD_PTRS(axisdata0)[istrides] = NAD_PTRS(axisdata1)[istrides]; @@ -1703,17 +1703,17 @@ npyiter_iternext_itflags@tag_itflags@_dims@tag_ndim@_iters@tag_niter@( # else axisdata2 = NIT_INDEX_AXISDATA(axisdata1, 1); - /* Increment coordinate 2 */ - NAD_COORD(axisdata2)++; + /* Increment index 2 */ + NAD_INDEX(axisdata2)++; /* Increment pointer 2 */ for (istrides = 0; istrides < nstrides; ++istrides) { NAD_PTRS(axisdata2)[istrides] += NAD_STRIDES(axisdata2)[istrides]; } - if (NAD_COORD(axisdata2) < NAD_SHAPE(axisdata2)) { - /* Reset the 1st and 2nd coordinates to 0 */ - NAD_COORD(axisdata0) = 0; - NAD_COORD(axisdata1) = 0; + if (NAD_INDEX(axisdata2) < NAD_SHAPE(axisdata2)) { + /* Reset the 1st and 2nd indices to 0 */ + NAD_INDEX(axisdata0) = 0; + NAD_INDEX(axisdata1) = 0; /* Reset the 1st and 2nd pointers to the value of the 3nd */ for (istrides = 0; istrides < nstrides; ++istrides) { NAD_PTRS(axisdata0)[istrides] = NAD_PTRS(axisdata2)[istrides]; @@ -1724,21 +1724,21 @@ npyiter_iternext_itflags@tag_itflags@_dims@tag_ndim@_iters@tag_niter@( for (idim = 3; idim < ndim; ++idim) { NIT_ADVANCE_AXISDATA(axisdata2, 1); - /* Increment the coordinate */ - NAD_COORD(axisdata2)++; + /* Increment the index */ + NAD_INDEX(axisdata2)++; /* Increment the pointer */ for (istrides = 0; istrides < nstrides; ++istrides) { NAD_PTRS(axisdata2)[istrides] += NAD_STRIDES(axisdata2)[istrides]; } - if (NAD_COORD(axisdata2) < NAD_SHAPE(axisdata2)) { - /* Reset the coordinates and pointers of all previous axisdatas */ + if (NAD_INDEX(axisdata2) < NAD_SHAPE(axisdata2)) { + /* Reset the indices and pointers of all previous axisdatas */ axisdata1 = axisdata2; do { NIT_ADVANCE_AXISDATA(axisdata1, -1); - /* Reset the coordinate to 0 */ - NAD_COORD(axisdata1) = 0; + /* Reset the index to 0 */ + NAD_INDEX(axisdata1) = 0; /* Reset the pointer to the updated value */ for (istrides = 0; istrides < nstrides; ++istrides) { NAD_PTRS(axisdata1)[istrides] = @@ -1793,7 +1793,7 @@ npyiter_buffered_reduce_iternext_iters@tag_niter@(NpyIter *iter) /* * If the iterator handles the inner loop, need to increment all - * the coordinates and pointers + * the indices and pointers */ if (!(itflags&NPY_ITFLAG_EXLOOP)) { /* Increment within the buffer */ @@ -1863,7 +1863,7 @@ npyiter_buffered_iternext(NpyIter *iter) /* * If the iterator handles the inner loop, need to increment all - * the coordinates and pointers + * the indices and pointers */ if (!(itflags&NPY_ITFLAG_EXLOOP)) { /* Increment within the buffer */ @@ -2033,7 +2033,7 @@ NpyIter_GetIterNext(NpyIter *iter, char **errmsg) } -/* SPECIALIZED getcoord functions */ +/* SPECIALIZED getindex functions */ /**begin repeat * #const_itflags = 0, @@ -2052,7 +2052,8 @@ NpyIter_GetIterNext(NpyIter *iter, char **errmsg) * BUF, INDuBUF, IDPuBUF, INDuIDPuBUF, NEGPuBUF, INDuNEGPuBUF# */ static void -npyiter_getcoord_itflags@tag_itflags@(NpyIter *iter, npy_intp *outcoord) +npyiter_get_multi_index_itflags@tag_itflags@( + NpyIter *iter, npy_intp *out_multi_index) { const npy_uint32 itflags = @const_itflags@; int idim, ndim = NIT_NDIM(iter); @@ -2067,25 +2068,25 @@ npyiter_getcoord_itflags@tag_itflags@(NpyIter *iter, npy_intp *outcoord) axisdata = NIT_AXISDATA(iter); sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter); #if ((@const_itflags@)&NPY_ITFLAG_IDENTPERM) - outcoord += ndim-1; - for(idim = 0; idim < ndim; ++idim, --outcoord, + out_multi_index += ndim-1; + for(idim = 0; idim < ndim; ++idim, --out_multi_index, NIT_ADVANCE_AXISDATA(axisdata, 1)) { - *outcoord = NAD_COORD(axisdata); + *out_multi_index = NAD_INDEX(axisdata); } #elif !((@const_itflags@)&NPY_ITFLAG_NEGPERM) for(idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) { char p = perm[idim]; - outcoord[ndim-p-1] = NAD_COORD(axisdata); + out_multi_index[ndim-p-1] = NAD_INDEX(axisdata); } #else for(idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) { char p = perm[idim]; if (p < 0) { - /* If the perm entry is negative, reverse the coordinate */ - outcoord[ndim+p] = NAD_SHAPE(axisdata) - NAD_COORD(axisdata) - 1; + /* If the perm entry is negative, reverse the index */ + out_multi_index[ndim+p] = NAD_SHAPE(axisdata) - NAD_INDEX(axisdata) - 1; } else { - outcoord[ndim-p-1] = NAD_COORD(axisdata); + out_multi_index[ndim-p-1] = NAD_INDEX(axisdata); } } #endif /* not ident perm */ @@ -2093,43 +2094,43 @@ npyiter_getcoord_itflags@tag_itflags@(NpyIter *iter, npy_intp *outcoord) /**end repeat**/ /*NUMPY_API - * Compute a specialized getcoords function for the iterator + * Compute a specialized get_multi_index function for the iterator * * If errmsg is non-NULL, it should point to a variable which will * receive the error message, and no Python exception will be set. * This is so that the function can be called from code not holding * the GIL. */ -NPY_NO_EXPORT NpyIter_GetCoordsFunc * -NpyIter_GetGetCoords(NpyIter *iter, char **errmsg) +NPY_NO_EXPORT NpyIter_GetMultiIndexFunc * +NpyIter_GetGetMultiIndex(NpyIter *iter, char **errmsg) { npy_uint32 itflags = NIT_ITFLAGS(iter); int ndim = NIT_NDIM(iter); int niter = NIT_NITER(iter); /* These flags must be correct */ - if ((itflags&(NPY_ITFLAG_HASCOORDS|NPY_ITFLAG_DELAYBUF)) != - NPY_ITFLAG_HASCOORDS) { - if (!(itflags&NPY_ITFLAG_HASCOORDS)) { + if ((itflags&(NPY_ITFLAG_HASMULTIINDEX|NPY_ITFLAG_DELAYBUF)) != + NPY_ITFLAG_HASMULTIINDEX) { + if (!(itflags&NPY_ITFLAG_HASMULTIINDEX)) { if (errmsg == NULL) { PyErr_SetString(PyExc_ValueError, - "Cannot retrieve a GetCoords function for an iterator " - "that doesn't track coordinates."); + "Cannot retrieve a GetMultiIndex function for an " + "iterator that doesn't track a multi-index."); } else { - *errmsg = "Cannot retrieve a GetCoords function for an " - "iterator that doesn't track coordinates."; + *errmsg = "Cannot retrieve a GetMultiIndex function for an " + "iterator that doesn't track a multi-index."; } return NULL; } else { if (errmsg == NULL) { PyErr_SetString(PyExc_ValueError, - "Cannot retrieve a GetCoords function for an iterator " - "that used DELAY_BUFALLOC before a Reset call"); + "Cannot retrieve a GetMultiIndex function for an " + "iterator that used DELAY_BUFALLOC before a Reset call"); } else { - *errmsg = "Cannot retrieve a GetCoords function for an " + *errmsg = "Cannot retrieve a GetMultiIndex function for an " "iterator that used DELAY_BUFALLOC before a " "Reset call"; } @@ -2139,7 +2140,7 @@ NpyIter_GetGetCoords(NpyIter *iter, char **errmsg) /* * Only these flags affect the iterator memory layout or - * the getcoords behavior. IDENTPERM and NEGPERM are mutually + * the get_multi_index behavior. IDENTPERM and NEGPERM are mutually * exclusive, so that reduces the number of cases slightly. */ itflags &= (NPY_ITFLAG_HASINDEX | @@ -2165,18 +2166,18 @@ NpyIter_GetGetCoords(NpyIter *iter, char **errmsg) * BUF, INDuBUF, IDPuBUF, INDuIDPuBUF, NEGPuBUF, INDuNEGPuBUF# */ case @const_itflags@: - return npyiter_getcoord_itflags@tag_itflags@; + return npyiter_get_multi_index_itflags@tag_itflags@; /**end repeat**/ } /* The switch above should have caught all the possibilities. */ if (errmsg == NULL) { PyErr_Format(PyExc_ValueError, - "GetGetCoords internal iterator error - unexpected " + "GetGetMultiIndex internal iterator error - unexpected " "itflags/ndim/niter combination (%04x/%d/%d)", (int)itflags, (int)ndim, (int)niter); } else { - *errmsg = "GetGetCoords internal iterator error - unexpected " + *errmsg = "GetGetMultiIndex internal iterator error - unexpected " "itflags/ndim/niter combination"; } return NULL; @@ -2202,12 +2203,12 @@ NpyIter_HasExternalLoop(NpyIter *iter) } /*NUMPY_API - * Whether the iterator is tracking coordinates + * Whether the iterator is tracking a multi-index */ NPY_NO_EXPORT npy_bool -NpyIter_HasCoords(NpyIter *iter) +NpyIter_HasMultiIndex(NpyIter *iter) { - return (NIT_ITFLAGS(iter)&NPY_ITFLAG_HASCOORDS) != 0; + return (NIT_ITFLAGS(iter)&NPY_ITFLAG_HASMULTIINDEX) != 0; } /*NUMPY_API @@ -2335,15 +2336,15 @@ NpyIter_GetIterIndexRange(NpyIter *iter, } /*NUMPY_API - * Gets the broadcast shape if coords are being tracked by the iterator, + * Gets the broadcast shape if a multi-index is being tracked by the iterator, * otherwise gets the shape of the iteration as Fortran-order - * (fastest-changing coordinate first). + * (fastest-changing index first). * - * The reason Fortran-order is returned when coords - * are not enabled is that this is providing a direct view into how + * The reason Fortran-order is returned when a multi-index + * is not enabled is that this is providing a direct view into how * the iterator traverses the n-dimensional space. The iterator organizes - * its memory from fastest coordinate to slowest coordinate, and when - * coords are enabled, it uses a permutation to recover the original + * its memory from fastest index to slowest index, and when + * a multi-index is enabled, it uses a permutation to recover the original * order. * * Returns NPY_SUCCEED or NPY_FAIL. @@ -2362,7 +2363,7 @@ NpyIter_GetShape(NpyIter *iter, npy_intp *outshape) axisdata = NIT_AXISDATA(iter); sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter); - if (itflags&NPY_ITFLAG_HASCOORDS) { + if (itflags&NPY_ITFLAG_HASMULTIINDEX) { perm = NIT_PERM(iter); for(idim = 0; idim < ndim; ++idim) { char p = perm[idim]; @@ -2401,7 +2402,7 @@ NpyIter_GetShape(NpyIter *iter, npy_intp *outshape) * you do the same thing but add two dimensions, or take advantage of * the symmetry and pack it into 1 dimension with a particular encoding. * - * This function may only be called if the iterator is tracking coordinates + * This function may only be called if the iterator is tracking a multi-index * and if NPY_ITER_DONT_NEGATE_STRIDES was used to prevent an axis from * being iterated in reverse order. * @@ -2423,10 +2424,10 @@ NpyIter_CreateCompatibleStrides(NpyIter *iter, NpyIter_AxisData *axisdata; char *perm; - if (!(itflags&NPY_ITFLAG_HASCOORDS)) { + if (!(itflags&NPY_ITFLAG_HASMULTIINDEX)) { PyErr_SetString(PyExc_RuntimeError, "Iterator CreateCompatibleStrides may only be called " - "if coordinates are being tracked"); + "if a multi-index is being tracked"); return NPY_FAIL; } @@ -2665,7 +2666,7 @@ NpyIter_GetInnerStrideArray(NpyIter *iter) /*NUMPY_API * Gets the array of strides for the specified axis. - * If the iterator is tracking coordinates, gets the strides + * If the iterator is tracking a multi-index, gets the strides * for the axis specified, otherwise gets the strides for * the iteration axis as Fortran order (fastest-changing axis first). * @@ -2688,7 +2689,7 @@ NpyIter_GetAxisStrideArray(NpyIter *iter, int axis) return NULL; } - if (itflags&NPY_ITFLAG_HASCOORDS) { + if (itflags&NPY_ITFLAG_HASMULTIINDEX) { /* Reverse axis, since the iterator treats them that way */ axis = ndim-1-axis; @@ -2818,7 +2819,7 @@ NpyIter_GetInnerLoopSizePtr(NpyIter *iter) } } -/* Checks 'flags' for (C|F)_ORDER_INDEX, COORDS, and EXTERNAL_LOOP, +/* Checks 'flags' for (C|F)_ORDER_INDEX, MULTI_INDEX, and EXTERNAL_LOOP, * setting the appropriate internal flags in 'itflags'. * * Returns 1 on success, 0 on error. @@ -2844,20 +2845,20 @@ npyiter_check_global_flags(npy_uint32 flags, npy_uint32* itflags) } (*itflags) |= NPY_ITFLAG_HASINDEX; } - /* Check if coordinates were requested */ - if (flags&NPY_ITER_COORDS) { + /* Check if a multi-index was requested */ + if (flags&NPY_ITER_MULTI_INDEX) { /* * This flag primarily disables dimension manipulations that - * would produce a different set of coordinates. + * would produce an incorrect multi-index. */ - (*itflags) |= NPY_ITFLAG_HASCOORDS; + (*itflags) |= NPY_ITFLAG_HASMULTIINDEX; } /* Check if the caller wants to handle inner iteration */ if (flags&NPY_ITER_EXTERNAL_LOOP) { - if ((*itflags)&(NPY_ITFLAG_HASINDEX|NPY_ITFLAG_HASCOORDS)) { + if ((*itflags)&(NPY_ITFLAG_HASINDEX|NPY_ITFLAG_HASMULTIINDEX)) { PyErr_SetString(PyExc_ValueError, "Iterator flag EXTERNAL_LOOP cannot be used " - "if coords or an index is being tracked"); + "if an index or multi-index is being tracked"); return 0; } (*itflags) |= NPY_ITFLAG_EXLOOP; @@ -3539,7 +3540,7 @@ npyiter_fill_axisdata(NpyIter *iter, npy_uint32 flags, char *op_itflags, npy_intp *strides = NAD_STRIDES(axisdata); NAD_SHAPE(axisdata) = bshape; - NAD_COORD(axisdata) = 0; + NAD_INDEX(axisdata) = 0; memcpy(NAD_PTRS(axisdata), op_dataptr, NPY_SIZEOF_INTP*niter); for (iiter = 0; iiter < niter; ++iiter) { @@ -4155,7 +4156,10 @@ npyiter_flip_negative_strides(NpyIter *iter) /* Flip the stride */ strides[istrides] = -stride; } - /* Make the perm entry negative, so getcoords knows it's flipped */ + /* + * Make the perm entry negative so get_multi_index + * knows it's flipped + */ NIT_PERM(iter)[idim] = -1-NIT_PERM(iter)[idim]; any_flipped = 1; @@ -4320,17 +4324,17 @@ npyiter_find_best_axis_ordering(NpyIter *iter) npy_intp i, size = sizeof_axisdata/NPY_SIZEOF_INTP; NpyIter_AxisData *ad_i; - /* Use the coord as a flag, set each to 1 */ + /* Use the index as a flag, set each to 1 */ ad_i = axisdata; for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(ad_i, 1)) { - NAD_COORD(ad_i) = 1; + NAD_INDEX(ad_i) = 1; } /* Apply the permutation by following the cycles */ for (idim = 0; idim < ndim; ++idim) { ad_i = NIT_INDEX_AXISDATA(axisdata, idim); /* If this axis hasn't been touched yet, process it */ - if (NAD_COORD(ad_i) == 1) { + if (NAD_INDEX(ad_i) == 1) { char pidim = perm[idim], qidim; npy_intp tmp; NpyIter_AxisData *ad_p, *ad_q; @@ -4356,11 +4360,11 @@ npyiter_find_best_axis_ordering(NpyIter *iter) pidim = perm[idim]; while (pidim != idim) { - NAD_COORD(NIT_INDEX_AXISDATA(axisdata, pidim)) = 0; + NAD_INDEX(NIT_INDEX_AXISDATA(axisdata, pidim)) = 0; pidim = perm[(int)pidim]; } } - NAD_COORD(ad_i) = 0; + NAD_INDEX(ad_i) = 0; } } /* Clear the identity perm flag */ @@ -4381,8 +4385,8 @@ npyiter_coalesce_axes(NpyIter *iter) NpyIter_AxisData *ad_compress; npy_intp new_ndim = 1; - /* The HASCOORDS or IDENTPERM flags do not apply after coalescing */ - NIT_ITFLAGS(iter) &= ~(NPY_ITFLAG_IDENTPERM|NPY_ITFLAG_HASCOORDS); + /* The HASMULTIINDEX or IDENTPERM flags do not apply after coalescing */ + NIT_ITFLAGS(iter) &= ~(NPY_ITFLAG_IDENTPERM|NPY_ITFLAG_HASMULTIINDEX); axisdata = NIT_AXISDATA(iter); ad_compress = axisdata; @@ -5259,7 +5263,7 @@ npyiter_goto_iterindex(NpyIter *iter, npy_intp iterindex) for (idim = 0; idim < ndim; ++idim) { char **ptrs; - NAD_COORD(axisdata) = 0; + NAD_INDEX(axisdata) = 0; ptrs = NAD_PTRS(axisdata); for (istrides = 0; istrides < nstrides; ++istrides) { ptrs[istrides] = dataptr[istrides]; @@ -5270,21 +5274,21 @@ npyiter_goto_iterindex(NpyIter *iter, npy_intp iterindex) } else { /* - * Set the coordinates, from the fastest-changing to the + * Set the multi-index, from the fastest-changing to the * slowest-changing. */ axisdata = NIT_AXISDATA(iter); shape = NAD_SHAPE(axisdata); i = iterindex; iterindex /= shape; - NAD_COORD(axisdata) = i - iterindex * shape; + NAD_INDEX(axisdata) = i - iterindex * shape; for (idim = 0; idim < ndim-1; ++idim) { NIT_ADVANCE_AXISDATA(axisdata, 1); shape = NAD_SHAPE(axisdata); i = iterindex; iterindex /= shape; - NAD_COORD(axisdata) = i - iterindex * shape; + NAD_INDEX(axisdata) = i - iterindex * shape; } dataptr = NIT_RESETDATAPTR(iter); @@ -5301,7 +5305,7 @@ npyiter_goto_iterindex(NpyIter *iter, npy_intp iterindex) strides = NAD_STRIDES(axisdata); ptrs = NAD_PTRS(axisdata); - i = NAD_COORD(axisdata); + i = NAD_INDEX(axisdata); for (istrides = 0; istrides < nstrides; ++istrides) { ptrs[istrides] = dataptr[istrides] + i*strides[istrides]; @@ -5316,7 +5320,7 @@ npyiter_goto_iterindex(NpyIter *iter, npy_intp iterindex) /* * This gets called after the the buffers have been exhausted, and - * their data needs to be written back to the arrays. The coordinates + * their data needs to be written back to the arrays. The multi-index * must be positioned for the beginning of the buffer. */ static void @@ -5397,7 +5401,7 @@ npyiter_copy_from_buffers(NpyIter *iter) op_transfersize = 1; src_stride = 0; dst_strides = &src_stride; - dst_coords = &NAD_COORD(reduce_outeraxisdata); + dst_coords = &NAD_INDEX(reduce_outeraxisdata); dst_shape = &NAD_SHAPE(reduce_outeraxisdata); ndim_transfer = 1; } @@ -5406,7 +5410,7 @@ npyiter_copy_from_buffers(NpyIter *iter) src_stride = reduce_outerstrides[iiter]; dst_strides = &NAD_STRIDES(reduce_outeraxisdata)[iiter]; - dst_coords = &NAD_COORD(reduce_outeraxisdata); + dst_coords = &NAD_INDEX(reduce_outeraxisdata); dst_shape = &NAD_SHAPE(reduce_outeraxisdata); ndim_transfer = ndim - reduce_outerdim; } @@ -5416,7 +5420,7 @@ npyiter_copy_from_buffers(NpyIter *iter) op_transfersize = NBF_SIZE(bufferdata); src_stride = strides[iiter]; dst_strides = &ad_strides[iiter]; - dst_coords = &NAD_COORD(axisdata); + dst_coords = &NAD_INDEX(axisdata); dst_shape = &NAD_SHAPE(axisdata); ndim_transfer = reduce_outerdim ? reduce_outerdim : 1; @@ -5425,7 +5429,7 @@ npyiter_copy_from_buffers(NpyIter *iter) op_transfersize = transfersize; src_stride = strides[iiter]; dst_strides = &ad_strides[iiter]; - dst_coords = &NAD_COORD(axisdata); + dst_coords = &NAD_INDEX(axisdata); dst_shape = &NAD_SHAPE(axisdata); ndim_transfer = ndim; } @@ -5435,7 +5439,7 @@ npyiter_copy_from_buffers(NpyIter *iter) op_transfersize = transfersize; src_stride = strides[iiter]; dst_strides = &ad_strides[iiter]; - dst_coords = &NAD_COORD(axisdata); + dst_coords = &NAD_INDEX(axisdata); dst_shape = &NAD_SHAPE(axisdata); ndim_transfer = ndim; } @@ -5483,7 +5487,7 @@ npyiter_copy_from_buffers(NpyIter *iter) } /* - * This gets called after the iterator has been positioned to coordinates + * This gets called after the iterator has been positioned to a multi-index * for the start of a buffer. It decides which operands need a buffer, * and copies the data into the buffers. */ @@ -5591,7 +5595,7 @@ npyiter_copy_to_buffers(NpyIter *iter, char **prev_dataptrs) } /* Calculate the maximum size if using a single stride and no buffers */ - singlestridesize = NAD_SHAPE(axisdata)-NAD_COORD(axisdata); + singlestridesize = NAD_SHAPE(axisdata)-NAD_INDEX(axisdata); if (singlestridesize > iterend - iterindex) { singlestridesize = iterend - iterindex; } @@ -5655,7 +5659,7 @@ npyiter_copy_to_buffers(NpyIter *iter, char **prev_dataptrs) (reduce_outerdim == 1) && (transfersize/reduce_innersize <= NAD_SHAPE(reduce_outeraxisdata) - - NAD_COORD(reduce_outeraxisdata))) { + NAD_INDEX(reduce_outeraxisdata))) { ptrs[iiter] = ad_ptrs[iiter]; reduce_outerptrs[iiter] = ptrs[iiter]; strides[iiter] = ad_strides[iiter]; @@ -5689,7 +5693,7 @@ npyiter_copy_to_buffers(NpyIter *iter, char **prev_dataptrs) else if ((reduce_outerdim > 0) && (transfersize/reduce_innersize <= NAD_SHAPE(reduce_outeraxisdata) - - NAD_COORD(reduce_outeraxisdata))) { + NAD_INDEX(reduce_outeraxisdata))) { NPY_IT_DBG_PRINT1("reduce op %d all one outer stride\n", (int)iiter); ptrs[iiter] = ad_ptrs[iiter]; @@ -5725,7 +5729,7 @@ npyiter_copy_to_buffers(NpyIter *iter, char **prev_dataptrs) if ((reduce_outerdim > 0) && (transfersize/reduce_innersize <= NAD_SHAPE(reduce_outeraxisdata) - - NAD_COORD(reduce_outeraxisdata))) { + NAD_INDEX(reduce_outeraxisdata))) { ptrs[iiter] = ad_ptrs[iiter]; strides[iiter] = ad_strides[iiter]; /* Outer reduce loop advances by one item */ @@ -5823,7 +5827,7 @@ npyiter_copy_to_buffers(NpyIter *iter, char **prev_dataptrs) op_transfersize = 1; dst_stride = 0; src_strides = &dst_stride; - src_coords = &NAD_COORD(reduce_outeraxisdata); + src_coords = &NAD_INDEX(reduce_outeraxisdata); src_shape = &NAD_SHAPE(reduce_outeraxisdata); ndim_transfer = 1; @@ -5847,7 +5851,7 @@ npyiter_copy_to_buffers(NpyIter *iter, char **prev_dataptrs) op_transfersize = NBF_REDUCE_OUTERSIZE(bufferdata); dst_stride = reduce_outerstrides[iiter]; src_strides = &NAD_STRIDES(reduce_outeraxisdata)[iiter]; - src_coords = &NAD_COORD(reduce_outeraxisdata); + src_coords = &NAD_INDEX(reduce_outeraxisdata); src_shape = &NAD_SHAPE(reduce_outeraxisdata); ndim_transfer = ndim - reduce_outerdim; } @@ -5857,7 +5861,7 @@ npyiter_copy_to_buffers(NpyIter *iter, char **prev_dataptrs) op_transfersize = NBF_SIZE(bufferdata); dst_stride = strides[iiter]; src_strides = &ad_strides[iiter]; - src_coords = &NAD_COORD(axisdata); + src_coords = &NAD_INDEX(axisdata); src_shape = &NAD_SHAPE(axisdata); ndim_transfer = reduce_outerdim ? reduce_outerdim : 1; } @@ -5865,7 +5869,7 @@ npyiter_copy_to_buffers(NpyIter *iter, char **prev_dataptrs) op_transfersize = transfersize; dst_stride = strides[iiter]; src_strides = &ad_strides[iiter]; - src_coords = &NAD_COORD(axisdata); + src_coords = &NAD_INDEX(axisdata); src_shape = &NAD_SHAPE(axisdata); ndim_transfer = ndim; } @@ -5875,7 +5879,7 @@ npyiter_copy_to_buffers(NpyIter *iter, char **prev_dataptrs) op_transfersize = transfersize; dst_stride = strides[iiter]; src_strides = &ad_strides[iiter]; - src_coords = &NAD_COORD(axisdata); + src_coords = &NAD_INDEX(axisdata); src_shape = &NAD_SHAPE(axisdata); ndim_transfer = ndim; } @@ -6006,7 +6010,7 @@ npyiter_checkreducesize(NpyIter *iter, npy_intp count, (strides[iiter] == 0); } shape = NAD_SHAPE(axisdata); - coord = NAD_COORD(axisdata); + coord = NAD_INDEX(axisdata); reducespace += (shape-coord-1); factor = shape; NIT_ADVANCE_AXISDATA(axisdata, 1); @@ -6020,7 +6024,7 @@ npyiter_checkreducesize(NpyIter *iter, npy_intp count, * If a reduce stride switched from zero to non-zero, or * vice versa, that's the point where the data will stop * being the same element or will repeat, and if the - * buffer starts with all zero coordinates up to this + * buffer starts with an all zero multi-index up to this * point, gives us the reduce_innersize. */ if((stride0op[iiter] && (strides[iiter] != 0)) || @@ -6057,7 +6061,7 @@ npyiter_checkreducesize(NpyIter *iter, npy_intp count, } shape = NAD_SHAPE(axisdata); - coord = NAD_COORD(axisdata); + coord = NAD_INDEX(axisdata); if (coord != 0) { nonzerocoord = 1; } @@ -6097,7 +6101,7 @@ npyiter_checkreducesize(NpyIter *iter, npy_intp count, (strides[iiter] == 0); } shape = NAD_SHAPE(axisdata); - coord = NAD_COORD(axisdata); + coord = NAD_INDEX(axisdata); reducespace += (shape-coord-1) * factor; factor *= shape; NIT_ADVANCE_AXISDATA(axisdata, 1); @@ -6111,7 +6115,7 @@ npyiter_checkreducesize(NpyIter *iter, npy_intp count, * If a reduce stride switched from zero to non-zero, or * vice versa, that's the point where the data will stop * being the same element or will repeat, and if the - * buffer starts with all zero coordinates up to this + * buffer starts with an all zero multi-index up to this * point, gives us the reduce_innersize. */ if((stride0op[iiter] && (strides[iiter] != 0)) || @@ -6133,7 +6137,7 @@ npyiter_checkreducesize(NpyIter *iter, npy_intp count, } shape = NAD_SHAPE(axisdata); - coord = NAD_COORD(axisdata); + coord = NAD_INDEX(axisdata); if (coord != 0) { nonzerocoord = 1; } @@ -6173,8 +6177,8 @@ NpyIter_DebugPrint(NpyIter *iter) printf("NEGPERM "); if (itflags&NPY_ITFLAG_HASINDEX) printf("HASINDEX "); - if (itflags&NPY_ITFLAG_HASCOORDS) - printf("HASCOORDS "); + if (itflags&NPY_ITFLAG_HASMULTIINDEX) + printf("HASMULTIINDEX "); if (itflags&NPY_ITFLAG_FORCEDORDER) printf("FORCEDORDER "); if (itflags&NPY_ITFLAG_EXLOOP) @@ -6352,7 +6356,7 @@ NpyIter_DebugPrint(NpyIter *iter) for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) { printf("| AxisData[%d]:\n", (int)idim); printf("| Shape: %d\n", (int)NAD_SHAPE(axisdata)); - printf("| Coord: %d\n", (int)NAD_COORD(axisdata)); + printf("| Index: %d\n", (int)NAD_INDEX(axisdata)); printf("| Strides: "); for (iiter = 0; iiter < niter; ++iiter) { printf("%d ", (int)NAD_STRIDES(axisdata)[iiter]); diff --git a/numpy/core/src/multiarray/nditer_pywrap.c b/numpy/core/src/multiarray/nditer_pywrap.c index d604d7889..3d13d9ec4 100644 --- a/numpy/core/src/multiarray/nditer_pywrap.c +++ b/numpy/core/src/multiarray/nditer_pywrap.c @@ -30,7 +30,7 @@ struct NewNpyArrayIterObject_tag { NewNpyArrayIterObject *nested_child; /* Cached values from the iterator */ NpyIter_IterNextFunc *iternext; - NpyIter_GetCoordsFunc *getcoords; + NpyIter_GetMultiIndexFunc *get_multi_index; char **dataptrs; PyArray_Descr **dtypes; PyArrayObject **operands; @@ -43,13 +43,13 @@ void npyiter_cache_values(NewNpyArrayIterObject *self) { NpyIter *iter = self->iter; - /* iternext and getcoords functions */ + /* iternext and get_multi_index functions */ self->iternext = NpyIter_GetIterNext(iter, NULL); - if (NpyIter_HasCoords(iter) && !NpyIter_HasDelayedBufAlloc(iter)) { - self->getcoords = NpyIter_GetGetCoords(iter, NULL); + if (NpyIter_HasMultiIndex(iter) && !NpyIter_HasDelayedBufAlloc(iter)) { + self->get_multi_index = NpyIter_GetGetMultiIndex(iter, NULL); } else { - self->getcoords = NULL; + self->get_multi_index = NULL; } /* Internal data pointers */ @@ -146,11 +146,6 @@ NpyIter_GlobalFlagsConverter(PyObject *flags_in, npy_uint32 *flags) flag = NPY_ITER_C_INDEX; } break; - case 's': - if (strcmp(str, "coords") == 0) { - flag = NPY_ITER_COORDS; - } - break; case 'n': if (strcmp(str, "common_dtype") == 0) { flag = NPY_ITER_COMMON_DTYPE; @@ -178,6 +173,11 @@ NpyIter_GlobalFlagsConverter(PyObject *flags_in, npy_uint32 *flags) flag = NPY_ITER_GROWINNER; } break; + case 'm': + if (strcmp(str, "multi_index") == 0) { + flag = NPY_ITER_MULTI_INDEX; + } + break; case 'r': if (strcmp(str, "ranged") == 0) { flag = NPY_ITER_RANGED; @@ -1246,8 +1246,8 @@ npyiter_reset(NewNpyArrayIterObject *self) self->finished = 0; } - if (self->getcoords == NULL && NpyIter_HasCoords(self->iter)) { - self->getcoords = NpyIter_GetGetCoords(self->iter, NULL); + if (self->get_multi_index == NULL && NpyIter_HasMultiIndex(self->iter)) { + self->get_multi_index = NpyIter_GetGetMultiIndex(self->iter, NULL); } /* If there is nesting, the nested iterators should be reset */ @@ -1347,7 +1347,7 @@ npyiter_remove_axis(NewNpyArrayIterObject *self, PyObject *args) } static PyObject * -npyiter_remove_coords(NewNpyArrayIterObject *self) +npyiter_remove_multi_index(NewNpyArrayIterObject *self) { if (self->iter == NULL) { PyErr_SetString(PyExc_ValueError, @@ -1355,10 +1355,10 @@ npyiter_remove_coords(NewNpyArrayIterObject *self) return NULL; } - NpyIter_RemoveCoords(self->iter); - /* RemoveCoords invalidates cached values */ + NpyIter_RemoveMultiIndex(self->iter); + /* RemoveMultiIndex invalidates cached values */ npyiter_cache_values(self); - /* RemoveCoords also resets the iterator */ + /* RemoveMultiIndex also resets the iterator */ if (NpyIter_GetIterSize(self->iter) == 0) { self->started = 1; self->finished = 1; @@ -1566,10 +1566,10 @@ static PyObject *npyiter_shape_get(NewNpyArrayIterObject *self) return NULL; } -static PyObject *npyiter_coords_get(NewNpyArrayIterObject *self) +static PyObject *npyiter_multi_index_get(NewNpyArrayIterObject *self) { PyObject *ret; - npy_intp idim, ndim, coords[NPY_MAXDIMS]; + npy_intp idim, ndim, multi_index[NPY_MAXDIMS]; if (self->iter == NULL || self->finished) { PyErr_SetString(PyExc_ValueError, @@ -1577,20 +1577,20 @@ static PyObject *npyiter_coords_get(NewNpyArrayIterObject *self) return NULL; } - if (self->getcoords != NULL) { + if (self->get_multi_index != NULL) { ndim = NpyIter_GetNDim(self->iter); - self->getcoords(self->iter, coords); + self->get_multi_index(self->iter, multi_index); ret = PyTuple_New(ndim); for (idim = 0; idim < ndim; ++idim) { PyTuple_SET_ITEM(ret, idim, - PyInt_FromLong(coords[idim])); + PyInt_FromLong(multi_index[idim])); } return ret; } else { - if (!NpyIter_HasCoords(self->iter)) { + if (!NpyIter_HasMultiIndex(self->iter)) { PyErr_SetString(PyExc_ValueError, - "Iterator does not have coordinates"); + "Iterator is not tracking a multi-index"); return NULL; } else if (NpyIter_HasDelayedBufAlloc(self->iter)) { @@ -1607,9 +1607,9 @@ static PyObject *npyiter_coords_get(NewNpyArrayIterObject *self) } } -static int npyiter_coords_set(NewNpyArrayIterObject *self, PyObject *value) +static int npyiter_multi_index_set(NewNpyArrayIterObject *self, PyObject *value) { - npy_intp idim, ndim, coords[NPY_MAXDIMS]; + npy_intp idim, ndim, multi_index[NPY_MAXDIMS]; if (self->iter == NULL) { PyErr_SetString(PyExc_ValueError, @@ -1619,30 +1619,30 @@ static int npyiter_coords_set(NewNpyArrayIterObject *self, PyObject *value) if (value == NULL) { PyErr_SetString(PyExc_ValueError, - "Cannot delete coordinates"); + "Cannot delete the multi_index"); return -1; } - if (NpyIter_HasCoords(self->iter)) { + if (NpyIter_HasMultiIndex(self->iter)) { ndim = NpyIter_GetNDim(self->iter); if (!PySequence_Check(value)) { PyErr_SetString(PyExc_ValueError, - "Coordinates must be set with a sequence"); + "multi_index must be set with a sequence"); return -1; } if (PySequence_Size(value) != ndim) { PyErr_SetString(PyExc_ValueError, - "Wrong number of coordinates"); + "Wrong number of indices"); return -1; } for (idim = 0; idim < ndim; ++idim) { PyObject *v = PySequence_GetItem(value, idim); - coords[idim] = PyInt_AsLong(v); - if (coords[idim]==-1 && PyErr_Occurred()) { + multi_index[idim] = PyInt_AsLong(v); + if (multi_index[idim]==-1 && PyErr_Occurred()) { return -1; } } - if (NpyIter_GotoCoords(self->iter, coords) != NPY_SUCCEED) { + if (NpyIter_GotoMultiIndex(self->iter, multi_index) != NPY_SUCCEED) { return -1; } self->started = 0; @@ -1657,7 +1657,7 @@ static int npyiter_coords_set(NewNpyArrayIterObject *self, PyObject *value) } else { PyErr_SetString(PyExc_ValueError, - "Iterator does not have coordinates"); + "Iterator is not tracking a multi-index"); return -1; } } @@ -1829,8 +1829,8 @@ static int npyiter_iterrange_set(NewNpyArrayIterObject *self, PyObject *value) self->started = self->finished = 1; } - if (self->getcoords == NULL && NpyIter_HasCoords(self->iter)) { - self->getcoords = NpyIter_GetGetCoords(self->iter, NULL); + if (self->get_multi_index == NULL && NpyIter_HasMultiIndex(self->iter)) { + self->get_multi_index = NpyIter_GetGetMultiIndex(self->iter, NULL); } /* If there is nesting, the nested iterators should be reset */ @@ -1841,7 +1841,7 @@ static int npyiter_iterrange_set(NewNpyArrayIterObject *self, PyObject *value) return 0; } -static PyObject *npyiter_hasdelayedbufalloc_get(NewNpyArrayIterObject *self) +static PyObject *npyiter_has_delayed_bufalloc_get(NewNpyArrayIterObject *self) { if (self->iter == NULL) { PyErr_SetString(PyExc_ValueError, @@ -1873,7 +1873,7 @@ static PyObject *npyiter_iterationneedsapi_get(NewNpyArrayIterObject *self) } } -static PyObject *npyiter_hascoords_get(NewNpyArrayIterObject *self) +static PyObject *npyiter_has_multi_index_get(NewNpyArrayIterObject *self) { if (self->iter == NULL) { PyErr_SetString(PyExc_ValueError, @@ -1881,7 +1881,7 @@ static PyObject *npyiter_hascoords_get(NewNpyArrayIterObject *self) return NULL; } - if (NpyIter_HasCoords(self->iter)) { + if (NpyIter_HasMultiIndex(self->iter)) { Py_RETURN_TRUE; } else { @@ -1889,7 +1889,7 @@ static PyObject *npyiter_hascoords_get(NewNpyArrayIterObject *self) } } -static PyObject *npyiter_hasindex_get(NewNpyArrayIterObject *self) +static PyObject *npyiter_has_index_get(NewNpyArrayIterObject *self) { if (self->iter == NULL) { PyErr_SetString(PyExc_ValueError, @@ -2336,7 +2336,8 @@ static PyMethodDef npyiter_methods[] = { {"__copy__", (PyCFunction)npyiter_copy, METH_NOARGS, NULL}, {"iternext", (PyCFunction)npyiter_iternext, METH_NOARGS, NULL}, {"remove_axis", (PyCFunction)npyiter_remove_axis, METH_VARARGS, NULL}, - {"remove_coords", (PyCFunction)npyiter_remove_coords, METH_NOARGS, NULL}, + {"remove_multi_index", (PyCFunction)npyiter_remove_multi_index, + METH_NOARGS, NULL}, {"enable_external_loop", (PyCFunction)npyiter_enable_external_loop, METH_NOARGS, NULL}, {"debug_print", (PyCFunction)npyiter_debug_print, METH_NOARGS, NULL}, @@ -2354,9 +2355,9 @@ static PyGetSetDef npyiter_getsets[] = { {"shape", (getter)npyiter_shape_get, NULL, NULL, NULL}, - {"coords", - (getter)npyiter_coords_get, - (setter)npyiter_coords_set, + {"multi_index", + (getter)npyiter_multi_index_get, + (setter)npyiter_multi_index_set, NULL, NULL}, {"index", (getter)npyiter_index_get, @@ -2376,17 +2377,17 @@ static PyGetSetDef npyiter_getsets[] = { {"itviews", (getter)npyiter_itviews_get, NULL, NULL, NULL}, - {"hasdelayedbufalloc", - (getter)npyiter_hasdelayedbufalloc_get, + {"has_delayed_bufalloc", + (getter)npyiter_has_delayed_bufalloc_get, NULL, NULL, NULL}, {"iterationneedsapi", (getter)npyiter_iterationneedsapi_get, NULL, NULL, NULL}, - {"hascoords", - (getter)npyiter_hascoords_get, + {"has_multi_index", + (getter)npyiter_has_multi_index_get, NULL, NULL, NULL}, - {"hasindex", - (getter)npyiter_hasindex_get, + {"has_index", + (getter)npyiter_has_index_get, NULL, NULL, NULL}, {"dtypes", (getter)npyiter_dtypes_get, diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c index e619da81d..1d53dd308 100644 --- a/numpy/core/src/umath/ufunc_object.c +++ b/numpy/core/src/umath/ufunc_object.c @@ -2305,7 +2305,7 @@ PyUFunc_GeneralizedFunction(PyUFuncObject *self, } /* Create the iterator */ - iter = NpyIter_AdvancedNew(niter, op, NPY_ITER_COORDS| + iter = NpyIter_AdvancedNew(niter, op, NPY_ITER_MULTI_INDEX| NPY_ITER_REFS_OK| NPY_ITER_REDUCE_OK, order, NPY_UNSAFE_CASTING, op_flags, @@ -2365,7 +2365,7 @@ PyUFunc_GeneralizedFunction(PyUFuncObject *self, goto fail; } } - if (NpyIter_RemoveCoords(iter) != NPY_SUCCEED) { + if (NpyIter_RemoveMultiIndex(iter) != NPY_SUCCEED) { retval = -1; goto fail; } @@ -2916,7 +2916,7 @@ PyUFunc_ReductionOp(PyUFuncObject *self, PyArrayObject *arr, * so make a copy instead when necessary. */ ndim_iter = ndim; - flags |= NPY_ITER_COORDS; + flags |= NPY_ITER_MULTI_INDEX; /* Add some more flags */ op_flags[0] |= NPY_ITER_UPDATEIFCOPY|NPY_ITER_ALIGNED; op_flags[1] |= NPY_ITER_COPY|NPY_ITER_ALIGNED; @@ -2949,7 +2949,7 @@ PyUFunc_ReductionOp(PyUFuncObject *self, PyArrayObject *arr, if (NpyIter_RemoveAxis(iter, axis) != NPY_SUCCEED) { goto fail; } - if (NpyIter_RemoveCoords(iter) != NPY_SUCCEED) { + if (NpyIter_RemoveMultiIndex(iter) != NPY_SUCCEED) { goto fail; } } @@ -3535,7 +3535,7 @@ PyUFunc_Reduceat(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *ind, if (need_outer_iterator) { npy_uint32 flags = NPY_ITER_ZEROSIZE_OK| NPY_ITER_REFS_OK| - NPY_ITER_COORDS; + NPY_ITER_MULTI_INDEX; /* * The way reduceat is set up, we can't do buffering, @@ -3570,7 +3570,7 @@ PyUFunc_Reduceat(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *ind, if (NpyIter_RemoveAxis(iter, axis) != NPY_SUCCEED) { goto fail; } - if (NpyIter_RemoveCoords(iter) != NPY_SUCCEED) { + if (NpyIter_RemoveMultiIndex(iter) != NPY_SUCCEED) { goto fail; } diff --git a/numpy/core/tests/test_iterator.py b/numpy/core/tests/test_iterator.py index 4b4aaecd9..e5a073e12 100644 --- a/numpy/core/tests/test_iterator.py +++ b/numpy/core/tests/test_iterator.py @@ -6,10 +6,10 @@ import sys, warnings import warnings -def iter_coords(i): +def iter_multi_index(i): ret = [] while not i.finished: - ret.append(i.coords) + ret.append(i.multi_index) i.iternext() return ret @@ -174,85 +174,85 @@ def test_iter_c_or_f_order(): assert_equal([x for x in i], aview.swapaxes(0,1).ravel(order='A')) -def test_iter_best_order_coords_1d(): - # The coords should be correct with any reordering +def test_iter_best_order_multi_index_1d(): + # The multi-indices should be correct with any reordering a = arange(4) # 1D order - i = nditer(a,['coords'],[['readonly']]) - assert_equal(iter_coords(i), [(0,),(1,),(2,),(3,)]) + i = nditer(a,['multi_index'],[['readonly']]) + assert_equal(iter_multi_index(i), [(0,),(1,),(2,),(3,)]) # 1D reversed order - i = nditer(a[::-1],['coords'],[['readonly']]) - assert_equal(iter_coords(i), [(3,),(2,),(1,),(0,)]) + i = nditer(a[::-1],['multi_index'],[['readonly']]) + assert_equal(iter_multi_index(i), [(3,),(2,),(1,),(0,)]) -def test_iter_best_order_coords_2d(): - # The coords should be correct with any reordering +def test_iter_best_order_multi_index_2d(): + # The multi-indices should be correct with any reordering a = arange(6) # 2D C-order - i = nditer(a.reshape(2,3),['coords'],[['readonly']]) - assert_equal(iter_coords(i), [(0,0),(0,1),(0,2),(1,0),(1,1),(1,2)]) + i = nditer(a.reshape(2,3),['multi_index'],[['readonly']]) + assert_equal(iter_multi_index(i), [(0,0),(0,1),(0,2),(1,0),(1,1),(1,2)]) # 2D Fortran-order - i = nditer(a.reshape(2,3).copy(order='F'),['coords'],[['readonly']]) - assert_equal(iter_coords(i), [(0,0),(1,0),(0,1),(1,1),(0,2),(1,2)]) + i = nditer(a.reshape(2,3).copy(order='F'),['multi_index'],[['readonly']]) + assert_equal(iter_multi_index(i), [(0,0),(1,0),(0,1),(1,1),(0,2),(1,2)]) # 2D reversed C-order - i = nditer(a.reshape(2,3)[::-1],['coords'],[['readonly']]) - assert_equal(iter_coords(i), [(1,0),(1,1),(1,2),(0,0),(0,1),(0,2)]) - i = nditer(a.reshape(2,3)[:,::-1],['coords'],[['readonly']]) - assert_equal(iter_coords(i), [(0,2),(0,1),(0,0),(1,2),(1,1),(1,0)]) - i = nditer(a.reshape(2,3)[::-1,::-1],['coords'],[['readonly']]) - assert_equal(iter_coords(i), [(1,2),(1,1),(1,0),(0,2),(0,1),(0,0)]) + i = nditer(a.reshape(2,3)[::-1],['multi_index'],[['readonly']]) + assert_equal(iter_multi_index(i), [(1,0),(1,1),(1,2),(0,0),(0,1),(0,2)]) + i = nditer(a.reshape(2,3)[:,::-1],['multi_index'],[['readonly']]) + assert_equal(iter_multi_index(i), [(0,2),(0,1),(0,0),(1,2),(1,1),(1,0)]) + i = nditer(a.reshape(2,3)[::-1,::-1],['multi_index'],[['readonly']]) + assert_equal(iter_multi_index(i), [(1,2),(1,1),(1,0),(0,2),(0,1),(0,0)]) # 2D reversed Fortran-order - i = nditer(a.reshape(2,3).copy(order='F')[::-1],['coords'],[['readonly']]) - assert_equal(iter_coords(i), [(1,0),(0,0),(1,1),(0,1),(1,2),(0,2)]) + i = nditer(a.reshape(2,3).copy(order='F')[::-1],['multi_index'],[['readonly']]) + assert_equal(iter_multi_index(i), [(1,0),(0,0),(1,1),(0,1),(1,2),(0,2)]) i = nditer(a.reshape(2,3).copy(order='F')[:,::-1], - ['coords'],[['readonly']]) - assert_equal(iter_coords(i), [(0,2),(1,2),(0,1),(1,1),(0,0),(1,0)]) + ['multi_index'],[['readonly']]) + assert_equal(iter_multi_index(i), [(0,2),(1,2),(0,1),(1,1),(0,0),(1,0)]) i = nditer(a.reshape(2,3).copy(order='F')[::-1,::-1], - ['coords'],[['readonly']]) - assert_equal(iter_coords(i), [(1,2),(0,2),(1,1),(0,1),(1,0),(0,0)]) + ['multi_index'],[['readonly']]) + assert_equal(iter_multi_index(i), [(1,2),(0,2),(1,1),(0,1),(1,0),(0,0)]) -def test_iter_best_order_coords_3d(): - # The coords should be correct with any reordering +def test_iter_best_order_multi_index_3d(): + # The multi-indices should be correct with any reordering a = arange(12) # 3D C-order - i = nditer(a.reshape(2,3,2),['coords'],[['readonly']]) - assert_equal(iter_coords(i), + i = nditer(a.reshape(2,3,2),['multi_index'],[['readonly']]) + assert_equal(iter_multi_index(i), [(0,0,0),(0,0,1),(0,1,0),(0,1,1),(0,2,0),(0,2,1), (1,0,0),(1,0,1),(1,1,0),(1,1,1),(1,2,0),(1,2,1)]) # 3D Fortran-order - i = nditer(a.reshape(2,3,2).copy(order='F'),['coords'],[['readonly']]) - assert_equal(iter_coords(i), + i = nditer(a.reshape(2,3,2).copy(order='F'),['multi_index'],[['readonly']]) + assert_equal(iter_multi_index(i), [(0,0,0),(1,0,0),(0,1,0),(1,1,0),(0,2,0),(1,2,0), (0,0,1),(1,0,1),(0,1,1),(1,1,1),(0,2,1),(1,2,1)]) # 3D reversed C-order - i = nditer(a.reshape(2,3,2)[::-1],['coords'],[['readonly']]) - assert_equal(iter_coords(i), + i = nditer(a.reshape(2,3,2)[::-1],['multi_index'],[['readonly']]) + assert_equal(iter_multi_index(i), [(1,0,0),(1,0,1),(1,1,0),(1,1,1),(1,2,0),(1,2,1), (0,0,0),(0,0,1),(0,1,0),(0,1,1),(0,2,0),(0,2,1)]) - i = nditer(a.reshape(2,3,2)[:,::-1],['coords'],[['readonly']]) - assert_equal(iter_coords(i), + i = nditer(a.reshape(2,3,2)[:,::-1],['multi_index'],[['readonly']]) + assert_equal(iter_multi_index(i), [(0,2,0),(0,2,1),(0,1,0),(0,1,1),(0,0,0),(0,0,1), (1,2,0),(1,2,1),(1,1,0),(1,1,1),(1,0,0),(1,0,1)]) - i = nditer(a.reshape(2,3,2)[:,:,::-1],['coords'],[['readonly']]) - assert_equal(iter_coords(i), + i = nditer(a.reshape(2,3,2)[:,:,::-1],['multi_index'],[['readonly']]) + assert_equal(iter_multi_index(i), [(0,0,1),(0,0,0),(0,1,1),(0,1,0),(0,2,1),(0,2,0), (1,0,1),(1,0,0),(1,1,1),(1,1,0),(1,2,1),(1,2,0)]) # 3D reversed Fortran-order i = nditer(a.reshape(2,3,2).copy(order='F')[::-1], - ['coords'],[['readonly']]) - assert_equal(iter_coords(i), + ['multi_index'],[['readonly']]) + assert_equal(iter_multi_index(i), [(1,0,0),(0,0,0),(1,1,0),(0,1,0),(1,2,0),(0,2,0), (1,0,1),(0,0,1),(1,1,1),(0,1,1),(1,2,1),(0,2,1)]) i = nditer(a.reshape(2,3,2).copy(order='F')[:,::-1], - ['coords'],[['readonly']]) - assert_equal(iter_coords(i), + ['multi_index'],[['readonly']]) + assert_equal(iter_multi_index(i), [(0,2,0),(1,2,0),(0,1,0),(1,1,0),(0,0,0),(1,0,0), (0,2,1),(1,2,1),(0,1,1),(1,1,1),(0,0,1),(1,0,1)]) i = nditer(a.reshape(2,3,2).copy(order='F')[:,:,::-1], - ['coords'],[['readonly']]) - assert_equal(iter_coords(i), + ['multi_index'],[['readonly']]) + assert_equal(iter_multi_index(i), [(0,0,1),(1,0,1),(0,1,1),(1,1,1),(0,2,1),(1,2,1), (0,0,0),(1,0,0),(0,1,0),(1,1,0),(0,2,0),(1,2,0)]) @@ -467,9 +467,9 @@ def test_iter_no_inner_dim_coalescing(): def test_iter_dim_coalescing(): # Check that the correct number of dimensions are coalesced - # Tracking coordinates disables coalescing + # Tracking a multi-index disables coalescing a = arange(24).reshape(2,3,4) - i = nditer(a, ['coords'], [['readonly']]) + i = nditer(a, ['multi_index'], [['readonly']]) assert_equal(i.ndim, 3) # A tracked index can allow coalescing if it's compatible with the array @@ -504,69 +504,69 @@ def test_iter_broadcasting(): # Standard NumPy broadcasting rules # 1D with scalar - i = nditer([arange(6), np.int32(2)], ['coords'], [['readonly']]*2) + i = nditer([arange(6), np.int32(2)], ['multi_index'], [['readonly']]*2) assert_equal(i.itersize, 6) assert_equal(i.shape, (6,)) # 2D with scalar i = nditer([arange(6).reshape(2,3), np.int32(2)], - ['coords'], [['readonly']]*2) + ['multi_index'], [['readonly']]*2) assert_equal(i.itersize, 6) assert_equal(i.shape, (2,3)) # 2D with 1D i = nditer([arange(6).reshape(2,3), arange(3)], - ['coords'], [['readonly']]*2) + ['multi_index'], [['readonly']]*2) assert_equal(i.itersize, 6) assert_equal(i.shape, (2,3)) i = nditer([arange(2).reshape(2,1), arange(3)], - ['coords'], [['readonly']]*2) + ['multi_index'], [['readonly']]*2) assert_equal(i.itersize, 6) assert_equal(i.shape, (2,3)) # 2D with 2D i = nditer([arange(2).reshape(2,1), arange(3).reshape(1,3)], - ['coords'], [['readonly']]*2) + ['multi_index'], [['readonly']]*2) assert_equal(i.itersize, 6) assert_equal(i.shape, (2,3)) # 3D with scalar i = nditer([np.int32(2), arange(24).reshape(4,2,3)], - ['coords'], [['readonly']]*2) + ['multi_index'], [['readonly']]*2) assert_equal(i.itersize, 24) assert_equal(i.shape, (4,2,3)) # 3D with 1D i = nditer([arange(3), arange(24).reshape(4,2,3)], - ['coords'], [['readonly']]*2) + ['multi_index'], [['readonly']]*2) assert_equal(i.itersize, 24) assert_equal(i.shape, (4,2,3)) i = nditer([arange(3), arange(8).reshape(4,2,1)], - ['coords'], [['readonly']]*2) + ['multi_index'], [['readonly']]*2) assert_equal(i.itersize, 24) assert_equal(i.shape, (4,2,3)) # 3D with 2D i = nditer([arange(6).reshape(2,3), arange(24).reshape(4,2,3)], - ['coords'], [['readonly']]*2) + ['multi_index'], [['readonly']]*2) assert_equal(i.itersize, 24) assert_equal(i.shape, (4,2,3)) i = nditer([arange(2).reshape(2,1), arange(24).reshape(4,2,3)], - ['coords'], [['readonly']]*2) + ['multi_index'], [['readonly']]*2) assert_equal(i.itersize, 24) assert_equal(i.shape, (4,2,3)) i = nditer([arange(3).reshape(1,3), arange(8).reshape(4,2,1)], - ['coords'], [['readonly']]*2) + ['multi_index'], [['readonly']]*2) assert_equal(i.itersize, 24) assert_equal(i.shape, (4,2,3)) # 3D with 3D i = nditer([arange(2).reshape(1,2,1), arange(3).reshape(1,1,3), arange(4).reshape(4,1,1)], - ['coords'], [['readonly']]*3) + ['multi_index'], [['readonly']]*3) assert_equal(i.itersize, 24) assert_equal(i.shape, (4,2,3)) i = nditer([arange(6).reshape(1,2,3), arange(4).reshape(4,1,1)], - ['coords'], [['readonly']]*2) + ['multi_index'], [['readonly']]*2) assert_equal(i.itersize, 24) assert_equal(i.shape, (4,2,3)) i = nditer([arange(24).reshape(4,2,3), arange(12).reshape(4,1,3)], - ['coords'], [['readonly']]*2) + ['multi_index'], [['readonly']]*2) assert_equal(i.itersize, 24) assert_equal(i.shape, (4,2,3)) @@ -681,9 +681,9 @@ def test_iter_flags_errors(): # Cannot track both a C and an F index assert_raises(ValueError, nditer, a, ['c_index','f_index'], [['readonly']]) - # Inner iteration and coords/indices are incompatible + # Inner iteration and multi-indices/indices are incompatible assert_raises(ValueError, nditer, a, - ['external_loop','coords'], [['readonly']]) + ['external_loop','multi_index'], [['readonly']]) assert_raises(ValueError, nditer, a, ['external_loop','c_index'], [['readonly']]) assert_raises(ValueError, nditer, a, @@ -706,14 +706,14 @@ def test_iter_flags_errors(): assert_raises(ValueError, nditer, a, [], [['writeonly']]) assert_raises(ValueError, nditer, a, [], [['readwrite']]) a.flags.writeable = True - # Coords available only with the coords flag + # Multi-indices available only with the multi_index flag i = nditer(arange(6), [], [['readonly']]) - assert_raises(ValueError, lambda i:i.coords, i) + assert_raises(ValueError, lambda i:i.multi_index, i) # Index available only with an index flag assert_raises(ValueError, lambda i:i.index, i) # GotoCoords and GotoIndex incompatible with buffering or no_inner - def assign_coords(i): - i.coords = (0,) + def assign_multi_index(i): + i.multi_index = (0,) def assign_index(i): i.index = 0 def assign_iterindex(i): @@ -721,12 +721,12 @@ def test_iter_flags_errors(): def assign_iterrange(i): i.iterrange = (0,1); i = nditer(arange(6), ['external_loop']) - assert_raises(ValueError, assign_coords, i) + assert_raises(ValueError, assign_multi_index, i) assert_raises(ValueError, assign_index, i) assert_raises(ValueError, assign_iterindex, i) assert_raises(ValueError, assign_iterrange, i) i = nditer(arange(6), ['buffered']) - assert_raises(ValueError, assign_coords, i) + assert_raises(ValueError, assign_multi_index, i) assert_raises(ValueError, assign_index, i) assert_raises(ValueError, assign_iterrange, i) # Can't iterate if size is zero @@ -1126,14 +1126,14 @@ def test_iter_op_axes(): # Inner product-style broadcasting a = arange(24).reshape(2,3,4) b = arange(40).reshape(5,2,4) - i = nditer([a,b], ['coords'], [['readonly']]*2, + i = nditer([a,b], ['multi_index'], [['readonly']]*2, op_axes=[[0,1,-1,-1],[-1,-1,0,1]]) assert_equal(i.shape, (2,3,5,2)) # Matrix product-style broadcasting a = arange(12).reshape(3,4) b = arange(20).reshape(4,5) - i = nditer([a,b], ['coords'], [['readonly']]*2, + i = nditer([a,b], ['multi_index'], [['readonly']]*2, op_axes=[[0,-1],[-1,1]]) assert_equal(i.shape, (3,5)) @@ -1370,28 +1370,28 @@ def test_iter_allocate_output_errors(): def test_iter_remove_axis(): a = arange(24).reshape(2,3,4) - i = nditer(a,['coords']) + i = nditer(a,['multi_index']) i.remove_axis(1) assert_equal([x for x in i], a[:,0,:].ravel()) a = a[::-1,:,:] - i = nditer(a,['coords']) + i = nditer(a,['multi_index']) i.remove_axis(0) assert_equal([x for x in i], a[0,:,:].ravel()) -def test_iter_remove_coords_inner_loop(): - # Check that removing coords support works +def test_iter_remove_multi_index_inner_loop(): + # Check that removing multi-index support works a = arange(24).reshape(2,3,4) - i = nditer(a,['coords']) + i = nditer(a,['multi_index']) assert_equal(i.ndim, 3) assert_equal(i.shape, (2,3,4)) assert_equal(i.itviews[0].shape, (2,3,4)) - # Removing coords causes all dimensions to coalesce + # Removing the multi-index tracking causes all dimensions to coalesce before = [x for x in i] - i.remove_coords() + i.remove_multi_index() after = [x for x in i] assert_equal(before, after) @@ -1534,12 +1534,12 @@ def test_iter_buffering_delayed_alloc(): a = np.arange(6) b = np.arange(1, dtype='f4') - i = nditer([a,b], ['buffered','delay_bufalloc','coords','reduce_ok'], + i = nditer([a,b], ['buffered','delay_bufalloc','multi_index','reduce_ok'], ['readwrite'], casting='unsafe', op_dtypes='f4') - assert_(i.hasdelayedbufalloc) - assert_raises(ValueError, lambda i:i.coords, i) + assert_(i.has_delayed_bufalloc) + assert_raises(ValueError, lambda i:i.multi_index, i) assert_raises(ValueError, lambda i:i[0], i) assert_raises(ValueError, lambda i:i[0:2], i) def assign_iter(i): @@ -1547,8 +1547,8 @@ def test_iter_buffering_delayed_alloc(): assert_raises(ValueError, assign_iter, i) i.reset() - assert_(not i.hasdelayedbufalloc) - assert_equal(i.coords, (0,)) + assert_(not i.has_delayed_bufalloc) + assert_equal(i.multi_index, (0,)) assert_equal(i[0], 0) i[1] = 1 assert_equal(i[0:2], [0,1]) diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py index d1e925ead..69539d482 100644 --- a/numpy/lib/index_tricks.py +++ b/numpy/lib/index_tricks.py @@ -1,4 +1,4 @@ -__all__ = ['ravel_coords', +__all__ = ['ravel_multi_index', 'unravel_index', 'mgrid', 'ogrid', @@ -17,7 +17,7 @@ import math import function_base import numpy.matrixlib as matrix from function_base import diff -from numpy.lib._compiled_base import ravel_coords, unravel_index +from numpy.lib._compiled_base import ravel_multi_index, unravel_index makemat = matrix.matrix def ix_(*args): diff --git a/numpy/lib/src/_compiled_base.c b/numpy/lib/src/_compiled_base.c index b81d2783a..066519bf1 100644 --- a/numpy/lib/src/_compiled_base.c +++ b/numpy/lib/src/_compiled_base.c @@ -614,7 +614,7 @@ static int sequence_to_arrays(PyObject *seq, /* Inner loop for unravel_index */ static int -ravel_coords_loop(int ravel_ndim, npy_intp *ravel_dims, +ravel_multi_index_loop(int ravel_ndim, npy_intp *ravel_dims, npy_intp *ravel_strides, npy_intp count, NPY_CLIPMODE *modes, @@ -674,9 +674,9 @@ ravel_coords_loop(int ravel_ndim, npy_intp *ravel_dims, return NPY_SUCCEED; } -/* ravel_coords implementation - see add_newdocs.py */ +/* ravel_multi_index implementation - see add_newdocs.py */ static PyObject * -arr_ravel_coords(PyObject *self, PyObject *args, PyObject *kwds) +arr_ravel_multi_index(PyObject *self, PyObject *args, PyObject *kwds) { int i, s; PyObject *mode0=NULL, *coords0=NULL; @@ -692,12 +692,13 @@ arr_ravel_coords(PyObject *self, PyObject *args, PyObject *kwds) NpyIter *iter = NULL; - char *kwlist[] = {"coords", "dims", "mode", "order", NULL}; + char *kwlist[] = {"multi_index", "dims", "mode", "order", NULL}; memset(op, 0, sizeof(op)); dtype[0] = NULL; - if(!PyArg_ParseTupleAndKeywords(args, kwds, "OO&|OO&:ravel_coords", kwlist, + if(!PyArg_ParseTupleAndKeywords(args, kwds, + "OO&|OO&:ravel_multi_index", kwlist, &coords0, PyArray_IntpConverter, &dimensions, &mode0, @@ -707,7 +708,7 @@ arr_ravel_coords(PyObject *self, PyObject *args, PyObject *kwds) if (dimensions.len+1 > NPY_MAXARGS) { PyErr_SetString(PyExc_ValueError, - "too many dimensions passed to ravel_coords"); + "too many dimensions passed to ravel_multi_index"); goto fail; } @@ -736,8 +737,8 @@ arr_ravel_coords(PyObject *self, PyObject *args, PyObject *kwds) goto fail; } - /* Get the coords into op */ - if (sequence_to_arrays(coords0, op, dimensions.len, "coords") < 0) { + /* Get the multi_index into op */ + if (sequence_to_arrays(coords0, op, dimensions.len, "multi_index") < 0) { goto fail; } @@ -779,7 +780,7 @@ arr_ravel_coords(PyObject *self, PyObject *args, PyObject *kwds) countptr = NpyIter_GetInnerLoopSizePtr(iter); do { - if (ravel_coords_loop(dimensions.len, dimensions.ptr, + if (ravel_multi_index_loop(dimensions.len, dimensions.ptr, ravel_strides, *countptr, modes, dataptr, strides) != NPY_SUCCEED) { goto fail; @@ -923,7 +924,7 @@ arr_unravel_index(PyObject *self, PyObject *args, PyObject *kwds) NPY_ITER_BUFFERED| NPY_ITER_ZEROSIZE_OK| NPY_ITER_DONT_NEGATE_STRIDES| - NPY_ITER_COORDS, + NPY_ITER_MULTI_INDEX, NPY_KEEPORDER, NPY_SAME_KIND_CASTING, dtype); if (iter == NULL) { @@ -932,7 +933,7 @@ arr_unravel_index(PyObject *self, PyObject *args, PyObject *kwds) /* * Create the return array with a layout compatible with the indices - * and with a dimension added to the end for the coordinates + * and with a dimension added to the end for the multi-index */ ret_ndim = PyArray_NDIM(indices) + 1; if (NpyIter_GetShape(iter, ret_dims) != NPY_SUCCEED) { @@ -945,8 +946,8 @@ arr_unravel_index(PyObject *self, PyObject *args, PyObject *kwds) } ret_strides[ret_ndim-1] = sizeof(npy_intp); - /* Remove the coords and inner loop */ - if (NpyIter_RemoveCoords(iter) != NPY_SUCCEED) { + /* Remove the multi-index and inner loop */ + if (NpyIter_RemoveMultiIndex(iter) != NPY_SUCCEED) { goto fail; } if (NpyIter_EnableExternalLoop(iter) != NPY_SUCCEED) { @@ -1020,7 +1021,7 @@ arr_unravel_index(PyObject *self, PyObject *args, PyObject *kwds) goto fail; } - /* Now make a tuple of views, one per coordinate */ + /* Now make a tuple of views, one per index */ ret_tuple = PyTuple_New(dimensions.len); if (ret_tuple == NULL) { goto fail; @@ -1411,7 +1412,7 @@ static struct PyMethodDef methods[] = { METH_VARARGS | METH_KEYWORDS, NULL}, {"interp", (PyCFunction)arr_interp, METH_VARARGS | METH_KEYWORDS, NULL}, - {"ravel_coords", (PyCFunction)arr_ravel_coords, + {"ravel_multi_index", (PyCFunction)arr_ravel_multi_index, METH_VARARGS | METH_KEYWORDS, NULL}, {"unravel_index", (PyCFunction)arr_unravel_index, METH_VARARGS | METH_KEYWORDS, NULL}, diff --git a/numpy/lib/tests/test_index_tricks.py b/numpy/lib/tests/test_index_tricks.py index 40f75936e..8b42292a2 100644 --- a/numpy/lib/tests/test_index_tricks.py +++ b/numpy/lib/tests/test_index_tricks.py @@ -7,28 +7,28 @@ from numpy import ( array, ones, r_, mgrid, unravel_index, zeros, where, class TestRavelUnravelIndex(TestCase): def test_basic(self): assert_equal(np.unravel_index(2,(2,2)), (1,0)) - assert_equal(np.ravel_coords((1,0),(2,2)), 2) + assert_equal(np.ravel_multi_index((1,0),(2,2)), 2) assert_equal(np.unravel_index(254,(17,94)), (2,66)) - assert_equal(np.ravel_coords((2,66),(17,94)), 254) + assert_equal(np.ravel_multi_index((2,66),(17,94)), 254) assert_raises(ValueError, np.unravel_index, -1, (2,2)) assert_raises(TypeError, np.unravel_index, 0.5, (2,2)) assert_raises(ValueError, np.unravel_index, 4, (2,2)) - assert_raises(ValueError, np.ravel_coords, (-3,1), (2,2)) - assert_raises(ValueError, np.ravel_coords, (2,1), (2,2)) - assert_raises(ValueError, np.ravel_coords, (0,-3), (2,2)) - assert_raises(ValueError, np.ravel_coords, (0,2), (2,2)) - assert_raises(TypeError, np.ravel_coords, (0.1,0.), (2,2)) + assert_raises(ValueError, np.ravel_multi_index, (-3,1), (2,2)) + assert_raises(ValueError, np.ravel_multi_index, (2,1), (2,2)) + assert_raises(ValueError, np.ravel_multi_index, (0,-3), (2,2)) + assert_raises(ValueError, np.ravel_multi_index, (0,2), (2,2)) + assert_raises(TypeError, np.ravel_multi_index, (0.1,0.), (2,2)) assert_equal(np.unravel_index((2*3 + 1)*6 + 4, (4,3,6)), [2,1,4]) - assert_equal(np.ravel_coords([2,1,4], (4,3,6)), (2*3 + 1)*6 + 4) + assert_equal(np.ravel_multi_index([2,1,4], (4,3,6)), (2*3 + 1)*6 + 4) arr = np.array([[3,6,6],[4,5,1]]) - assert_equal(np.ravel_coords(arr, (7,6)), [22,41,37]) - assert_equal(np.ravel_coords(arr, (7,6), order='F'), [31,41,13]) - assert_equal(np.ravel_coords(arr, (4,6), mode='clip'), [22,23,19]) - assert_equal(np.ravel_coords(arr, (4,4), mode=('clip','wrap')), + assert_equal(np.ravel_multi_index(arr, (7,6)), [22,41,37]) + assert_equal(np.ravel_multi_index(arr, (7,6), order='F'), [31,41,13]) + assert_equal(np.ravel_multi_index(arr, (4,6), mode='clip'), [22,23,19]) + assert_equal(np.ravel_multi_index(arr, (4,4), mode=('clip','wrap')), [12,13,13]) - assert_equal(np.ravel_coords((3,1,4,1), (6,7,8,9)), 1621) + assert_equal(np.ravel_multi_index((3,1,4,1), (6,7,8,9)), 1621) assert_equal(np.unravel_index(np.array([22, 41, 37]), (7,6)), [[3, 6, 6],[4, 5, 1]]) @@ -43,30 +43,30 @@ class TestRavelUnravelIndex(TestCase): coords = np.array([[1,0,1,2,3,4],[1,6,1,3,2,0]], dtype=dtype) shape = (5,8) uncoords = 8*coords[0]+coords[1] - assert_equal(np.ravel_coords(coords, shape), uncoords) + assert_equal(np.ravel_multi_index(coords, shape), uncoords) assert_equal(coords, np.unravel_index(uncoords, shape)) uncoords = coords[0]+5*coords[1] - assert_equal(np.ravel_coords(coords, shape, order='F'), uncoords) + assert_equal(np.ravel_multi_index(coords, shape, order='F'), uncoords) assert_equal(coords, np.unravel_index(uncoords, shape, order='F')) coords = np.array([[1,0,1,2,3,4],[1,6,1,3,2,0],[1,3,1,0,9,5]], dtype=dtype) shape = (5,8,10) uncoords = 10*(8*coords[0]+coords[1])+coords[2] - assert_equal(np.ravel_coords(coords, shape), uncoords) + assert_equal(np.ravel_multi_index(coords, shape), uncoords) assert_equal(coords, np.unravel_index(uncoords, shape)) uncoords = coords[0]+5*(coords[1]+8*coords[2]) - assert_equal(np.ravel_coords(coords, shape, order='F'), uncoords) + assert_equal(np.ravel_multi_index(coords, shape, order='F'), uncoords) assert_equal(coords, np.unravel_index(uncoords, shape, order='F')) def test_clipmodes(self): # Test clipmodes - assert_equal(np.ravel_coords([5,1,-1,2], (4,3,7,12), mode='wrap'), - np.ravel_coords([1,1,6,2], (4,3,7,12))) - assert_equal(np.ravel_coords([5,1,-1,2], (4,3,7,12), + assert_equal(np.ravel_multi_index([5,1,-1,2], (4,3,7,12), mode='wrap'), + np.ravel_multi_index([1,1,6,2], (4,3,7,12))) + assert_equal(np.ravel_multi_index([5,1,-1,2], (4,3,7,12), mode=('wrap','raise','clip','raise')), - np.ravel_coords([1,1,0,2], (4,3,7,12))) - assert_raises(ValueError, np.ravel_coords, [5,1,-1,2], (4,3,7,12)) + np.ravel_multi_index([1,1,0,2], (4,3,7,12))) + assert_raises(ValueError, np.ravel_multi_index, [5,1,-1,2], (4,3,7,12)) class TestGrid(TestCase): def test_basic(self): |