Author: Brian Kearns <[email protected]>
Branch: 
Changeset: r61749:7551c6b88bb8
Date: 2013-02-25 00:52 -0500
http://bitbucket.org/pypy/pypy/changeset/7551c6b88bb8/

Log:    move some numpypy constants to the umath module

diff --git a/lib_pypy/numpypy/core/__init__.py 
b/lib_pypy/numpypy/core/__init__.py
--- a/lib_pypy/numpypy/core/__init__.py
+++ b/lib_pypy/numpypy/core/__init__.py
@@ -6,7 +6,6 @@
 from fromnumeric import *
 import shape_base
 from shape_base import *
-import multiarray
 
 from fromnumeric import amax as max, amin as min
 from _numpypy import absolute as abs
diff --git a/lib_pypy/numpypy/core/numeric.py b/lib_pypy/numpypy/core/numeric.py
--- a/lib_pypy/numpypy/core/numeric.py
+++ b/lib_pypy/numpypy/core/numeric.py
@@ -1,15 +1,33 @@
-__all__ = ['asanyarray', 'base_repr',
+__all__ = [
+           'asanyarray', 'base_repr',
            'array_repr', 'array_str', 'set_string_function',
-           'array_equal', 'asarray', 'outer', 'identity']
+           'array_equal', 'asarray', 'outer', 'identity', 'little_endian',
+           'Inf', 'inf', 'infty', 'Infinity', 'nan', 'NaN', 'False_', 'True_',
+          ]
 
 from _numpypy import array, ndarray, int_, float_, bool_, flexible #, 
complex_# , longlong
 from _numpypy import concatenate
 from .fromnumeric import any
-import math
 import sys
 import multiarray
+import umath
+from umath import *
 from numpypy.core.arrayprint import array2string
 
+def extend_all(module):
+    adict = {}
+    for a in __all__:
+        adict[a] = 1
+    try:
+        mall = getattr(module, '__all__')
+    except AttributeError:
+        mall = [k for k in module.__dict__.keys() if not k.startswith('_')]
+    for a in mall:
+        if a not in adict:
+            __all__.append(a)
+
+extend_all(umath)
+
 newaxis = None
 
 # XXX this file to be reviewed
@@ -422,15 +440,10 @@
 
 little_endian = (sys.byteorder == 'little')
 
-Inf = inf = infty = Infinity = PINF = float('inf')
-NINF = float('-inf')
-PZERO = 0.0
-NZERO = -0.0
-nan = NaN = NAN = float('nan')
+Inf = inf = infty = Infinity = PINF
+nan = NaN = NAN
 False_ = bool_(False)
 True_ = bool_(True)
-e = math.e
-pi = math.pi
 
 def outer(a,b):
     """
diff --git a/lib_pypy/numpypy/core/umath.py b/lib_pypy/numpypy/core/umath.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/numpypy/core/umath.py
@@ -0,0 +1,10 @@
+import math
+e = math.e
+pi = math.pi
+del math
+
+PZERO = 0.0
+NZERO = -0.0
+PINF = float('inf')
+NINF = float('-inf')
+NAN = float('nan')
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
@@ -23,10 +23,6 @@
         'count_nonzero': 'interp_arrayops.count_nonzero',
 
         'set_string_function': 'appbridge.set_string_function',
-
-        'True_': 'types.Bool.True',
-        'False_': 'types.Bool.False',
-
         'typeinfo': 'interp_dtype.get_dtype_cache(space).w_typeinfo',
 
         'generic': 'interp_boxes.W_GenericBox',
diff --git a/pypy/module/micronumpy/test/test_dtypes.py 
b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -80,7 +80,8 @@
         assert str(d) == "bool"
 
     def test_bool_array(self):
-        from _numpypy import array, False_, True_
+        from _numpypy import array
+        from numpypy import False_, True_
 
         a = array([0, 1, 2, 2.5], dtype='?')
         assert a[0] is False_
@@ -88,7 +89,8 @@
             assert a[i] is True_
 
     def test_copy_array_with_dtype(self):
-        from _numpypy import array, False_, longlong
+        from _numpypy import array, longlong
+        from numpypy import False_
 
         a = array([0, 1, 2, 3], dtype=long)
         # int on 64-bit, long in 32-bit
@@ -102,14 +104,16 @@
         assert b[0] is False_
 
     def test_zeros_bool(self):
-        from _numpypy import zeros, False_
+        from _numpypy import zeros
+        from numpypy import False_
 
         a = zeros(10, dtype=bool)
         for i in range(10):
             assert a[i] is False_
 
     def test_ones_bool(self):
-        from _numpypy import ones, True_
+        from _numpypy import ones
+        from numpypy import True_
 
         a = ones(10, dtype=bool)
         for i in range(10):
@@ -317,7 +321,7 @@
         assert int_(4) ** 2 == 16
 
     def test_bool(self):
-        import _numpypy as numpy
+        import numpypy as numpy
 
         assert numpy.bool_.mro() == [numpy.bool_, numpy.generic, object]
         assert numpy.bool_(3) is numpy.True_
@@ -634,7 +638,8 @@
 
     def test_operators(self):
         from operator import truediv
-        from _numpypy import float64, int_, True_, False_
+        from _numpypy import float64, int_
+        from numpypy import True_, False_
         assert 5 / int_(2) == int_(2)
         assert truediv(int_(3), int_(2)) == float64(1.5)
         assert truediv(3, int_(2)) == float64(1.5)
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
@@ -780,6 +780,7 @@
 
     def test_mul(self):
         import _numpypy
+        from numpypy import False_, True_
 
         a = _numpypy.array(range(5))
         b = a * a
@@ -790,9 +791,9 @@
         a = _numpypy.array(range(5), dtype=bool)
         b = a * a
         assert b.dtype is _numpypy.dtype(bool)
-        assert b[0] is _numpypy.False_
+        assert b[0] is False_
         for i in range(1, 5):
-            assert b[i] is _numpypy.True_
+            assert b[i] is True_
 
     def test_mul_constant(self):
         from _numpypy import array
diff --git a/pypy/module/test_lib_pypy/numpypy/test_numpy.py 
b/pypy/module/test_lib_pypy/numpypy/test_numpy.py
--- a/pypy/module/test_lib_pypy/numpypy/test_numpy.py
+++ b/pypy/module/test_lib_pypy/numpypy/test_numpy.py
@@ -53,3 +53,9 @@
         import numpypy
         assert numpypy.set_string_function is not \
                numpypy.core.multiarray.set_string_function
+
+    def test_constants(self):
+        import numpypy
+        assert numpypy.PZERO == numpypy.NZERO == 0.0
+        assert numpypy.inf is float('inf')
+        assert numpypy.nan is float('nan')
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to