diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/numeric.py | 4 | ||||
-rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.c | 2 | ||||
-rw-r--r-- | numpy/core/src/multiarray/new_iterator_pywrap.c | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_new_iterator.py | 576 |
4 files changed, 292 insertions, 292 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index fa9f19165..187296efe 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -1,4 +1,4 @@ -__all__ = ['newaxis', 'ndarray', 'flatiter', 'newiter', 'nested_iters', 'ufunc', +__all__ = ['newaxis', 'ndarray', 'flatiter', 'nditer', 'nested_iters', 'ufunc', 'arange', 'array', 'zeros', 'count_nonzero', 'empty', 'broadcast', 'dtype', 'fromstring', 'fromfile', 'frombuffer', 'int_asbuffer', 'where', 'argwhere', @@ -54,7 +54,7 @@ BUFSIZE = multiarray.BUFSIZE ndarray = multiarray.ndarray flatiter = multiarray.flatiter -newiter = multiarray.newiter +nditer = multiarray.nditer nested_iters = multiarray.nested_iters broadcast = multiarray.broadcast dtype = multiarray.dtype diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index d39fdb0a8..c964e2f02 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -3857,7 +3857,7 @@ PyMODINIT_FUNC initmultiarray(void) { Py_INCREF(&PyArrayIter_Type); PyDict_SetItemString(d, "flatiter", (PyObject *)&PyArrayIter_Type); Py_INCREF(&PyArrayMultiIter_Type); - PyDict_SetItemString(d, "newiter", (PyObject *)&NpyIter_Type); + PyDict_SetItemString(d, "nditer", (PyObject *)&NpyIter_Type); Py_INCREF(&NpyIter_Type); PyDict_SetItemString(d, "broadcast", (PyObject *)&PyArrayMultiIter_Type); diff --git a/numpy/core/src/multiarray/new_iterator_pywrap.c b/numpy/core/src/multiarray/new_iterator_pywrap.c index a2af3030b..1f2adc535 100644 --- a/numpy/core/src/multiarray/new_iterator_pywrap.c +++ b/numpy/core/src/multiarray/new_iterator_pywrap.c @@ -2450,7 +2450,7 @@ NPY_NO_EXPORT PyTypeObject NpyIter_Type = { PyObject_HEAD_INIT(NULL) 0, /* ob_size */ #endif - "numpy.newiter", /* tp_name */ + "numpy.nditer", /* tp_name */ sizeof(NewNpyArrayIterObject), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ diff --git a/numpy/core/tests/test_new_iterator.py b/numpy/core/tests/test_new_iterator.py index 28cac8563..1c12f6b55 100644 --- a/numpy/core/tests/test_new_iterator.py +++ b/numpy/core/tests/test_new_iterator.py @@ -1,5 +1,5 @@ import numpy as np -from numpy import array, arange, newiter, all +from numpy import array, arange, nditer, all from numpy.compat import asbytes from numpy.testing import * import sys, warnings @@ -35,7 +35,7 @@ def test_iter_refcount(): dt = np.dtype('f4').newbyteorder() rc_a = sys.getrefcount(a) rc_dt = sys.getrefcount(dt) - it = newiter(a, [], + it = nditer(a, [], [['readwrite','updateifcopy']], casting='unsafe', op_dtypes=[dt]) @@ -51,7 +51,7 @@ def test_iter_refcount(): dt = np.dtype('f4') rc_a = sys.getrefcount(a) rc_dt = sys.getrefcount(dt) - it = newiter(a, [], + it = nditer(a, [], [['readwrite']], op_dtypes=[dt]) rc2_a = sys.getrefcount(a) @@ -83,14 +83,14 @@ def test_iter_best_order(): aview = a.reshape(shape)[dirs_index] # C-order - i = newiter(aview, [], [['readonly']]) + i = nditer(aview, [], [['readonly']]) assert_equal([x for x in i], a) # Fortran-order - i = newiter(aview.T, [], [['readonly']]) + i = nditer(aview.T, [], [['readonly']]) assert_equal([x for x in i], a) # Other order if len(shape) > 2: - i = newiter(aview.swapaxes(0,1), [], [['readonly']]) + i = nditer(aview.swapaxes(0,1), [], [['readonly']]) assert_equal([x for x in i], a) def test_iter_c_order(): @@ -109,14 +109,14 @@ def test_iter_c_order(): aview = a.reshape(shape)[dirs_index] # C-order - i = newiter(aview, order='C') + i = nditer(aview, order='C') assert_equal([x for x in i], aview.ravel(order='C')) # Fortran-order - i = newiter(aview.T, order='C') + i = nditer(aview.T, order='C') assert_equal([x for x in i], aview.T.ravel(order='C')) # Other order if len(shape) > 2: - i = newiter(aview.swapaxes(0,1), order='C') + i = nditer(aview.swapaxes(0,1), order='C') assert_equal([x for x in i], aview.swapaxes(0,1).ravel(order='C')) @@ -136,14 +136,14 @@ def test_iter_f_order(): aview = a.reshape(shape)[dirs_index] # C-order - i = newiter(aview, order='F') + i = nditer(aview, order='F') assert_equal([x for x in i], aview.ravel(order='F')) # Fortran-order - i = newiter(aview.T, order='F') + i = nditer(aview.T, order='F') assert_equal([x for x in i], aview.T.ravel(order='F')) # Other order if len(shape) > 2: - i = newiter(aview.swapaxes(0,1), order='F') + i = nditer(aview.swapaxes(0,1), order='F') assert_equal([x for x in i], aview.swapaxes(0,1).ravel(order='F')) @@ -163,14 +163,14 @@ def test_iter_c_or_f_order(): aview = a.reshape(shape)[dirs_index] # C-order - i = newiter(aview, order='A') + i = nditer(aview, order='A') assert_equal([x for x in i], aview.ravel(order='A')) # Fortran-order - i = newiter(aview.T, order='A') + i = nditer(aview.T, order='A') assert_equal([x for x in i], aview.T.ravel(order='A')) # Other order if len(shape) > 2: - i = newiter(aview.swapaxes(0,1), order='A') + i = nditer(aview.swapaxes(0,1), order='A') assert_equal([x for x in i], aview.swapaxes(0,1).ravel(order='A')) @@ -179,10 +179,10 @@ def test_iter_best_order_coords_1d(): a = arange(4) # 1D order - i = newiter(a,['coords'],[['readonly']]) + i = nditer(a,['coords'],[['readonly']]) assert_equal(iter_coords(i), [(0,),(1,),(2,),(3,)]) # 1D reversed order - i = newiter(a[::-1],['coords'],[['readonly']]) + i = nditer(a[::-1],['coords'],[['readonly']]) assert_equal(iter_coords(i), [(3,),(2,),(1,),(0,)]) def test_iter_best_order_coords_2d(): @@ -190,25 +190,25 @@ def test_iter_best_order_coords_2d(): a = arange(6) # 2D C-order - i = newiter(a.reshape(2,3),['coords'],[['readonly']]) + 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)]) # 2D Fortran-order - i = newiter(a.reshape(2,3).copy(order='F'),['coords'],[['readonly']]) + 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)]) # 2D reversed C-order - i = newiter(a.reshape(2,3)[::-1],['coords'],[['readonly']]) + 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 = newiter(a.reshape(2,3)[:,::-1],['coords'],[['readonly']]) + 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 = newiter(a.reshape(2,3)[::-1,::-1],['coords'],[['readonly']]) + 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)]) # 2D reversed Fortran-order - i = newiter(a.reshape(2,3).copy(order='F')[::-1],['coords'],[['readonly']]) + 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 = newiter(a.reshape(2,3).copy(order='F')[:,::-1], + 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)]) - i = newiter(a.reshape(2,3).copy(order='F')[::-1,::-1], + 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)]) @@ -217,40 +217,40 @@ def test_iter_best_order_coords_3d(): a = arange(12) # 3D C-order - i = newiter(a.reshape(2,3,2),['coords'],[['readonly']]) + i = nditer(a.reshape(2,3,2),['coords'],[['readonly']]) assert_equal(iter_coords(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 = newiter(a.reshape(2,3,2).copy(order='F'),['coords'],[['readonly']]) + i = nditer(a.reshape(2,3,2).copy(order='F'),['coords'],[['readonly']]) assert_equal(iter_coords(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 = newiter(a.reshape(2,3,2)[::-1],['coords'],[['readonly']]) + i = nditer(a.reshape(2,3,2)[::-1],['coords'],[['readonly']]) assert_equal(iter_coords(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 = newiter(a.reshape(2,3,2)[:,::-1],['coords'],[['readonly']]) + i = nditer(a.reshape(2,3,2)[:,::-1],['coords'],[['readonly']]) assert_equal(iter_coords(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 = newiter(a.reshape(2,3,2)[:,:,::-1],['coords'],[['readonly']]) + i = nditer(a.reshape(2,3,2)[:,:,::-1],['coords'],[['readonly']]) assert_equal(iter_coords(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 = newiter(a.reshape(2,3,2).copy(order='F')[::-1], + i = nditer(a.reshape(2,3,2).copy(order='F')[::-1], ['coords'],[['readonly']]) assert_equal(iter_coords(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 = newiter(a.reshape(2,3,2).copy(order='F')[:,::-1], + i = nditer(a.reshape(2,3,2).copy(order='F')[:,::-1], ['coords'],[['readonly']]) assert_equal(iter_coords(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 = newiter(a.reshape(2,3,2).copy(order='F')[:,:,::-1], + i = nditer(a.reshape(2,3,2).copy(order='F')[:,:,::-1], ['coords'],[['readonly']]) assert_equal(iter_coords(i), [(0,0,1),(1,0,1),(0,1,1),(1,1,1),(0,2,1),(1,2,1), @@ -261,10 +261,10 @@ def test_iter_best_order_c_index_1d(): a = arange(4) # 1D order - i = newiter(a,['c_index'],[['readonly']]) + i = nditer(a,['c_index'],[['readonly']]) assert_equal(iter_indices(i), [0,1,2,3]) # 1D reversed order - i = newiter(a[::-1],['c_index'],[['readonly']]) + i = nditer(a[::-1],['c_index'],[['readonly']]) assert_equal(iter_indices(i), [3,2,1,0]) def test_iter_best_order_c_index_2d(): @@ -272,27 +272,27 @@ def test_iter_best_order_c_index_2d(): a = arange(6) # 2D C-order - i = newiter(a.reshape(2,3),['c_index'],[['readonly']]) + i = nditer(a.reshape(2,3),['c_index'],[['readonly']]) assert_equal(iter_indices(i), [0,1,2,3,4,5]) # 2D Fortran-order - i = newiter(a.reshape(2,3).copy(order='F'), + i = nditer(a.reshape(2,3).copy(order='F'), ['c_index'],[['readonly']]) assert_equal(iter_indices(i), [0,3,1,4,2,5]) # 2D reversed C-order - i = newiter(a.reshape(2,3)[::-1],['c_index'],[['readonly']]) + i = nditer(a.reshape(2,3)[::-1],['c_index'],[['readonly']]) assert_equal(iter_indices(i), [3,4,5,0,1,2]) - i = newiter(a.reshape(2,3)[:,::-1],['c_index'],[['readonly']]) + i = nditer(a.reshape(2,3)[:,::-1],['c_index'],[['readonly']]) assert_equal(iter_indices(i), [2,1,0,5,4,3]) - i = newiter(a.reshape(2,3)[::-1,::-1],['c_index'],[['readonly']]) + i = nditer(a.reshape(2,3)[::-1,::-1],['c_index'],[['readonly']]) assert_equal(iter_indices(i), [5,4,3,2,1,0]) # 2D reversed Fortran-order - i = newiter(a.reshape(2,3).copy(order='F')[::-1], + i = nditer(a.reshape(2,3).copy(order='F')[::-1], ['c_index'],[['readonly']]) assert_equal(iter_indices(i), [3,0,4,1,5,2]) - i = newiter(a.reshape(2,3).copy(order='F')[:,::-1], + i = nditer(a.reshape(2,3).copy(order='F')[:,::-1], ['c_index'],[['readonly']]) assert_equal(iter_indices(i), [2,5,1,4,0,3]) - i = newiter(a.reshape(2,3).copy(order='F')[::-1,::-1], + i = nditer(a.reshape(2,3).copy(order='F')[::-1,::-1], ['c_index'],[['readonly']]) assert_equal(iter_indices(i), [5,2,4,1,3,0]) @@ -301,34 +301,34 @@ def test_iter_best_order_c_index_3d(): a = arange(12) # 3D C-order - i = newiter(a.reshape(2,3,2),['c_index'],[['readonly']]) + i = nditer(a.reshape(2,3,2),['c_index'],[['readonly']]) assert_equal(iter_indices(i), [0,1,2,3,4,5,6,7,8,9,10,11]) # 3D Fortran-order - i = newiter(a.reshape(2,3,2).copy(order='F'), + i = nditer(a.reshape(2,3,2).copy(order='F'), ['c_index'],[['readonly']]) assert_equal(iter_indices(i), [0,6,2,8,4,10,1,7,3,9,5,11]) # 3D reversed C-order - i = newiter(a.reshape(2,3,2)[::-1],['c_index'],[['readonly']]) + i = nditer(a.reshape(2,3,2)[::-1],['c_index'],[['readonly']]) assert_equal(iter_indices(i), [6,7,8,9,10,11,0,1,2,3,4,5]) - i = newiter(a.reshape(2,3,2)[:,::-1],['c_index'],[['readonly']]) + i = nditer(a.reshape(2,3,2)[:,::-1],['c_index'],[['readonly']]) assert_equal(iter_indices(i), [4,5,2,3,0,1,10,11,8,9,6,7]) - i = newiter(a.reshape(2,3,2)[:,:,::-1],['c_index'],[['readonly']]) + i = nditer(a.reshape(2,3,2)[:,:,::-1],['c_index'],[['readonly']]) assert_equal(iter_indices(i), [1,0,3,2,5,4,7,6,9,8,11,10]) # 3D reversed Fortran-order - i = newiter(a.reshape(2,3,2).copy(order='F')[::-1], + i = nditer(a.reshape(2,3,2).copy(order='F')[::-1], ['c_index'],[['readonly']]) assert_equal(iter_indices(i), [6,0,8,2,10,4,7,1,9,3,11,5]) - i = newiter(a.reshape(2,3,2).copy(order='F')[:,::-1], + i = nditer(a.reshape(2,3,2).copy(order='F')[:,::-1], ['c_index'],[['readonly']]) assert_equal(iter_indices(i), [4,10,2,8,0,6,5,11,3,9,1,7]) - i = newiter(a.reshape(2,3,2).copy(order='F')[:,:,::-1], + i = nditer(a.reshape(2,3,2).copy(order='F')[:,:,::-1], ['c_index'],[['readonly']]) assert_equal(iter_indices(i), [1,7,3,9,5,11,0,6,2,8,4,10]) @@ -338,10 +338,10 @@ def test_iter_best_order_f_index_1d(): a = arange(4) # 1D order - i = newiter(a,['f_index'],[['readonly']]) + i = nditer(a,['f_index'],[['readonly']]) assert_equal(iter_indices(i), [0,1,2,3]) # 1D reversed order - i = newiter(a[::-1],['f_index'],[['readonly']]) + i = nditer(a[::-1],['f_index'],[['readonly']]) assert_equal(iter_indices(i), [3,2,1,0]) def test_iter_best_order_f_index_2d(): @@ -349,27 +349,27 @@ def test_iter_best_order_f_index_2d(): a = arange(6) # 2D C-order - i = newiter(a.reshape(2,3),['f_index'],[['readonly']]) + i = nditer(a.reshape(2,3),['f_index'],[['readonly']]) assert_equal(iter_indices(i), [0,2,4,1,3,5]) # 2D Fortran-order - i = newiter(a.reshape(2,3).copy(order='F'), + i = nditer(a.reshape(2,3).copy(order='F'), ['f_index'],[['readonly']]) assert_equal(iter_indices(i), [0,1,2,3,4,5]) # 2D reversed C-order - i = newiter(a.reshape(2,3)[::-1],['f_index'],[['readonly']]) + i = nditer(a.reshape(2,3)[::-1],['f_index'],[['readonly']]) assert_equal(iter_indices(i), [1,3,5,0,2,4]) - i = newiter(a.reshape(2,3)[:,::-1],['f_index'],[['readonly']]) + i = nditer(a.reshape(2,3)[:,::-1],['f_index'],[['readonly']]) assert_equal(iter_indices(i), [4,2,0,5,3,1]) - i = newiter(a.reshape(2,3)[::-1,::-1],['f_index'],[['readonly']]) + i = nditer(a.reshape(2,3)[::-1,::-1],['f_index'],[['readonly']]) assert_equal(iter_indices(i), [5,3,1,4,2,0]) # 2D reversed Fortran-order - i = newiter(a.reshape(2,3).copy(order='F')[::-1], + i = nditer(a.reshape(2,3).copy(order='F')[::-1], ['f_index'],[['readonly']]) assert_equal(iter_indices(i), [1,0,3,2,5,4]) - i = newiter(a.reshape(2,3).copy(order='F')[:,::-1], + i = nditer(a.reshape(2,3).copy(order='F')[:,::-1], ['f_index'],[['readonly']]) assert_equal(iter_indices(i), [4,5,2,3,0,1]) - i = newiter(a.reshape(2,3).copy(order='F')[::-1,::-1], + i = nditer(a.reshape(2,3).copy(order='F')[::-1,::-1], ['f_index'],[['readonly']]) assert_equal(iter_indices(i), [5,4,3,2,1,0]) @@ -378,34 +378,34 @@ def test_iter_best_order_f_index_3d(): a = arange(12) # 3D C-order - i = newiter(a.reshape(2,3,2),['f_index'],[['readonly']]) + i = nditer(a.reshape(2,3,2),['f_index'],[['readonly']]) assert_equal(iter_indices(i), [0,6,2,8,4,10,1,7,3,9,5,11]) # 3D Fortran-order - i = newiter(a.reshape(2,3,2).copy(order='F'), + i = nditer(a.reshape(2,3,2).copy(order='F'), ['f_index'],[['readonly']]) assert_equal(iter_indices(i), [0,1,2,3,4,5,6,7,8,9,10,11]) # 3D reversed C-order - i = newiter(a.reshape(2,3,2)[::-1],['f_index'],[['readonly']]) + i = nditer(a.reshape(2,3,2)[::-1],['f_index'],[['readonly']]) assert_equal(iter_indices(i), [1,7,3,9,5,11,0,6,2,8,4,10]) - i = newiter(a.reshape(2,3,2)[:,::-1],['f_index'],[['readonly']]) + i = nditer(a.reshape(2,3,2)[:,::-1],['f_index'],[['readonly']]) assert_equal(iter_indices(i), [4,10,2,8,0,6,5,11,3,9,1,7]) - i = newiter(a.reshape(2,3,2)[:,:,::-1],['f_index'],[['readonly']]) + i = nditer(a.reshape(2,3,2)[:,:,::-1],['f_index'],[['readonly']]) assert_equal(iter_indices(i), [6,0,8,2,10,4,7,1,9,3,11,5]) # 3D reversed Fortran-order - i = newiter(a.reshape(2,3,2).copy(order='F')[::-1], + i = nditer(a.reshape(2,3,2).copy(order='F')[::-1], ['f_index'],[['readonly']]) assert_equal(iter_indices(i), [1,0,3,2,5,4,7,6,9,8,11,10]) - i = newiter(a.reshape(2,3,2).copy(order='F')[:,::-1], + i = nditer(a.reshape(2,3,2).copy(order='F')[:,::-1], ['f_index'],[['readonly']]) assert_equal(iter_indices(i), [4,5,2,3,0,1,10,11,8,9,6,7]) - i = newiter(a.reshape(2,3,2).copy(order='F')[:,:,::-1], + i = nditer(a.reshape(2,3,2).copy(order='F')[:,:,::-1], ['f_index'],[['readonly']]) assert_equal(iter_indices(i), [6,7,8,9,10,11,0,1,2,3,4,5]) @@ -426,16 +426,16 @@ def test_iter_no_inner_full_coalesce(): aview = a.reshape(shape)[dirs_index] # C-order - i = newiter(aview, ['no_inner_iteration'], [['readonly']]) + i = nditer(aview, ['no_inner_iteration'], [['readonly']]) assert_equal(i.ndim, 1) assert_equal(i[0].shape, (size,)) # Fortran-order - i = newiter(aview.T, ['no_inner_iteration'], [['readonly']]) + i = nditer(aview.T, ['no_inner_iteration'], [['readonly']]) assert_equal(i.ndim, 1) assert_equal(i[0].shape, (size,)) # Other order if len(shape) > 2: - i = newiter(aview.swapaxes(0,1), + i = nditer(aview.swapaxes(0,1), ['no_inner_iteration'], [['readonly']]) assert_equal(i.ndim, 1) assert_equal(i[0].shape, (size,)) @@ -446,21 +446,21 @@ def test_iter_no_inner_dim_coalescing(): # Skipping the last element in a dimension prevents coalescing # with the next-bigger dimension a = arange(24).reshape(2,3,4)[:,:,:-1] - i = newiter(a, ['no_inner_iteration'], [['readonly']]) + i = nditer(a, ['no_inner_iteration'], [['readonly']]) assert_equal(i.ndim, 2) assert_equal(i[0].shape, (3,)) a = arange(24).reshape(2,3,4)[:,:-1,:] - i = newiter(a, ['no_inner_iteration'], [['readonly']]) + i = nditer(a, ['no_inner_iteration'], [['readonly']]) assert_equal(i.ndim, 2) assert_equal(i[0].shape, (8,)) a = arange(24).reshape(2,3,4)[:-1,:,:] - i = newiter(a, ['no_inner_iteration'], [['readonly']]) + i = nditer(a, ['no_inner_iteration'], [['readonly']]) assert_equal(i.ndim, 1) assert_equal(i[0].shape, (12,)) # Even with lots of 1-sized dimensions, should still coalesce a = arange(24).reshape(1,1,2,1,1,3,1,1,4,1,1) - i = newiter(a, ['no_inner_iteration'], [['readonly']]) + i = nditer(a, ['no_inner_iteration'], [['readonly']]) assert_equal(i.ndim, 1) assert_equal(i[0].shape, (24,)) @@ -469,103 +469,103 @@ def test_iter_dim_coalescing(): # Tracking coordinates disables coalescing a = arange(24).reshape(2,3,4) - i = newiter(a, ['coords'], [['readonly']]) + i = nditer(a, ['coords'], [['readonly']]) assert_equal(i.ndim, 3) # A tracked index can allow coalescing if it's compatible with the array a3d = arange(24).reshape(2,3,4) - i = newiter(a3d, ['c_index'], [['readonly']]) + i = nditer(a3d, ['c_index'], [['readonly']]) assert_equal(i.ndim, 1) - i = newiter(a3d.swapaxes(0,1), ['c_index'], [['readonly']]) + i = nditer(a3d.swapaxes(0,1), ['c_index'], [['readonly']]) assert_equal(i.ndim, 3) - i = newiter(a3d.T, ['c_index'], [['readonly']]) + i = nditer(a3d.T, ['c_index'], [['readonly']]) assert_equal(i.ndim, 3) - i = newiter(a3d.T, ['f_index'], [['readonly']]) + i = nditer(a3d.T, ['f_index'], [['readonly']]) assert_equal(i.ndim, 1) - i = newiter(a3d.T.swapaxes(0,1), ['f_index'], [['readonly']]) + i = nditer(a3d.T.swapaxes(0,1), ['f_index'], [['readonly']]) assert_equal(i.ndim, 3) # When C or F order is forced, coalescing may still occur a3d = arange(24).reshape(2,3,4) - i = newiter(a3d, order='C') + i = nditer(a3d, order='C') assert_equal(i.ndim, 1) - i = newiter(a3d.T, order='C') + i = nditer(a3d.T, order='C') assert_equal(i.ndim, 3) - i = newiter(a3d, order='F') + i = nditer(a3d, order='F') assert_equal(i.ndim, 3) - i = newiter(a3d.T, order='F') + i = nditer(a3d.T, order='F') assert_equal(i.ndim, 1) - i = newiter(a3d, order='A') + i = nditer(a3d, order='A') assert_equal(i.ndim, 1) - i = newiter(a3d.T, order='A') + i = nditer(a3d.T, order='A') assert_equal(i.ndim, 1) def test_iter_broadcasting(): # Standard NumPy broadcasting rules # 1D with scalar - i = newiter([arange(6), np.int32(2)], ['coords'], [['readonly']]*2) + i = nditer([arange(6), np.int32(2)], ['coords'], [['readonly']]*2) assert_equal(i.itersize, 6) assert_equal(i.shape, (6,)) # 2D with scalar - i = newiter([arange(6).reshape(2,3), np.int32(2)], + i = nditer([arange(6).reshape(2,3), np.int32(2)], ['coords'], [['readonly']]*2) assert_equal(i.itersize, 6) assert_equal(i.shape, (2,3)) # 2D with 1D - i = newiter([arange(6).reshape(2,3), arange(3)], + i = nditer([arange(6).reshape(2,3), arange(3)], ['coords'], [['readonly']]*2) assert_equal(i.itersize, 6) assert_equal(i.shape, (2,3)) - i = newiter([arange(2).reshape(2,1), arange(3)], + i = nditer([arange(2).reshape(2,1), arange(3)], ['coords'], [['readonly']]*2) assert_equal(i.itersize, 6) assert_equal(i.shape, (2,3)) # 2D with 2D - i = newiter([arange(2).reshape(2,1), arange(3).reshape(1,3)], + i = nditer([arange(2).reshape(2,1), arange(3).reshape(1,3)], ['coords'], [['readonly']]*2) assert_equal(i.itersize, 6) assert_equal(i.shape, (2,3)) # 3D with scalar - i = newiter([np.int32(2), arange(24).reshape(4,2,3)], + i = nditer([np.int32(2), arange(24).reshape(4,2,3)], ['coords'], [['readonly']]*2) assert_equal(i.itersize, 24) assert_equal(i.shape, (4,2,3)) # 3D with 1D - i = newiter([arange(3), arange(24).reshape(4,2,3)], + i = nditer([arange(3), arange(24).reshape(4,2,3)], ['coords'], [['readonly']]*2) assert_equal(i.itersize, 24) assert_equal(i.shape, (4,2,3)) - i = newiter([arange(3), arange(8).reshape(4,2,1)], + i = nditer([arange(3), arange(8).reshape(4,2,1)], ['coords'], [['readonly']]*2) assert_equal(i.itersize, 24) assert_equal(i.shape, (4,2,3)) # 3D with 2D - i = newiter([arange(6).reshape(2,3), arange(24).reshape(4,2,3)], + i = nditer([arange(6).reshape(2,3), arange(24).reshape(4,2,3)], ['coords'], [['readonly']]*2) assert_equal(i.itersize, 24) assert_equal(i.shape, (4,2,3)) - i = newiter([arange(2).reshape(2,1), arange(24).reshape(4,2,3)], + i = nditer([arange(2).reshape(2,1), arange(24).reshape(4,2,3)], ['coords'], [['readonly']]*2) assert_equal(i.itersize, 24) assert_equal(i.shape, (4,2,3)) - i = newiter([arange(3).reshape(1,3), arange(8).reshape(4,2,1)], + i = nditer([arange(3).reshape(1,3), arange(8).reshape(4,2,1)], ['coords'], [['readonly']]*2) assert_equal(i.itersize, 24) assert_equal(i.shape, (4,2,3)) # 3D with 3D - i = newiter([arange(2).reshape(1,2,1), arange(3).reshape(1,1,3), + i = nditer([arange(2).reshape(1,2,1), arange(3).reshape(1,1,3), arange(4).reshape(4,1,1)], ['coords'], [['readonly']]*3) assert_equal(i.itersize, 24) assert_equal(i.shape, (4,2,3)) - i = newiter([arange(6).reshape(1,2,3), arange(4).reshape(4,1,1)], + i = nditer([arange(6).reshape(1,2,3), arange(4).reshape(4,1,1)], ['coords'], [['readonly']]*2) assert_equal(i.itersize, 24) assert_equal(i.shape, (4,2,3)) - i = newiter([arange(24).reshape(4,2,3), arange(12).reshape(4,1,3)], + i = nditer([arange(24).reshape(4,2,3), arange(12).reshape(4,1,3)], ['coords'], [['readonly']]*2) assert_equal(i.itersize, 24) assert_equal(i.shape, (4,2,3)) @@ -573,19 +573,19 @@ def test_iter_broadcasting(): def test_iter_itershape(): # Check that allocated outputs work with a specified shape a = np.arange(6, dtype='i2').reshape(2,3) - i = newiter([a, None], [], [['readonly'], ['writeonly','allocate']], + i = nditer([a, None], [], [['readonly'], ['writeonly','allocate']], op_axes=[[0,1,None], None], itershape=(-1,-1,4)) assert_equal(i.operands[1].shape, (2,3,4)) assert_equal(i.operands[1].strides, (24,8,2)) - i = newiter([a.T, None], [], [['readonly'], ['writeonly','allocate']], + i = nditer([a.T, None], [], [['readonly'], ['writeonly','allocate']], op_axes=[[0,1,None], None], itershape=(-1,-1,4)) assert_equal(i.operands[1].shape, (3,2,4)) assert_equal(i.operands[1].strides, (8,24,2)) - i = newiter([a.T, None], [], [['readonly'], ['writeonly','allocate']], + i = nditer([a.T, None], [], [['readonly'], ['writeonly','allocate']], order='F', op_axes=[[0,1,None], None], itershape=(-1,-1,4)) @@ -594,7 +594,7 @@ def test_iter_itershape(): # If we specify 1 in the itershape, it shouldn't allow broadcasting # of that dimension to a bigger value - assert_raises(ValueError, newiter, [a, None], [], + assert_raises(ValueError, nditer, [a, None], [], [['readonly'], ['writeonly','allocate']], op_axes=[[0,1,None], None], itershape=(-1,1,4)) @@ -603,30 +603,30 @@ def test_iter_broadcasting_errors(): # Check that errors are thrown for bad broadcasting shapes # 1D with 1D - assert_raises(ValueError, newiter, [arange(2), arange(3)], + assert_raises(ValueError, nditer, [arange(2), arange(3)], [], [['readonly']]*2) # 2D with 1D - assert_raises(ValueError, newiter, + assert_raises(ValueError, nditer, [arange(6).reshape(2,3), arange(2)], [], [['readonly']]*2) # 2D with 2D - assert_raises(ValueError, newiter, + assert_raises(ValueError, nditer, [arange(6).reshape(2,3), arange(9).reshape(3,3)], [], [['readonly']]*2) - assert_raises(ValueError, newiter, + assert_raises(ValueError, nditer, [arange(6).reshape(2,3), arange(4).reshape(2,2)], [], [['readonly']]*2) # 3D with 3D - assert_raises(ValueError, newiter, + assert_raises(ValueError, nditer, [arange(36).reshape(3,3,4), arange(24).reshape(2,3,4)], [], [['readonly']]*2) - assert_raises(ValueError, newiter, + assert_raises(ValueError, nditer, [arange(8).reshape(2,4,1), arange(24).reshape(2,3,4)], [], [['readonly']]*2) # Verify that the error message mentions the right shapes try: - i = newiter([arange(2).reshape(1,2,1), + i = nditer([arange(2).reshape(1,2,1), arange(3).reshape(1,3), arange(6).reshape(2,3)], [], @@ -648,49 +648,49 @@ def test_iter_flags_errors(): a = arange(6) # Not enough operands - assert_raises(ValueError, newiter, [], [], []) + assert_raises(ValueError, nditer, [], [], []) # Too many operands - assert_raises(ValueError, newiter, [a]*100, [], [['readonly']]*100) + assert_raises(ValueError, nditer, [a]*100, [], [['readonly']]*100) # Bad global flag - assert_raises(ValueError, newiter, [a], ['bad flag'], [['readonly']]) + assert_raises(ValueError, nditer, [a], ['bad flag'], [['readonly']]) # Bad op flag - assert_raises(ValueError, newiter, [a], [], [['readonly','bad flag']]) + assert_raises(ValueError, nditer, [a], [], [['readonly','bad flag']]) # Bad order parameter - assert_raises(ValueError, newiter, [a], [], [['readonly']], order='G') + assert_raises(ValueError, nditer, [a], [], [['readonly']], order='G') # Bad casting parameter - assert_raises(ValueError, newiter, [a], [], [['readonly']], casting='noon') + assert_raises(ValueError, nditer, [a], [], [['readonly']], casting='noon') # op_flags must match ops - assert_raises(ValueError, newiter, [a]*3, [], [['readonly']]*2) + assert_raises(ValueError, nditer, [a]*3, [], [['readonly']]*2) # Cannot track both a C and an F index - assert_raises(ValueError, newiter, a, + assert_raises(ValueError, nditer, a, ['c_index','f_index'], [['readonly']]) # Inner iteration and coords/indices are incompatible - assert_raises(ValueError, newiter, a, + assert_raises(ValueError, nditer, a, ['no_inner_iteration','coords'], [['readonly']]) - assert_raises(ValueError, newiter, a, + assert_raises(ValueError, nditer, a, ['no_inner_iteration','c_index'], [['readonly']]) - assert_raises(ValueError, newiter, a, + assert_raises(ValueError, nditer, a, ['no_inner_iteration','f_index'], [['readonly']]) # Must specify exactly one of readwrite/readonly/writeonly per operand - assert_raises(ValueError, newiter, a, [], [[]]) - assert_raises(ValueError, newiter, a, [], [['readonly','writeonly']]) - assert_raises(ValueError, newiter, a, [], [['readonly','readwrite']]) - assert_raises(ValueError, newiter, a, [], [['writeonly','readwrite']]) - assert_raises(ValueError, newiter, a, + assert_raises(ValueError, nditer, a, [], [[]]) + assert_raises(ValueError, nditer, a, [], [['readonly','writeonly']]) + assert_raises(ValueError, nditer, a, [], [['readonly','readwrite']]) + assert_raises(ValueError, nditer, a, [], [['writeonly','readwrite']]) + assert_raises(ValueError, nditer, a, [], [['readonly','writeonly','readwrite']]) # Python scalars are always readonly - assert_raises(TypeError, newiter, 1.5, [], [['writeonly']]) - assert_raises(TypeError, newiter, 1.5, [], [['readwrite']]) + assert_raises(TypeError, nditer, 1.5, [], [['writeonly']]) + assert_raises(TypeError, nditer, 1.5, [], [['readwrite']]) # Array scalars are always readonly - assert_raises(TypeError, newiter, np.int32(1), [], [['writeonly']]) - assert_raises(TypeError, newiter, np.int32(1), [], [['readwrite']]) + assert_raises(TypeError, nditer, np.int32(1), [], [['writeonly']]) + assert_raises(TypeError, nditer, np.int32(1), [], [['readwrite']]) # Check readonly array a.flags.writeable = False - assert_raises(ValueError, newiter, a, [], [['writeonly']]) - assert_raises(ValueError, newiter, a, [], [['readwrite']]) + assert_raises(ValueError, nditer, a, [], [['writeonly']]) + assert_raises(ValueError, nditer, a, [], [['readwrite']]) a.flags.writeable = True # Coords available only with the coords flag - i = newiter(arange(6), [], [['readonly']]) + i = nditer(arange(6), [], [['readonly']]) assert_raises(ValueError, lambda i:i.coords, i) # Index available only with an index flag assert_raises(ValueError, lambda i:i.index, i) @@ -703,21 +703,21 @@ def test_iter_flags_errors(): i.iterindex = 0; def assign_iterrange(i): i.iterrange = (0,1); - i = newiter(arange(6), ['no_inner_iteration']) + i = nditer(arange(6), ['no_inner_iteration']) assert_raises(ValueError, assign_coords, i) assert_raises(ValueError, assign_index, i) assert_raises(ValueError, assign_iterindex, i) assert_raises(ValueError, assign_iterrange, i) - i = newiter(arange(6), ['buffered']) + i = nditer(arange(6), ['buffered']) assert_raises(ValueError, assign_coords, i) assert_raises(ValueError, assign_index, i) assert_raises(ValueError, assign_iterrange, i) # Can't iterate if size is zero - assert_raises(ValueError, newiter, np.array([])) + assert_raises(ValueError, nditer, np.array([])) def test_iter_slice(): a, b, c = np.arange(3), np.arange(3), np.arange(3.) - i = newiter([a,b,c], [], ['readwrite']) + i = nditer([a,b,c], [], ['readwrite']) i[0:2] = (3,3) assert_equal(a, [3,1,2]) assert_equal(b, [3,1,2]) @@ -732,7 +732,7 @@ def test_iter_nbo_align_contig(): a = np.arange(6, dtype='f4') au = a.byteswap().newbyteorder() assert_(a.dtype.byteorder != au.dtype.byteorder) - i = newiter(au, [], [['readwrite','updateifcopy']], + i = nditer(au, [], [['readwrite','updateifcopy']], casting='equiv', op_dtypes=[np.dtype('f4')]) assert_equal(i.dtypes[0].byteorder, a.dtype.byteorder) @@ -746,7 +746,7 @@ def test_iter_nbo_align_contig(): a = np.arange(6, dtype='f4') au = a.byteswap().newbyteorder() assert_(a.dtype.byteorder != au.dtype.byteorder) - i = newiter(au, [], [['readwrite','updateifcopy','nbo']], casting='equiv') + i = nditer(au, [], [['readwrite','updateifcopy','nbo']], casting='equiv') assert_equal(i.dtypes[0].byteorder, a.dtype.byteorder) assert_equal(i.operands[0].dtype.byteorder, a.dtype.byteorder) assert_equal(i.operands[0], a) @@ -760,11 +760,11 @@ def test_iter_nbo_align_contig(): a[:] = np.arange(6, dtype='f4') assert_(not a.flags.aligned) # Without 'aligned', shouldn't copy - i = newiter(a, [], [['readonly']]) + i = nditer(a, [], [['readonly']]) assert_(not i.operands[0].flags.aligned) assert_equal(i.operands[0], a); # With 'aligned', should make a copy - i = newiter(a, [], [['readwrite','updateifcopy','aligned']]) + i = nditer(a, [], [['readwrite','updateifcopy','aligned']]) assert_(i.operands[0].flags.aligned) assert_equal(i.operands[0], a); i.operands[0][:] = 3 @@ -774,11 +774,11 @@ def test_iter_nbo_align_contig(): # Discontiguous input a = arange(12) # If it is contiguous, shouldn't copy - i = newiter(a[:6], [], [['readonly']]) + i = nditer(a[:6], [], [['readonly']]) assert_(i.operands[0].flags.contiguous) assert_equal(i.operands[0], a[:6]); # If it isn't contiguous, should buffer - i = newiter(a[::2], ['buffered','no_inner_iteration'], + i = nditer(a[::2], ['buffered','no_inner_iteration'], [['readonly','contig']], buffersize=10) assert_(i[0].flags.contiguous) @@ -789,13 +789,13 @@ def test_iter_array_cast(): # No cast 'f4' -> 'f4' a = np.arange(6, dtype='f4').reshape(2,3) - i = newiter(a, [], [['readwrite']], op_dtypes=[np.dtype('f4')]) + i = nditer(a, [], [['readwrite']], op_dtypes=[np.dtype('f4')]) assert_equal(i.operands[0], a) assert_equal(i.operands[0].dtype, np.dtype('f4')) # Byte-order cast '<f4' -> '>f4' a = np.arange(6, dtype='<f4').reshape(2,3) - i = newiter(a, [], [['readwrite','updateifcopy']], + i = nditer(a, [], [['readwrite','updateifcopy']], casting='equiv', op_dtypes=[np.dtype('>f4')]) assert_equal(i.operands[0], a) @@ -803,7 +803,7 @@ def test_iter_array_cast(): # Safe case 'f4' -> 'f8' a = np.arange(24, dtype='f4').reshape(2,3,4).swapaxes(1,2) - i = newiter(a, [], [['readonly','copy']], + i = nditer(a, [], [['readonly','copy']], casting='safe', op_dtypes=[np.dtype('f8')]) assert_equal(i.operands[0], a) @@ -811,7 +811,7 @@ def test_iter_array_cast(): # The memory layout of the temporary should match a (a is (48,4,16)) assert_equal(i.operands[0].strides, (96,8,32)) a = a[::-1,:,::-1] - i = newiter(a, [], [['readonly','copy']], + i = nditer(a, [], [['readonly','copy']], casting='safe', op_dtypes=[np.dtype('f8')]) assert_equal(i.operands[0], a) @@ -820,7 +820,7 @@ def test_iter_array_cast(): # Same-kind cast 'f8' -> 'f4' -> 'f8' a = np.arange(24, dtype='f8').reshape(2,3,4).T - i = newiter(a, [], + i = nditer(a, [], [['readwrite','updateifcopy']], casting='same_kind', op_dtypes=[np.dtype('f4')]) @@ -835,7 +835,7 @@ def test_iter_array_cast(): # Unsafe cast 'f4' -> 'i4' a = np.arange(6, dtype='i4')[::-2] - i = newiter(a, [], + i = nditer(a, [], [['writeonly','updateifcopy']], casting='unsafe', op_dtypes=[np.dtype('f4')]) @@ -849,42 +849,42 @@ def test_iter_array_cast_errors(): # Check that invalid casts are caught # Need to enable copying for casts to occur - assert_raises(TypeError, newiter, arange(2,dtype='f4'), [], + assert_raises(TypeError, nditer, arange(2,dtype='f4'), [], [['readonly']], op_dtypes=[np.dtype('f8')]) # Also need to allow casting for casts to occur - assert_raises(TypeError, newiter, arange(2,dtype='f4'), [], + assert_raises(TypeError, nditer, arange(2,dtype='f4'), [], [['readonly','copy']], casting='no', op_dtypes=[np.dtype('f8')]) - assert_raises(TypeError, newiter, arange(2,dtype='f4'), [], + assert_raises(TypeError, nditer, arange(2,dtype='f4'), [], [['readonly','copy']], casting='equiv', op_dtypes=[np.dtype('f8')]) - assert_raises(TypeError, newiter, arange(2,dtype='f8'), [], + assert_raises(TypeError, nditer, arange(2,dtype='f8'), [], [['writeonly','updateifcopy']], casting='no', op_dtypes=[np.dtype('f4')]) - assert_raises(TypeError, newiter, arange(2,dtype='f8'), [], + assert_raises(TypeError, nditer, arange(2,dtype='f8'), [], [['writeonly','updateifcopy']], casting='equiv', op_dtypes=[np.dtype('f4')]) # '<f4' -> '>f4' should not work with casting='no' - assert_raises(TypeError, newiter, arange(2,dtype='<f4'), [], + assert_raises(TypeError, nditer, arange(2,dtype='<f4'), [], [['readonly','copy']], casting='no', op_dtypes=[np.dtype('>f4')]) # 'f4' -> 'f8' is a safe cast, but 'f8' -> 'f4' isn't - assert_raises(TypeError, newiter, arange(2,dtype='f4'), [], + assert_raises(TypeError, nditer, arange(2,dtype='f4'), [], [['readwrite','updateifcopy']], casting='safe', op_dtypes=[np.dtype('f8')]) - assert_raises(TypeError, newiter, arange(2,dtype='f8'), [], + assert_raises(TypeError, nditer, arange(2,dtype='f8'), [], [['readwrite','updateifcopy']], casting='safe', op_dtypes=[np.dtype('f4')]) # 'f4' -> 'i4' is neither a safe nor a same-kind cast - assert_raises(TypeError, newiter, arange(2,dtype='f4'), [], + assert_raises(TypeError, nditer, arange(2,dtype='f4'), [], [['readonly','copy']], casting='same_kind', op_dtypes=[np.dtype('i4')]) - assert_raises(TypeError, newiter, arange(2,dtype='i4'), [], + assert_raises(TypeError, nditer, arange(2,dtype='i4'), [], [['writeonly','updateifcopy']], casting='same_kind', op_dtypes=[np.dtype('f4')]) @@ -893,13 +893,13 @@ def test_iter_scalar_cast(): # Check that scalars are cast as requested # No cast 'f4' -> 'f4' - i = newiter(np.float32(2.5), [], [['readonly']], + i = nditer(np.float32(2.5), [], [['readonly']], op_dtypes=[np.dtype('f4')]) assert_equal(i.dtypes[0], np.dtype('f4')) assert_equal(i.value.dtype, np.dtype('f4')) assert_equal(i.value, 2.5) # Safe cast 'f4' -> 'f8' - i = newiter(np.float32(2.5), [], + i = nditer(np.float32(2.5), [], [['readonly','copy']], casting='safe', op_dtypes=[np.dtype('f8')]) @@ -907,7 +907,7 @@ def test_iter_scalar_cast(): assert_equal(i.value.dtype, np.dtype('f8')) assert_equal(i.value, 2.5) # Same-kind cast 'f8' -> 'f4' - i = newiter(np.float64(2.5), [], + i = nditer(np.float64(2.5), [], [['readonly','copy']], casting='same_kind', op_dtypes=[np.dtype('f4')]) @@ -915,7 +915,7 @@ def test_iter_scalar_cast(): assert_equal(i.value.dtype, np.dtype('f4')) assert_equal(i.value, 2.5) # Unsafe cast 'f8' -> 'i4' - i = newiter(np.float64(3.0), [], + i = nditer(np.float64(3.0), [], [['readonly','copy']], casting='unsafe', op_dtypes=[np.dtype('i4')]) @@ -923,7 +923,7 @@ def test_iter_scalar_cast(): assert_equal(i.value.dtype, np.dtype('i4')) assert_equal(i.value, 3) # Readonly scalars may be cast even without setting COPY or BUFFERED - i = newiter(3, [], [['readonly']], op_dtypes=[np.dtype('f8')]) + i = nditer(3, [], [['readonly']], op_dtypes=[np.dtype('f8')]) assert_equal(i[0].dtype, np.dtype('f8')) assert_equal(i[0], 3.) @@ -931,17 +931,17 @@ def test_iter_scalar_cast_errors(): # Check that invalid casts are caught # Need to allow copying/buffering for write casts of scalars to occur - assert_raises(TypeError, newiter, np.float32(2), [], + assert_raises(TypeError, nditer, np.float32(2), [], [['readwrite']], op_dtypes=[np.dtype('f8')]) - assert_raises(TypeError, newiter, 2.5, [], + assert_raises(TypeError, nditer, 2.5, [], [['readwrite']], op_dtypes=[np.dtype('f4')]) # 'f8' -> 'f4' isn't a safe cast if the value would overflow - assert_raises(TypeError, newiter, np.float64(1e60), [], + assert_raises(TypeError, nditer, np.float64(1e60), [], [['readonly']], casting='safe', op_dtypes=[np.dtype('f4')]) # 'f4' -> 'i4' is neither a safe nor a same-kind cast - assert_raises(TypeError, newiter, np.float32(2), [], + assert_raises(TypeError, nditer, np.float32(2), [], [['readonly']], casting='same_kind', op_dtypes=[np.dtype('i4')]) @@ -954,16 +954,16 @@ def test_iter_object_arrays_basic(): rc = sys.getrefcount(obj) # Need to allow references for object arrays - assert_raises(TypeError, newiter, a) + assert_raises(TypeError, nditer, a) assert_equal(sys.getrefcount(obj), rc) - i = newiter(a, ['refs_ok'], ['readonly']) + i = nditer(a, ['refs_ok'], ['readonly']) vals = [x[()] for x in i] assert_equal(np.array(vals, dtype='O'), a) vals, i, x = [None]*3 assert_equal(sys.getrefcount(obj), rc) - i = newiter(a.reshape(2,2).T, ['refs_ok','buffered'], + i = nditer(a.reshape(2,2).T, ['refs_ok','buffered'], ['readonly'], order='C') assert_(i.iterationneedsapi) vals = [x[()] for x in i] @@ -971,7 +971,7 @@ def test_iter_object_arrays_basic(): vals, i, x = [None]*3 assert_equal(sys.getrefcount(obj), rc) - i = newiter(a.reshape(2,2).T, ['refs_ok','buffered'], + i = nditer(a.reshape(2,2).T, ['refs_ok','buffered'], ['readwrite'], order='C') for x in i: x[...] = None @@ -982,14 +982,14 @@ def test_iter_object_arrays_basic(): def test_iter_object_arrays_conversions(): # Conversions to/from objects a = np.arange(6, dtype='O') - i = newiter(a, ['refs_ok','buffered'], ['readwrite'], + i = nditer(a, ['refs_ok','buffered'], ['readwrite'], casting='unsafe', op_dtypes='i4') for x in i: x[...] += 1 assert_equal(a, np.arange(6)+1) a = np.arange(6, dtype='i4') - i = newiter(a, ['refs_ok','buffered'], ['readwrite'], + i = nditer(a, ['refs_ok','buffered'], ['readwrite'], casting='unsafe', op_dtypes='O') for x in i: x[...] += 1 @@ -999,7 +999,7 @@ def test_iter_object_arrays_conversions(): a = np.zeros((6,), dtype=[('p','i1'),('a','O')]) a = a['a'] a[:] = np.arange(6) - i = newiter(a, ['refs_ok','buffered'], ['readwrite'], + i = nditer(a, ['refs_ok','buffered'], ['readwrite'], casting='unsafe', op_dtypes='i4') for x in i: x[...] += 1 @@ -1009,7 +1009,7 @@ def test_iter_object_arrays_conversions(): a = np.zeros((6,), dtype=[('p','i1'),('a','i4')]) a = a['a'] a[:] = np.arange(6) + 98172488 - i = newiter(a, ['refs_ok','buffered'], ['readwrite'], + i = nditer(a, ['refs_ok','buffered'], ['readwrite'], casting='unsafe', op_dtypes='O') ob = i[0][()] rc = sys.getrefcount(ob) @@ -1021,37 +1021,37 @@ def test_iter_object_arrays_conversions(): def test_iter_common_dtype(): # Check that the iterator finds a common data type correctly - i = newiter([array([3],dtype='f4'),array([0],dtype='f8')], + i = nditer([array([3],dtype='f4'),array([0],dtype='f8')], ['common_dtype'], [['readonly','copy']]*2, casting='safe') assert_equal(i.dtypes[0], np.dtype('f8')); assert_equal(i.dtypes[1], np.dtype('f8')); - i = newiter([array([3],dtype='i4'),array([0],dtype='f4')], + i = nditer([array([3],dtype='i4'),array([0],dtype='f4')], ['common_dtype'], [['readonly','copy']]*2, casting='safe') assert_equal(i.dtypes[0], np.dtype('f8')); assert_equal(i.dtypes[1], np.dtype('f8')); - i = newiter([array([3],dtype='f4'),array(0,dtype='f8')], + i = nditer([array([3],dtype='f4'),array(0,dtype='f8')], ['common_dtype'], [['readonly','copy']]*2, casting='same_kind') assert_equal(i.dtypes[0], np.dtype('f4')); assert_equal(i.dtypes[1], np.dtype('f4')); - i = newiter([array([3],dtype='u4'),array(0,dtype='i4')], + i = nditer([array([3],dtype='u4'),array(0,dtype='i4')], ['common_dtype'], [['readonly','copy']]*2, casting='safe') assert_equal(i.dtypes[0], np.dtype('u4')); assert_equal(i.dtypes[1], np.dtype('u4')); - i = newiter([array([3],dtype='u4'),array(-12,dtype='i4')], + i = nditer([array([3],dtype='u4'),array(-12,dtype='i4')], ['common_dtype'], [['readonly','copy']]*2, casting='safe') assert_equal(i.dtypes[0], np.dtype('i8')); assert_equal(i.dtypes[1], np.dtype('i8')); - i = newiter([array([3],dtype='u4'),array(-12,dtype='i4'), + i = nditer([array([3],dtype='u4'),array(-12,dtype='i4'), array([2j],dtype='c8'),array([9],dtype='f8')], ['common_dtype'], [['readonly','copy']]*4, @@ -1063,7 +1063,7 @@ def test_iter_common_dtype(): assert_equal(i.value, (3,-12,2j,9)) # When allocating outputs, other outputs aren't factored in - i = newiter([array([3],dtype='i4'),None,array([2j],dtype='c16')], [], + i = nditer([array([3],dtype='i4'),None,array([2j],dtype='c16')], [], [['readonly','copy'], ['writeonly','allocate'], ['writeonly']], @@ -1072,7 +1072,7 @@ def test_iter_common_dtype(): assert_equal(i.dtypes[1], np.dtype('i4')); assert_equal(i.dtypes[2], np.dtype('c16')); # But, if common data types are requested, they are - i = newiter([array([3],dtype='i4'),None,array([2j],dtype='c16')], + i = nditer([array([3],dtype='i4'),None,array([2j],dtype='c16')], ['common_dtype'], [['readonly','copy'], ['writeonly','allocate'], @@ -1087,36 +1087,36 @@ def test_iter_op_axes(): # Reverse the axes a = arange(6).reshape(2,3) - i = newiter([a,a.T], [], [['readonly']]*2, op_axes=[[0,1],[1,0]]) + i = nditer([a,a.T], [], [['readonly']]*2, op_axes=[[0,1],[1,0]]) assert_(all([x==y for (x,y) in i])) a = arange(24).reshape(2,3,4) - i = newiter([a.T,a], [], [['readonly']]*2, op_axes=[[2,1,0],None]) + i = nditer([a.T,a], [], [['readonly']]*2, op_axes=[[2,1,0],None]) assert_(all([x==y for (x,y) in i])) # Broadcast 1D to any dimension a = arange(1,31).reshape(2,3,5) b = arange(1,3) - i = newiter([a,b], [], [['readonly']]*2, op_axes=[None,[0,-1,-1]]) + i = nditer([a,b], [], [['readonly']]*2, op_axes=[None,[0,-1,-1]]) assert_equal([x*y for (x,y) in i], (a*b.reshape(2,1,1)).ravel()) b = arange(1,4) - i = newiter([a,b], [], [['readonly']]*2, op_axes=[None,[-1,0,-1]]) + i = nditer([a,b], [], [['readonly']]*2, op_axes=[None,[-1,0,-1]]) assert_equal([x*y for (x,y) in i], (a*b.reshape(1,3,1)).ravel()) b = arange(1,6) - i = newiter([a,b], [], [['readonly']]*2, + i = nditer([a,b], [], [['readonly']]*2, op_axes=[None,[np.newaxis,np.newaxis,0]]) assert_equal([x*y for (x,y) in i], (a*b.reshape(1,1,5)).ravel()) # Inner product-style broadcasting a = arange(24).reshape(2,3,4) b = arange(40).reshape(5,2,4) - i = newiter([a,b], ['coords'], [['readonly']]*2, + i = nditer([a,b], ['coords'], [['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 = newiter([a,b], ['coords'], [['readonly']]*2, + i = nditer([a,b], ['coords'], [['readonly']]*2, op_axes=[[0,-1],[-1,1]]) assert_equal(i.shape, (3,5)) @@ -1125,25 +1125,25 @@ def test_iter_op_axes_errors(): # Wrong number of items in op_axes a = arange(6).reshape(2,3) - assert_raises(ValueError, newiter, [a,a], [], [['readonly']]*2, + assert_raises(ValueError, nditer, [a,a], [], [['readonly']]*2, op_axes=[[0],[1],[0]]) # Out of bounds items in op_axes - assert_raises(ValueError, newiter, [a,a], [], [['readonly']]*2, + assert_raises(ValueError, nditer, [a,a], [], [['readonly']]*2, op_axes=[[2,1],[0,1]]) - assert_raises(ValueError, newiter, [a,a], [], [['readonly']]*2, + assert_raises(ValueError, nditer, [a,a], [], [['readonly']]*2, op_axes=[[0,1],[2,-1]]) # Duplicate items in op_axes - assert_raises(ValueError, newiter, [a,a], [], [['readonly']]*2, + assert_raises(ValueError, nditer, [a,a], [], [['readonly']]*2, op_axes=[[0,0],[0,1]]) - assert_raises(ValueError, newiter, [a,a], [], [['readonly']]*2, + assert_raises(ValueError, nditer, [a,a], [], [['readonly']]*2, op_axes=[[0,1],[1,1]]) # Different sized arrays in op_axes - assert_raises(ValueError, newiter, [a,a], [], [['readonly']]*2, + assert_raises(ValueError, nditer, [a,a], [], [['readonly']]*2, op_axes=[[0,1],[0,1,0]]) # Non-broadcastable dimensions in the result - assert_raises(ValueError, newiter, [a,a], [], [['readonly']]*2, + assert_raises(ValueError, nditer, [a,a], [], [['readonly']]*2, op_axes=[[0,1],[1,0]]) def test_iter_copy(): @@ -1151,7 +1151,7 @@ def test_iter_copy(): a = arange(24).reshape(2,3,4) # Simple iterator - i = newiter(a) + i = nditer(a) j = i.copy() assert_equal([x[()] for x in i], [x[()] for x in j]) @@ -1160,7 +1160,7 @@ def test_iter_copy(): assert_equal([x[()] for x in i], [x[()] for x in j]) # Buffered iterator - i = newiter(a, ['buffered','ranged'], order='F', buffersize=3) + i = nditer(a, ['buffered','ranged'], order='F', buffersize=3) j = i.copy() assert_equal([x[()] for x in i], [x[()] for x in j]) @@ -1178,14 +1178,14 @@ def test_iter_copy(): assert_equal([x[()] for x in i], [x[()] for x in j]) # Casting iterator - i = newiter(a, ['buffered'], order='F', casting='unsafe', + i = nditer(a, ['buffered'], order='F', casting='unsafe', op_dtypes='f8', buffersize=5) j = i.copy() i = None assert_equal([x[()] for x in j], a.ravel(order='F')) a = arange(24, dtype='<i4').reshape(2,3,4) - i = newiter(a, ['buffered'], order='F', casting='unsafe', + i = nditer(a, ['buffered'], order='F', casting='unsafe', op_dtypes='>f8', buffersize=5) j = i.copy() i = None @@ -1196,7 +1196,7 @@ def test_iter_allocate_output_simple(): # Simple case a = arange(6) - i = newiter([a,None], [], [['readonly'],['writeonly','allocate']], + i = nditer([a,None], [], [['readonly'],['writeonly','allocate']], op_dtypes=[None,np.dtype('f4')]) assert_equal(i.operands[1].shape, a.shape) assert_equal(i.operands[1].dtype, np.dtype('f4')) @@ -1205,7 +1205,7 @@ def test_iter_allocate_output_buffered_readwrite(): # Allocated output with buffering + delay_bufalloc a = arange(6) - i = newiter([a,None], ['buffered','delay_bufalloc'], + i = nditer([a,None], ['buffered','delay_bufalloc'], [['readonly'],['allocate','readwrite']]) i.operands[1][:] = 1 i.reset() @@ -1218,21 +1218,21 @@ def test_iter_allocate_output_itorder(): # C-order input, best iteration order a = arange(6, dtype='i4').reshape(2,3) - i = newiter([a,None], [], [['readonly'],['writeonly','allocate']], + i = nditer([a,None], [], [['readonly'],['writeonly','allocate']], op_dtypes=[None,np.dtype('f4')]) assert_equal(i.operands[1].shape, a.shape) assert_equal(i.operands[1].strides, a.strides) assert_equal(i.operands[1].dtype, np.dtype('f4')) # F-order input, best iteration order a = arange(24, dtype='i4').reshape(2,3,4).T - i = newiter([a,None], [], [['readonly'],['writeonly','allocate']], + i = nditer([a,None], [], [['readonly'],['writeonly','allocate']], op_dtypes=[None,np.dtype('f4')]) assert_equal(i.operands[1].shape, a.shape) assert_equal(i.operands[1].strides, a.strides) assert_equal(i.operands[1].dtype, np.dtype('f4')) # Non-contiguous input, C iteration order a = arange(24, dtype='i4').reshape(2,3,4).swapaxes(0,1) - i = newiter([a,None], [], + i = nditer([a,None], [], [['readonly'],['writeonly','allocate']], order='C', op_dtypes=[None,np.dtype('f4')]) @@ -1244,7 +1244,7 @@ def test_iter_allocate_output_opaxes(): # Specifing op_axes should work a = arange(24, dtype='i4').reshape(2,3,4) - i = newiter([None,a], [], [['writeonly','allocate'],['readonly']], + i = nditer([None,a], [], [['writeonly','allocate'],['readonly']], op_dtypes=[np.dtype('u4'),None], op_axes=[[1,2,0],None]); assert_equal(i.operands[0].shape, (4,2,3)) @@ -1254,19 +1254,19 @@ def test_iter_allocate_output_opaxes(): def test_iter_allocate_output_types_promotion(): # Check type promotion of automatic outputs - i = newiter([array([3],dtype='f4'),array([0],dtype='f8'),None], [], + i = nditer([array([3],dtype='f4'),array([0],dtype='f8'),None], [], [['readonly']]*2+[['writeonly','allocate']]) assert_equal(i.dtypes[2], np.dtype('f8')); - i = newiter([array([3],dtype='i4'),array([0],dtype='f4'),None], [], + i = nditer([array([3],dtype='i4'),array([0],dtype='f4'),None], [], [['readonly']]*2+[['writeonly','allocate']]) assert_equal(i.dtypes[2], np.dtype('f8')); - i = newiter([array([3],dtype='f4'),array(0,dtype='f8'),None], [], + i = nditer([array([3],dtype='f4'),array(0,dtype='f8'),None], [], [['readonly']]*2+[['writeonly','allocate']]) assert_equal(i.dtypes[2], np.dtype('f4')); - i = newiter([array([3],dtype='u4'),array(0,dtype='i4'),None], [], + i = nditer([array([3],dtype='u4'),array(0,dtype='i4'),None], [], [['readonly']]*2+[['writeonly','allocate']]) assert_equal(i.dtypes[2], np.dtype('u4')); - i = newiter([array([3],dtype='u4'),array(-12,dtype='i4'),None], [], + i = nditer([array([3],dtype='u4'),array(-12,dtype='i4'),None], [], [['readonly']]*2+[['writeonly','allocate']]) assert_equal(i.dtypes[2], np.dtype('i8')); @@ -1275,11 +1275,11 @@ def test_iter_allocate_output_types_byte_order(): # When there's just one input, the output type exactly matches a = array([3],dtype='u4').newbyteorder() - i = newiter([a,None], [], + i = nditer([a,None], [], [['readonly'],['writeonly','allocate']]) assert_equal(i.dtypes[0], i.dtypes[1]); # With two or more inputs, the output type is in native byte order - i = newiter([a,a,None], [], + i = nditer([a,a,None], [], [['readonly'],['readonly'],['writeonly','allocate']]) assert_(i.dtypes[0] != i.dtypes[2]); assert_equal(i.dtypes[0].newbyteorder('='), i.dtypes[2]) @@ -1287,7 +1287,7 @@ def test_iter_allocate_output_types_byte_order(): def test_iter_allocate_output_types_scalar(): # If the inputs are all scalars, the output should be a scalar - i = newiter([None,1,2.3,np.float32(12),np.complex128(3)],[], + i = nditer([None,1,2.3,np.float32(12),np.complex128(3)],[], [['writeonly','allocate']] + [['readonly']]*4) assert_equal(i.operands[0].dtype, np.dtype('complex128')) assert_equal(i.operands[0].ndim, 0) @@ -1298,7 +1298,7 @@ def test_iter_allocate_output_subtype(): # matrix vs ndarray a = np.matrix([[1,2], [3,4]]) b = np.arange(4).reshape(2,2).T - i = newiter([a,b,None], [], + i = nditer([a,b,None], [], [['readonly'],['readonly'],['writeonly','allocate']]) assert_equal(type(a), type(i.operands[2])) assert_(type(b) != type(i.operands[2])) @@ -1306,10 +1306,10 @@ def test_iter_allocate_output_subtype(): # matrix always wants things to be 2D b = np.arange(4).reshape(1,2,2) - assert_raises(RuntimeError, newiter, [a,b,None], [], + assert_raises(RuntimeError, nditer, [a,b,None], [], [['readonly'],['readonly'],['writeonly','allocate']]) # but if subtypes are disabled, the result can still work - i = newiter([a,b,None], [], + i = nditer([a,b,None], [], [['readonly'],['readonly'],['writeonly','allocate','no_subtype']]) assert_equal(type(b), type(i.operands[2])) assert_(type(a) != type(i.operands[2])) @@ -1320,32 +1320,32 @@ def test_iter_allocate_output_errors(): # Need an input if no output data type is specified a = arange(6) - assert_raises(TypeError, newiter, [a,None], [], + assert_raises(TypeError, nditer, [a,None], [], [['writeonly'],['writeonly','allocate']]) # Allocated output should be flagged for writing - assert_raises(ValueError, newiter, [a,None], [], + assert_raises(ValueError, nditer, [a,None], [], [['readonly'],['allocate','readonly']]) # Allocated output can't have buffering without delayed bufalloc - assert_raises(ValueError, newiter, [a,None], ['buffered'], + assert_raises(ValueError, nditer, [a,None], ['buffered'], ['allocate','readwrite']) # Must specify at least one input - assert_raises(ValueError, newiter, [None,None], [], + assert_raises(ValueError, nditer, [None,None], [], [['writeonly','allocate'], ['writeonly','allocate']], op_dtypes=[np.dtype('f4'),np.dtype('f4')]) # If using op_axes, must specify all the axes a = arange(24, dtype='i4').reshape(2,3,4) - assert_raises(ValueError, newiter, [a,None], [], + assert_raises(ValueError, nditer, [a,None], [], [['readonly'],['writeonly','allocate']], op_dtypes=[None,np.dtype('f4')], op_axes=[None,[0,np.newaxis,1]]) # If using op_axes, the axes must be within bounds - assert_raises(ValueError, newiter, [a,None], [], + assert_raises(ValueError, nditer, [a,None], [], [['readonly'],['writeonly','allocate']], op_dtypes=[None,np.dtype('f4')], op_axes=[None,[0,3,1]]) # If using op_axes, there can't be duplicates - assert_raises(ValueError, newiter, [a,None], [], + assert_raises(ValueError, nditer, [a,None], [], [['readonly'],['writeonly','allocate']], op_dtypes=[None,np.dtype('f4')], op_axes=[None,[0,2,1,0]]) @@ -1353,12 +1353,12 @@ def test_iter_allocate_output_errors(): def test_iter_remove_axis(): a = arange(24).reshape(2,3,4) - i = newiter(a,['coords']) + i = nditer(a,['coords']) i.remove_axis(1) assert_equal([x for x in i], a[:,0,:].ravel()) a = a[::-1,:,:] - i = newiter(a,['coords']) + i = nditer(a,['coords']) i.remove_axis(0) assert_equal([x for x in i], a[0,:,:].ravel()) @@ -1367,7 +1367,7 @@ def test_iter_remove_coords_inner_loop(): a = arange(24).reshape(2,3,4) - i = newiter(a,['coords']) + i = nditer(a,['coords']) assert_equal(i.ndim, 3) assert_equal(i.shape, (2,3,4)) assert_equal(i.itviews[0].shape, (2,3,4)) @@ -1397,27 +1397,27 @@ def test_iter_iterindex(): buffersize = 5 a = arange(24).reshape(4,3,2) for flags in ([], ['buffered']): - i = newiter(a, flags, buffersize=buffersize) + i = nditer(a, flags, buffersize=buffersize) assert_equal(iter_iterindices(i), range(24)) i.iterindex = 2 assert_equal(iter_iterindices(i), range(2,24)) - i = newiter(a, flags, order='F', buffersize=buffersize) + i = nditer(a, flags, order='F', buffersize=buffersize) assert_equal(iter_iterindices(i), range(24)) i.iterindex = 5 assert_equal(iter_iterindices(i), range(5,24)) - i = newiter(a[::-1], flags, order='F', buffersize=buffersize) + i = nditer(a[::-1], flags, order='F', buffersize=buffersize) assert_equal(iter_iterindices(i), range(24)) i.iterindex = 9 assert_equal(iter_iterindices(i), range(9,24)) - i = newiter(a[::-1,::-1], flags, order='C', buffersize=buffersize) + i = nditer(a[::-1,::-1], flags, order='C', buffersize=buffersize) assert_equal(iter_iterindices(i), range(24)) i.iterindex = 13 assert_equal(iter_iterindices(i), range(13,24)) - i = newiter(a[::1,::-1], flags, buffersize=buffersize) + i = nditer(a[::1,::-1], flags, buffersize=buffersize) assert_equal(iter_iterindices(i), range(24)) i.iterindex = 23 assert_equal(iter_iterindices(i), range(23,24)) @@ -1432,7 +1432,7 @@ def test_iter_iterrange(): a = arange(24, dtype='i4').reshape(4,3,2) a_fort = a.ravel(order='F') - i = newiter(a, ['ranged'], ['readonly'], order='F', + i = nditer(a, ['ranged'], ['readonly'], order='F', buffersize=buffersize) assert_equal(i.iterrange, (0,24)) assert_equal([x[()] for x in i], a_fort) @@ -1441,7 +1441,7 @@ def test_iter_iterrange(): assert_equal(i.iterrange, r) assert_equal([x[()] for x in i], a_fort[r[0]:r[1]]) - i = newiter(a, ['ranged','buffered'], ['readonly'], order='F', + i = nditer(a, ['ranged','buffered'], ['readonly'], order='F', op_dtypes='f8', buffersize=buffersize) assert_equal(i.iterrange, (0,24)) assert_equal([x[()] for x in i], a_fort) @@ -1456,7 +1456,7 @@ def test_iter_iterrange(): val = np.concatenate((val, x)) return val - i = newiter(a, ['ranged','buffered','no_inner_iteration'], + i = nditer(a, ['ranged','buffered','no_inner_iteration'], ['readonly'], order='F', op_dtypes='f8', buffersize=buffersize) assert_equal(i.iterrange, (0,24)) @@ -1484,7 +1484,7 @@ def test_iter_buffering(): for a in arrays: for buffersize in (1,2,3,5,8,11,16,1024): vals = [] - i = newiter(a, ['buffered','no_inner_iteration'], + i = nditer(a, ['buffered','no_inner_iteration'], [['readonly','nbo','aligned']], order='C', casting='equiv', @@ -1500,7 +1500,7 @@ def test_iter_write_buffering(): # F-order swapped array a = np.arange(24).reshape(2,3,4).T.newbyteorder().byteswap() - i = newiter(a, ['buffered'], + i = nditer(a, ['buffered'], [['readwrite','nbo','aligned']], casting='equiv', order='C', @@ -1517,7 +1517,7 @@ def test_iter_buffering_delayed_alloc(): a = np.arange(6) b = np.arange(1, dtype='f4') - i = newiter([a,b], ['buffered','delay_bufalloc','coords','reduce_ok'], + i = nditer([a,b], ['buffered','delay_bufalloc','coords','reduce_ok'], ['readwrite'], casting='unsafe', op_dtypes='f4') @@ -1541,7 +1541,7 @@ def test_iter_buffered_cast_simple(): # Test that buffering can handle a simple cast a = np.arange(10, dtype='f4') - i = newiter(a, ['buffered','no_inner_iteration'], + i = nditer(a, ['buffered','no_inner_iteration'], [['readwrite','nbo','aligned']], casting='same_kind', op_dtypes=[np.dtype('f8')], @@ -1555,7 +1555,7 @@ def test_iter_buffered_cast_byteswapped(): # Test that buffering can handle a cast which requires swap->cast->swap a = np.arange(10, dtype='f4').newbyteorder().byteswap() - i = newiter(a, ['buffered','no_inner_iteration'], + i = nditer(a, ['buffered','no_inner_iteration'], [['readwrite','nbo','aligned']], casting='same_kind', op_dtypes=[np.dtype('f8').newbyteorder()], @@ -1569,7 +1569,7 @@ def test_iter_buffered_cast_byteswapped(): warnings.simplefilter("ignore", np.ComplexWarning) a = np.arange(10, dtype='f8').newbyteorder().byteswap() - i = newiter(a, ['buffered','no_inner_iteration'], + i = nditer(a, ['buffered','no_inner_iteration'], [['readwrite','nbo','aligned']], casting='unsafe', op_dtypes=[np.dtype('c8').newbyteorder()], @@ -1586,7 +1586,7 @@ def test_iter_buffered_cast_byteswapped_complex(): a = np.arange(10, dtype='c8').newbyteorder().byteswap() a += 2j - i = newiter(a, ['buffered','no_inner_iteration'], + i = nditer(a, ['buffered','no_inner_iteration'], [['readwrite','nbo','aligned']], casting='same_kind', op_dtypes=[np.dtype('c16')], @@ -1597,7 +1597,7 @@ def test_iter_buffered_cast_byteswapped_complex(): a = np.arange(10, dtype='c8') a += 2j - i = newiter(a, ['buffered','no_inner_iteration'], + i = nditer(a, ['buffered','no_inner_iteration'], [['readwrite','nbo','aligned']], casting='same_kind', op_dtypes=[np.dtype('c16').newbyteorder()], @@ -1608,7 +1608,7 @@ def test_iter_buffered_cast_byteswapped_complex(): a = np.arange(10, dtype=np.clongdouble).newbyteorder().byteswap() a += 2j - i = newiter(a, ['buffered','no_inner_iteration'], + i = nditer(a, ['buffered','no_inner_iteration'], [['readwrite','nbo','aligned']], casting='same_kind', op_dtypes=[np.dtype('c16')], @@ -1618,7 +1618,7 @@ def test_iter_buffered_cast_byteswapped_complex(): assert_equal(a, 2*np.arange(10, dtype=np.clongdouble) + 4j) a = np.arange(10, dtype=np.longdouble).newbyteorder().byteswap() - i = newiter(a, ['buffered','no_inner_iteration'], + i = nditer(a, ['buffered','no_inner_iteration'], [['readwrite','nbo','aligned']], casting='same_kind', op_dtypes=[np.dtype('f4')], @@ -1633,7 +1633,7 @@ def test_iter_buffered_cast_structured_type(): # simple -> struct type (duplicates the value) sdt = [('a', 'f4'), ('b', 'i8'), ('c', 'c8', (2,3)), ('d', 'O')] a = np.arange(3, dtype='f4') + 0.5 - i = newiter(a, ['buffered','refs_ok'], ['readonly'], + i = nditer(a, ['buffered','refs_ok'], ['readonly'], casting='unsafe', op_dtypes=sdt) vals = [np.array(x) for x in i] @@ -1651,7 +1651,7 @@ def test_iter_buffered_cast_structured_type(): sdt = [('a', 'f4'), ('b', 'i8'), ('c', 'c8', (2,3)), ('d', 'O')] a = np.arange(3, dtype='O') + 0.5 rc = sys.getrefcount(a[0]) - i = newiter(a, ['buffered','refs_ok'], ['readonly'], + i = nditer(a, ['buffered','refs_ok'], ['readonly'], casting='unsafe', op_dtypes=sdt) vals = [np.array(x) for x in i] @@ -1670,7 +1670,7 @@ def test_iter_buffered_cast_structured_type(): # struct type -> simple (takes the first value) sdt = [('a', 'f4'), ('b', 'i8'), ('d', 'O')] a = np.array([(5.5,7,'test'),(8,10,11)], dtype=sdt) - i = newiter(a, ['buffered','refs_ok'], ['readonly'], + i = nditer(a, ['buffered','refs_ok'], ['readonly'], casting='unsafe', op_dtypes='i4') assert_equal([x[()] for x in i], [5, 8]) @@ -1679,7 +1679,7 @@ def test_iter_buffered_cast_structured_type(): sdt1 = [('a', 'f4'), ('b', 'i8'), ('d', 'O')] sdt2 = [('d', 'u2'), ('a', 'O'), ('b', 'f8')] a = np.array([(1,2,3),(4,5,6)], dtype=sdt1) - i = newiter(a, ['buffered','refs_ok'], ['readonly'], + i = nditer(a, ['buffered','refs_ok'], ['readonly'], casting='unsafe', op_dtypes=sdt2) assert_equal(i[0].dtype, np.dtype(sdt2)) @@ -1691,7 +1691,7 @@ def test_iter_buffered_cast_structured_type(): sdt1 = [('a', 'f4'), ('b', 'i8'), ('d', 'O')] sdt2 = [('b', 'O'), ('a', 'f8')] a = np.array([(1,2,3),(4,5,6)], dtype=sdt1) - i = newiter(a, ['buffered','refs_ok'], ['readwrite'], + i = nditer(a, ['buffered','refs_ok'], ['readwrite'], casting='unsafe', op_dtypes=sdt2) assert_equal(i[0].dtype, np.dtype(sdt2)) @@ -1707,7 +1707,7 @@ def test_iter_buffered_cast_structured_type(): sdt1 = [('a', 'f4'), ('b', 'i8'), ('d', [('a', 'i2'),('b','i4')])] sdt2 = [('b', 'O'), ('a', 'f8')] a = np.array([(1,2,(0,9)),(4,5,(20,21))], dtype=sdt1) - i = newiter(a, ['buffered','refs_ok'], ['readwrite'], + i = nditer(a, ['buffered','refs_ok'], ['readwrite'], casting='unsafe', op_dtypes=sdt2) assert_equal(i[0].dtype, np.dtype(sdt2)) @@ -1723,7 +1723,7 @@ def test_iter_buffered_cast_structured_type(): sdt1 = [('a', 'f4'), ('b', 'i8'), ('d', [('a', 'i2'),('b','O')])] sdt2 = [('b', 'O'), ('a', 'f8')] a = np.array([(1,2,(0,9)),(4,5,(20,21))], dtype=sdt1) - i = newiter(a, ['buffered','refs_ok'], ['readwrite'], + i = nditer(a, ['buffered','refs_ok'], ['readwrite'], casting='unsafe', op_dtypes=sdt2) assert_equal(i[0].dtype, np.dtype(sdt2)) @@ -1739,7 +1739,7 @@ def test_iter_buffered_cast_structured_type(): sdt1 = [('b', 'O'), ('a', 'f8')] sdt2 = [('a', 'f4'), ('b', 'i8'), ('d', [('a', 'i2'),('b','O')])] a = np.array([(1,2),(4,5)], dtype=sdt1) - i = newiter(a, ['buffered','refs_ok'], ['readwrite'], + i = nditer(a, ['buffered','refs_ok'], ['readwrite'], casting='unsafe', op_dtypes=sdt2) assert_equal(i[0].dtype, np.dtype(sdt2)) @@ -1760,7 +1760,7 @@ def test_iter_buffered_cast_subarray(): sdt2 = [('a', 'f8', (3,2,2))] a = np.zeros((6,), dtype=sdt1) a['a'] = np.arange(6) - i = newiter(a, ['buffered','refs_ok'], ['readonly'], + i = nditer(a, ['buffered','refs_ok'], ['readonly'], casting='unsafe', op_dtypes=sdt2) assert_equal(i[0].dtype, np.dtype(sdt2)) @@ -1772,7 +1772,7 @@ def test_iter_buffered_cast_subarray(): sdt2 = [('a', 'O', (3,2,2))] a = np.zeros((6,), dtype=sdt1) a['a'][:,0,0] = np.arange(6) - i = newiter(a, ['buffered','refs_ok'], ['readwrite'], + i = nditer(a, ['buffered','refs_ok'], ['readwrite'], casting='unsafe', op_dtypes=sdt2) assert_equal(i[0].dtype, np.dtype(sdt2)) @@ -1788,7 +1788,7 @@ def test_iter_buffered_cast_subarray(): sdt2 = [('a', 'O', (1,))] a = np.zeros((6,), dtype=sdt1) a['a'][:,0,0,0] = np.arange(6) - i = newiter(a, ['buffered','refs_ok'], ['readwrite'], + i = nditer(a, ['buffered','refs_ok'], ['readwrite'], casting='unsafe', op_dtypes=sdt2) assert_equal(i[0].dtype, np.dtype(sdt2)) @@ -1804,7 +1804,7 @@ def test_iter_buffered_cast_subarray(): sdt2 = [('a', 'O', (1,))] a = np.zeros((6,), dtype=sdt1) a['a'][:,0,0,0] = np.arange(6) - i = newiter(a, ['buffered','refs_ok'], ['readonly'], + i = nditer(a, ['buffered','refs_ok'], ['readonly'], casting='unsafe', op_dtypes=sdt2) assert_equal(i[0].dtype, np.dtype(sdt2)) @@ -1818,7 +1818,7 @@ def test_iter_buffered_cast_subarray(): sdt2 = [('a', 'f4', (1,))] a = np.zeros((6,), dtype=sdt1) a['a'][:,0,0,0] = np.arange(6) - i = newiter(a, ['buffered','refs_ok'], ['readonly'], + i = nditer(a, ['buffered','refs_ok'], ['readonly'], casting='unsafe', op_dtypes=sdt2) assert_equal(i[0].dtype, np.dtype(sdt2)) @@ -1832,7 +1832,7 @@ def test_iter_buffered_cast_subarray(): sdt2 = [('a', 'f4', (3,2,2))] a = np.zeros((6,), dtype=sdt1) a['a'] = np.arange(6*3*2*2).reshape(6,3,2,2) - i = newiter(a, ['buffered','refs_ok'], ['readonly'], + i = nditer(a, ['buffered','refs_ok'], ['readonly'], casting='unsafe', op_dtypes=sdt2) assert_equal(i[0].dtype, np.dtype(sdt2)) @@ -1846,7 +1846,7 @@ def test_iter_buffered_cast_subarray(): sdt2 = [('a', 'f4', (2,))] a = np.zeros((6,), dtype=sdt1) a['a'] = np.arange(6*6).reshape(6,6) - i = newiter(a, ['buffered','refs_ok'], ['readonly'], + i = nditer(a, ['buffered','refs_ok'], ['readonly'], casting='unsafe', op_dtypes=sdt2) assert_equal(i[0].dtype, np.dtype(sdt2)) @@ -1860,7 +1860,7 @@ def test_iter_buffered_cast_subarray(): sdt2 = [('a', 'f4', (6,))] a = np.zeros((6,), dtype=sdt1) a['a'] = np.arange(6*2).reshape(6,2) - i = newiter(a, ['buffered','refs_ok'], ['readonly'], + i = nditer(a, ['buffered','refs_ok'], ['readonly'], casting='unsafe', op_dtypes=sdt2) assert_equal(i[0].dtype, np.dtype(sdt2)) @@ -1875,7 +1875,7 @@ def test_iter_buffered_cast_subarray(): sdt2 = [('a', 'f4', (2,2))] a = np.zeros((6,), dtype=sdt1) a['a'] = np.arange(6*2).reshape(6,2) - i = newiter(a, ['buffered','refs_ok'], ['readonly'], + i = nditer(a, ['buffered','refs_ok'], ['readonly'], casting='unsafe', op_dtypes=sdt2) assert_equal(i[0].dtype, np.dtype(sdt2)) @@ -1890,7 +1890,7 @@ def test_iter_buffered_cast_subarray(): sdt2 = [('a', 'f4', (3,2))] a = np.zeros((6,), dtype=sdt1) a['a'] = np.arange(6*2).reshape(6,2,1) - i = newiter(a, ['buffered','refs_ok'], ['readonly'], + i = nditer(a, ['buffered','refs_ok'], ['readonly'], casting='unsafe', op_dtypes=sdt2) assert_equal(i[0].dtype, np.dtype(sdt2)) @@ -1906,7 +1906,7 @@ def test_iter_buffered_cast_subarray(): sdt2 = [('a', 'f4', (3,2))] a = np.zeros((6,), dtype=sdt1) a['a'] = np.arange(6*2*3).reshape(6,2,3) - i = newiter(a, ['buffered','refs_ok'], ['readonly'], + i = nditer(a, ['buffered','refs_ok'], ['readonly'], casting='unsafe', op_dtypes=sdt2) assert_equal(i[0].dtype, np.dtype(sdt2)) @@ -1923,30 +1923,30 @@ def test_iter_buffering_badwriteback(): # a needs write buffering, but had a broadcast dimension a = np.arange(6).reshape(2,3,1) b = np.arange(12).reshape(2,3,2) - assert_raises(ValueError,newiter,[a,b], + assert_raises(ValueError,nditer,[a,b], ['buffered','no_inner_iteration'], [['readwrite'],['writeonly']], order='C') # But if a is readonly, it's fine - i = newiter([a,b],['buffered','no_inner_iteration'], + i = nditer([a,b],['buffered','no_inner_iteration'], [['readonly'],['writeonly']], order='C') # If a has just one element, it's fine too (constant 0 stride, a reduction) a = np.arange(1).reshape(1,1,1) - i = newiter([a,b],['buffered','no_inner_iteration','reduce_ok'], + i = nditer([a,b],['buffered','no_inner_iteration','reduce_ok'], [['readwrite'],['writeonly']], order='C') # check that it fails on other dimensions too a = np.arange(6).reshape(1,3,2) - assert_raises(ValueError,newiter,[a,b], + assert_raises(ValueError,nditer,[a,b], ['buffered','no_inner_iteration'], [['readwrite'],['writeonly']], order='C') a = np.arange(4).reshape(2,1,2) - assert_raises(ValueError,newiter,[a,b], + assert_raises(ValueError,nditer,[a,b], ['buffered','no_inner_iteration'], [['readwrite'],['writeonly']], order='C') @@ -1955,24 +1955,24 @@ def test_iter_buffering_string(): # Safe casting disallows shrinking strings a = np.array(['abc', 'a', 'abcd'], dtype=np.bytes_) assert_equal(a.dtype, np.dtype('S4')); - assert_raises(TypeError,newiter,a,['buffered'],['readonly'], + assert_raises(TypeError,nditer,a,['buffered'],['readonly'], op_dtypes='S2') - i = newiter(a, ['buffered'], ['readonly'], op_dtypes='S6') + i = nditer(a, ['buffered'], ['readonly'], op_dtypes='S6') assert_equal(i[0], asbytes('abc')) assert_equal(i[0].dtype, np.dtype('S6')) a = np.array(['abc', 'a', 'abcd'], dtype=np.unicode) assert_equal(a.dtype, np.dtype('U4')); - assert_raises(TypeError,newiter,a,['buffered'],['readonly'], + assert_raises(TypeError,nditer,a,['buffered'],['readonly'], op_dtypes='U2') - i = newiter(a, ['buffered'], ['readonly'], op_dtypes='U6') + i = nditer(a, ['buffered'], ['readonly'], op_dtypes='U6') assert_equal(i[0], u'abc') assert_equal(i[0].dtype, np.dtype('U6')) def test_iter_buffering_growinner(): # Test that the inner loop grows when no buffering is needed a = np.arange(30) - i = newiter(a, ['buffered','growinner','no_inner_iteration'], + i = nditer(a, ['buffered','growinner','no_inner_iteration'], buffersize=5) # Should end up with just one inner loop here assert_equal(i[0].size, a.size) @@ -1983,11 +1983,11 @@ def test_iter_no_broadcast(): b = np.arange(6).reshape(2,3,1) c = np.arange(12).reshape(3,4) - i = newiter([a,b,c], [], + i = nditer([a,b,c], [], [['readonly','no_broadcast'],['readonly'],['readonly']]) - assert_raises(ValueError, newiter, [a,b,c], [], + assert_raises(ValueError, nditer, [a,b,c], [], [['readonly'],['readonly','no_broadcast'],['readonly']]) - assert_raises(ValueError, newiter, [a,b,c], [], + assert_raises(ValueError, nditer, [a,b,c], [], [['readonly'],['readonly'],['readonly','no_broadcast']]) def test_iter_nested_iters_basic(): @@ -2160,12 +2160,12 @@ def test_iter_nested_iters_dtype_buffered(): def test_iter_reduction_error(): a = np.arange(6) - assert_raises(ValueError, newiter, [a,None], [], + assert_raises(ValueError, nditer, [a,None], [], [['readonly'], ['readwrite','allocate']], op_axes=[[0],[-1]]) a = np.arange(6).reshape(2,3) - assert_raises(ValueError, newiter, [a,None], ['no_inner_iteration'], + assert_raises(ValueError, nditer, [a,None], ['no_inner_iteration'], [['readonly'], ['readwrite','allocate']], op_axes=[[0,1],[-1,-1]]) @@ -2173,7 +2173,7 @@ def test_iter_reduction(): # Test doing reductions with the iterator a = np.arange(6) - i = newiter([a,None], ['reduce_ok'], + i = nditer([a,None], ['reduce_ok'], [['readonly'], ['readwrite','allocate']], op_axes=[[0],[-1]]) # Need to initialize the output operand to the addition unit @@ -2186,7 +2186,7 @@ def test_iter_reduction(): assert_equal(i.operands[1], np.sum(a)) a = np.arange(6).reshape(2,3) - i = newiter([a,None], ['reduce_ok','no_inner_iteration'], + i = nditer([a,None], ['reduce_ok','no_inner_iteration'], [['readonly'], ['readwrite','allocate']], op_axes=[[0,1],[-1,-1]]) # Need to initialize the output operand to the addition unit @@ -2207,7 +2207,7 @@ def test_iter_buffering_reduction(): a = np.arange(6) b = np.array(0., dtype='f8').byteswap().newbyteorder() - i = newiter([a,b], ['reduce_ok', 'buffered'], + i = nditer([a,b], ['reduce_ok', 'buffered'], [['readonly'], ['readwrite','nbo']], op_axes=[[0],[-1]]) assert_equal(i[1].dtype, np.dtype('f8')) @@ -2220,7 +2220,7 @@ def test_iter_buffering_reduction(): a = np.arange(6).reshape(2,3) b = np.array([0,0], dtype='f8').byteswap().newbyteorder() - i = newiter([a,b], ['reduce_ok','no_inner_iteration', 'buffered'], + i = nditer([a,b], ['reduce_ok','no_inner_iteration', 'buffered'], [['readonly'], ['readwrite','nbo']], op_axes=[[0,1],[0,-1]]) # Reduction shape/strides for the output |