[pypy-commit] pypy newindex: the name in numpy is actually newaxis -- make sure keywords make sense

MichaelBlume noreply at buildbot.pypy.org
Sat Mar 17 09:38:32 CET 2012


Author: Mike Blume <mike at loggly.com>
Branch: newindex
Changeset: r53754:dc7baf8b94ea
Date: 2012-03-14 16:35 -0700
http://bitbucket.org/pypy/pypy/changeset/dc7baf8b94ea/

Log:	the name in numpy is actually newaxis -- make sure keywords make
	sense

diff --git a/pypy/module/micronumpy/interp_iter.py b/pypy/module/micronumpy/interp_iter.py
--- a/pypy/module/micronumpy/interp_iter.py
+++ b/pypy/module/micronumpy/interp_iter.py
@@ -50,7 +50,7 @@
 # structures to describe slicing
 
 class Chunk(object):
-    ind_step = 1
+    axis_step = 1
     def __init__(self, start, stop, step, lgt):
         self.start = start
         self.stop = stop
@@ -65,12 +65,12 @@
         return 'Chunk(%d, %d, %d, %d)' % (self.start, self.stop, self.step,
                                           self.lgt)
 
-class NewIndexChunk(Chunk):
+class NewAxisChunk(Chunk):
     start = 0
     stop = 1
     step = 1
     lgt = 1
-    ind_step = 0
+    axis_step = 0
 
     def __init__(self):
         pass
diff --git a/pypy/module/micronumpy/interp_numarray.py b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -7,7 +7,7 @@
 from pypy.module.micronumpy.appbridge import get_appbridge_cache
 from pypy.module.micronumpy.dot import multidim_dot, match_dot_shapes
 from pypy.module.micronumpy.interp_iter import (ArrayIterator,
-    SkipLastAxisIterator, Chunk, NewIndexChunk, ViewIterator)
+    SkipLastAxisIterator, Chunk, NewAxisChunk, ViewIterator)
 from pypy.module.micronumpy.strides import (calculate_slice_strides,
     shape_agreement, find_shape_and_elems, get_shape_from_iterable,
     calc_new_strides, to_coords, enumerate_chunks)
@@ -351,12 +351,12 @@
             space.isinstance_w(w_idx, space.w_slice)):
             return [Chunk(*space.decode_index4(w_idx, self.shape[0]))]
         elif space.isinstance_w(w_idx, space.w_NoneType):
-            return [NewIndexChunk()]
+            return [NewAxisChunk()]
         result = []
         i = 0
         for w_item in space.fixedview(w_idx):
             if space.isinstance_w(w_item, space.w_NoneType):
-                result.append(NewIndexChunk())
+                result.append(NewAxisChunk())
             else:
                 result.append(Chunk(*space.decode_index4(w_item,
                                                          self.shape[i])))
diff --git a/pypy/module/micronumpy/strides.py b/pypy/module/micronumpy/strides.py
--- a/pypy/module/micronumpy/strides.py
+++ b/pypy/module/micronumpy/strides.py
@@ -5,7 +5,7 @@
     result = []
     i = -1
     for chunk in chunks:
-        i += chunk.ind_step
+        i += chunk.axis_step
         result.append((i, chunk))
     return result
 
diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -376,14 +376,14 @@
 
     def test_newindex(self):
         from _numpypy import array
-        newindex = None
+        from numpypy.core.numeric import newaxis
         a = array(range(5))
         b = array([range(5)])
-        assert (a[newindex] == b).all()
+        assert (a[newaxis] == b).all()
 
     def test_newindex_slice(self):
         from _numpypy import array
-        newindex = None
+        from numpypy.core.numeric import newaxis
 
         a = array(range(5))
         b = array(range(1,5))
@@ -391,8 +391,8 @@
         d = array([[x] for x in range(1,5)])
 
         assert (a[1:] == b).all()
-        assert (a[1:,newindex] == d).all()
-        assert (a[newindex,1:] == c).all()
+        assert (a[1:,newaxis] == d).all()
+        assert (a[newaxis,1:] == c).all()
 
     def test_scalar(self):
         from _numpypy import array, dtype


More information about the pypy-commit mailing list