[pypy-commit] pypy numpy-monkeyaround: test, implement arange

mattip noreply at buildbot.pypy.org
Mon Nov 21 05:18:07 CET 2011


Author: mattip
Branch: numpy-monkeyaround
Changeset: r49594:1ae3fd3bf105
Date: 2011-11-21 06:15 +0200
http://bitbucket.org/pypy/pypy/changeset/1ae3fd3bf105/

Log:	test, implement arange

diff --git a/pypy/module/micronumpy/__init__.py b/pypy/module/micronumpy/__init__.py
--- a/pypy/module/micronumpy/__init__.py
+++ b/pypy/module/micronumpy/__init__.py
@@ -57,4 +57,5 @@
         'mean': 'app_numpy.mean',
         'inf': 'app_numpy.inf',
         'e': 'app_numpy.e',
+        'arange' : 'app_numpy.arange',
     }
diff --git a/pypy/module/micronumpy/app_numpy.py b/pypy/module/micronumpy/app_numpy.py
--- a/pypy/module/micronumpy/app_numpy.py
+++ b/pypy/module/micronumpy/app_numpy.py
@@ -15,3 +15,24 @@
     if not hasattr(a, "mean"):
         a = numpypy.array(a)
     return a.mean()
+
+
+def arange(start, stop=None, step=1, dtype=None, maskna=False):
+    '''arange([start], stop[, step], dtype=None, maskna=False)
+    Generate values in the half-interval [start, stop). 
+    '''
+    if stop is None:
+        stop = start
+        start = 0
+    if maskna is not False:
+        raise ValueError,'Not Implemented'
+    if dtype is None:
+        test = numpypy.array([start,stop,step])
+        dtype = test.dtype
+    arr = numpypy.zeros(int(math.ceil((stop-start)/step)),dtype=dtype)
+    i = start
+    for j in range(arr.size):
+        arr[j] = i
+        j += 1
+        i += step
+    return arr
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
@@ -177,10 +177,10 @@
     def get_offset(self):
         return self.offset
 
-class BroadcastIterator(BaseIterator):
+class BroadcastIterator(ViewIterator):
     '''Like a view iterator, but will repeatedly access values
        for all iterations across a res_shape, folding the offset
-       using mod() arithmetic
+       by setting shards, backshards to 0
     '''
     def __init__(self, arr, res_shape):
         self.indices = [0] * len(res_shape)
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
@@ -1003,7 +1003,7 @@
 
 class AppTestRanges(BaseNumpyAppTest):
     def test_arange(self):
-        from numpypy import arange, array
+        from numpypy import arange, array, dtype
         a = arange(3)
         assert (a == [0, 1, 2]).all()
         assert a.dtype is dtype(int)


More information about the pypy-commit mailing list