[pypy-commit] pypy default: Merged numpy-pi-sum-min-max, adding numpypy.pi, .sum, .min, and .max

jterrace noreply at buildbot.pypy.org
Mon Dec 12 18:49:12 CET 2011


Author: Jeff Terrace <jterrace at gmail.com>
Branch: 
Changeset: r50436:863190739032
Date: 2011-12-12 12:43 -0500
http://bitbucket.org/pypy/pypy/changeset/863190739032/

Log:	Merged numpy-pi-sum-min-max, adding numpypy.pi, .sum, .min, and .max

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
@@ -79,8 +79,12 @@
     appleveldefs = {
         'average': 'app_numpy.average',
         'mean': 'app_numpy.mean',
+        'sum': 'app_numpy.sum',
+        'min': 'app_numpy.min',
+        'max': 'app_numpy.max',
         'inf': 'app_numpy.inf',
         'e': 'app_numpy.e',
+        'pi': 'app_numpy.pi',
         'arange': 'app_numpy.arange',
         'reshape': 'app_numpy.reshape',
     }
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
@@ -5,6 +5,7 @@
 
 inf = float("inf")
 e = math.e
+pi = math.pi
 
 
 def average(a):
@@ -18,6 +19,20 @@
         a = numpypy.array(a)
     return a.mean()
 
+def sum(a):
+    if not hasattr(a, "sum"):
+        a = numpypy.array(a)
+    return a.sum()
+
+def min(a):
+    if not hasattr(a, "min"):
+        a = numpypy.array(a)
+    return a.min()
+
+def max(a):
+    if not hasattr(a, "max"):
+        a = numpypy.array(a)
+    return a.max()
 
 def arange(start, stop=None, step=1, dtype=None):
     '''arange([start], stop[, step], dtype=None)
diff --git a/pypy/module/micronumpy/test/test_module.py b/pypy/module/micronumpy/test/test_module.py
--- a/pypy/module/micronumpy/test/test_module.py
+++ b/pypy/module/micronumpy/test/test_module.py
@@ -11,11 +11,28 @@
         from numpypy import array, average
         assert average(range(10)) == 4.5
         assert average(array(range(10))) == 4.5
+        
+    def test_sum(self):
+        from numpypy import array, sum
+        assert sum(range(10)) == 45
+        assert sum(array(range(10))) == 45
+
+    def test_min(self):
+        from numpypy import array, min
+        assert min(range(10)) == 0
+        assert min(array(range(10))) == 0
+        
+    def test_max(self):
+        from numpypy import array, max
+        assert max(range(10)) == 9
+        assert max(array(range(10))) == 9
 
     def test_constants(self):
         import math
-        from numpypy import inf, e
+        from numpypy import inf, e, pi
         assert type(inf) is float
         assert inf == float("inf")
         assert e == math.e
         assert type(e) is float
+        assert pi == math.pi
+        assert type(pi) is float


More information about the pypy-commit mailing list