[pypy-commit] pypy remove-numpypy: merge default

bdkearns noreply at buildbot.pypy.org
Wed Oct 30 02:50:27 CET 2013


Author: Brian Kearns <bdkearns at gmail.com>
Branch: remove-numpypy
Changeset: r67720:86fae1ee9645
Date: 2013-10-29 21:34 -0400
http://bitbucket.org/pypy/pypy/changeset/86fae1ee9645/

Log:	merge default

diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -34,7 +34,7 @@
         from pypy.module.micronumpy.interp_dtype import get_dtype_cache
         return get_dtype_cache(space).dtypes_by_name[name]
 
-    def new(space, w_subtype, w_value):
+    def new(space, w_subtype, w_value=None):
         dtype = _get_dtype(space)
         return dtype.itemtype.coerce_subtype(space, w_subtype, w_value)
 
diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -491,6 +491,7 @@
             char=NPY_BOOLLTR,
             w_box_type=space.gettypefor(interp_boxes.W_BoolBox),
             alternate_constructors=[space.w_bool],
+            aliases=['bool8'],
         )
         self.w_int8dtype = W_Dtype(
             types.Int8(),
@@ -498,7 +499,8 @@
             kind=NPY_SIGNEDLTR,
             name="int8",
             char=NPY_BYTELTR,
-            w_box_type=space.gettypefor(interp_boxes.W_Int8Box)
+            w_box_type=space.gettypefor(interp_boxes.W_Int8Box),
+            aliases=['byte'],
         )
         self.w_uint8dtype = W_Dtype(
             types.UInt8(),
@@ -507,6 +509,7 @@
             name="uint8",
             char=NPY_UBYTELTR,
             w_box_type=space.gettypefor(interp_boxes.W_UInt8Box),
+            aliases=['ubyte'],
         )
         self.w_int16dtype = W_Dtype(
             types.Int16(),
@@ -515,6 +518,7 @@
             name="int16",
             char=NPY_SHORTLTR,
             w_box_type=space.gettypefor(interp_boxes.W_Int16Box),
+            aliases=['short'],
         )
         self.w_uint16dtype = W_Dtype(
             types.UInt16(),
@@ -523,6 +527,7 @@
             name="uint16",
             char=NPY_USHORTLTR,
             w_box_type=space.gettypefor(interp_boxes.W_UInt16Box),
+            aliases=['ushort'],
         )
         self.w_int32dtype = W_Dtype(
             types.Int32(),
@@ -572,6 +577,7 @@
             char=NPY_LONGLONGLTR,
             w_box_type=space.gettypefor(interp_boxes.W_Int64Box),
             alternate_constructors=[space.w_long],
+            aliases=['longlong'],
         )
         self.w_uint64dtype = W_Dtype(
             types.UInt64(),
@@ -580,6 +586,7 @@
             name="uint64",
             char=NPY_ULONGLONGLTR,
             w_box_type=space.gettypefor(interp_boxes.W_UInt64Box),
+            aliases=['ulonglong'],
         )
         self.w_float32dtype = W_Dtype(
             types.Float32(),
@@ -588,6 +595,7 @@
             name="float32",
             char=NPY_FLOATLTR,
             w_box_type=space.gettypefor(interp_boxes.W_Float32Box),
+            aliases=['single']
         )
         self.w_float64dtype = W_Dtype(
             types.Float64(),
@@ -617,6 +625,7 @@
             name="complex64",
             char=NPY_CFLOATLTR,
             w_box_type = space.gettypefor(interp_boxes.W_Complex64Box),
+            aliases=['csingle'],
             float_type = self.w_float32dtype,
         )
         self.w_complex128dtype = W_Dtype(
@@ -627,7 +636,7 @@
             char=NPY_CDOUBLELTR,
             w_box_type = space.gettypefor(interp_boxes.W_Complex128Box),
             alternate_constructors=[space.w_complex],
-            aliases=["complex"],
+            aliases=["complex", 'cfloat', 'cdouble'],
             float_type = self.w_float64dtype,
         )
         self.w_complexlongdtype = W_Dtype(
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
@@ -56,8 +56,21 @@
 
     def test_dtype_aliases(self):
         from numpypy import dtype
+        assert dtype('bool8') is dtype('bool')
+        assert dtype('byte') is dtype('int8')
+        assert dtype('ubyte') is dtype('uint8')
+        assert dtype('short') is dtype('int16')
+        assert dtype('ushort') is dtype('uint16')
+        assert dtype('longlong') is dtype('q')
+        assert dtype('ulonglong') is dtype('Q')
+        assert dtype("float") is dtype(float)
+        assert dtype('single') is dtype('float32')
+        assert dtype('double') is dtype('float64')
         assert dtype('longfloat').num in (12, 13)
         assert dtype('longdouble').num in (12, 13)
+        assert dtype('csingle') is dtype('complex64')
+        assert dtype('cfloat') is dtype('complex128')
+        assert dtype('cdouble') is dtype('complex128')
         assert dtype('clongfloat').num in (15, 16)
         assert dtype('clongdouble').num in (15, 16)
 
@@ -223,10 +236,6 @@
             pass
         assert True
 
-    def test_aliases(self):
-        from numpypy import dtype
-        assert dtype("float") is dtype(float)
-
     def test_index(self):
         import numpypy as np
         for dtype in [np.int8, np.int16, np.int32, np.int64]:
diff --git a/pypy/module/micronumpy/test/test_scalar.py b/pypy/module/micronumpy/test/test_scalar.py
--- a/pypy/module/micronumpy/test/test_scalar.py
+++ b/pypy/module/micronumpy/test/test_scalar.py
@@ -3,6 +3,21 @@
 class AppTestScalar(BaseNumpyAppTest):
     spaceconfig = dict(usemodules=["micronumpy", "binascii", "struct"])
 
+    def test_init(self):
+        import numpypy as np
+        import math
+        assert np.intp() == np.intp(0)
+        assert np.intp('123') == np.intp(123)
+        raises(TypeError, np.intp, None)
+        assert np.float64() == np.float64(0)
+        assert math.isnan(np.float64(None))
+        assert np.bool_() == np.bool_(False)
+        assert np.bool_('abc') == np.bool_(True)
+        assert np.bool_(None) == np.bool_(False)
+        assert np.complex_() == np.complex_(0)
+        #raises(TypeError, np.complex_, '1+2j')
+        assert math.isnan(np.complex_(None))
+
     def test_pickle(self):
         from numpypy import dtype, zeros
         try:
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -347,6 +347,8 @@
         return self._coerce(space, w_item)
 
     def _coerce(self, space, w_item):
+        if space.is_none(w_item):
+            return self.box(False)
         return self.box(space.is_true(w_item))
 
     def to_builtin_type(self, space, w_item):
@@ -410,6 +412,8 @@
     _mixin_ = True
 
     def _base_coerce(self, space, w_item):
+        if w_item is None:
+            return self.box(0)
         return self.box(space.int_w(space.call_function(space.w_int, w_item)))
     def _coerce(self, space, w_item):
         return self._base_coerce(space, w_item)
@@ -629,6 +633,8 @@
     _mixin_ = True
 
     def _coerce(self, space, w_item):
+        if w_item is None:
+            return self.box(0.0)
         if space.is_none(w_item):
             return self.box(rfloat.NAN)
         return self.box(space.float_w(space.call_function(space.w_float, w_item)))
@@ -999,6 +1005,10 @@
     _mixin_ = True
 
     def _coerce(self, space, w_item):
+        if w_item is None:
+            return self.box_complex(0.0, 0.0)
+        if space.is_none(w_item):
+            return self.box_complex(rfloat.NAN, rfloat.NAN)
         w_item = space.call_function(space.w_complex, w_item)
         real, imag = space.unpackcomplex(w_item)
         return self.box_complex(real, imag)


More information about the pypy-commit mailing list