Author: Brian Kearns <[email protected]>
Branch: 
Changeset: r67474:0032c1800df8
Date: 2013-10-18 00:39 -0400
http://bitbucket.org/pypy/pypy/changeset/0032c1800df8/

Log:    more cleanups for numpypy

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
@@ -116,6 +116,8 @@
 
 
 class W_GenericBox(W_Root):
+    _attrs_ = []
+
     def descr__new__(space, w_subtype, __args__):
         raise operationerrfmt(space.w_TypeError,
                               "cannot create '%N' instances",
@@ -359,6 +361,7 @@
         _COMPONENTS_BOX = W_FloatLongBox
 
 class W_FlexibleBox(W_GenericBox):
+    _attrs_ = ['arr', 'ofs', 'dtype']
     _immutable_fields_ = ['arr', 'ofs', 'dtype']
 
     def __init__(self, arr, ofs, dtype):
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
@@ -1,4 +1,3 @@
-
 import sys
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.error import OperationError, operationerrfmt
@@ -11,6 +10,12 @@
 from rpython.rtyper.lltypesystem import rffi
 from rpython.rlib import jit
 
+if sys.byteorder == 'little':
+    byteorder_prefix = '<'
+    nonnative_byteorder_prefix = '>'
+else:
+    byteorder_prefix = '>'
+    nonnative_byteorder_prefix = '<'
 
 UNSIGNEDLTR = "u"
 SIGNEDLTR = "i"
@@ -44,12 +49,11 @@
     out = base.W_NDimArray.from_shape(space, shape, dtype)
     return out
 
-
 class W_Dtype(W_Root):
     _immutable_fields_ = ["itemtype", "num", "kind", "shape"]
 
     def __init__(self, itemtype, num, kind, name, char, w_box_type,
-                 alternate_constructors=[], aliases=[],
+                 alternate_constructors=[], aliases=[], float_type=None,
                  fields=None, fieldnames=None, native=True, shape=[], 
subdtype=None):
         self.itemtype = itemtype
         self.num = num
@@ -59,10 +63,10 @@
         self.w_box_type = w_box_type
         self.alternate_constructors = alternate_constructors
         self.aliases = aliases
+        self.float_type = float_type
         self.fields = fields
         self.fieldnames = fieldnames
         self.native = native
-        self.float_type = None
         self.shape = list(shape)
         self.subdtype = subdtype
         if not subdtype:
@@ -227,7 +231,7 @@
         return self.kind == SIGNEDLTR
 
     def is_complex_type(self):
-        return False
+        return self.kind == COMPLEXLTR
 
     def is_float_type(self):
         return (self.kind == FLOATINGLTR or self.float_type is not None)
@@ -300,18 +304,6 @@
         fields = space.getitem(w_data, space.wrap(4))
         self.set_fields(space, fields)
 
-class W_ComplexDtype(W_Dtype):
-    def __init__(self, itemtype, num, kind, name, char, w_box_type,
-                 alternate_constructors=[], aliases=[],
-                 fields=None, fieldnames=None, native=True, float_type=None):
-        W_Dtype.__init__(self, itemtype, num, kind, name, char, w_box_type,
-                 alternate_constructors=alternate_constructors, 
aliases=aliases,
-                 fields=fields, fieldnames=fieldnames, native=native)
-        self.float_type = float_type
-
-    def is_complex_type(self):
-        return True
-
 def dtype_from_list(space, w_lst):
     lst_w = space.listview(w_lst)
     fields = {}
@@ -345,38 +337,6 @@
     raise OperationError(space.w_NotImplementedError, space.wrap(
         "dtype from dict"))
 
-def variable_dtype(space, name):
-    if name[0] in '<>=':
-        name = name[1:]
-    char = name[0]
-    if len(name) == 1:
-        size = 0
-    else:
-        try:
-            size = int(name[1:])
-        except ValueError:
-            raise OperationError(space.w_TypeError, space.wrap("data type not 
understood"))
-    if char == 'S' or char == 'c':
-        itemtype = types.StringType(size)
-        basename = 'string'
-        num = 18
-        w_box_type = space.gettypefor(interp_boxes.W_StringBox)
-    elif char == 'V':
-        num = 20
-        basename = 'void'
-        itemtype = types.VoidType(size)
-        return W_Dtype(itemtype, 20, VOIDLTR, "void" + str(size),
-                    "V", space.gettypefor(interp_boxes.W_VoidBox))
-    else:
-        assert char == 'U'
-        basename = 'unicode'
-        itemtype = types.UnicodeType(size)
-        num = 19
-        w_box_type = space.gettypefor(interp_boxes.W_UnicodeBox)
-    return W_Dtype(itemtype, num, char,
-                   basename + str(8 * itemtype.get_element_size()),
-                   char, w_box_type)
-
 def dtype_from_spec(space, name):
         raise OperationError(space.w_NotImplementedError, space.wrap(
             "dtype from spec"))
@@ -460,12 +420,38 @@
 )
 W_Dtype.typedef.acceptable_as_base_class = False
 
-if sys.byteorder == 'little':
-    byteorder_prefix = '<'
-    nonnative_byteorder_prefix = '>'
-else:
-    byteorder_prefix = '>'
-    nonnative_byteorder_prefix = '<'
+
+def variable_dtype(space, name):
+    if name[0] in '<>=':
+        name = name[1:]
+    char = name[0]
+    if len(name) == 1:
+        size = 0
+    else:
+        try:
+            size = int(name[1:])
+        except ValueError:
+            raise OperationError(space.w_TypeError, space.wrap("data type not 
understood"))
+    if char == 'S' or char == 'c':
+        itemtype = types.StringType(size)
+        basename = 'string'
+        num = 18
+        w_box_type = space.gettypefor(interp_boxes.W_StringBox)
+    elif char == 'V':
+        num = 20
+        basename = 'void'
+        itemtype = types.VoidType(size)
+        return W_Dtype(itemtype, 20, VOIDLTR, "void" + str(size),
+                    "V", space.gettypefor(interp_boxes.W_VoidBox))
+    else:
+        assert char == 'U'
+        basename = 'unicode'
+        itemtype = types.UnicodeType(size)
+        num = 19
+        w_box_type = space.gettypefor(interp_boxes.W_UnicodeBox)
+    return W_Dtype(itemtype, num, char,
+                   basename + str(8 * itemtype.get_element_size()),
+                   char, w_box_type)
 
 def new_string_dtype(space, size):
     return W_Dtype(
@@ -617,7 +603,7 @@
             w_box_type=space.gettypefor(interp_boxes.W_FloatLongBox),
             aliases=["longdouble", "longfloat"],
         )
-        self.w_complex64dtype = W_ComplexDtype(
+        self.w_complex64dtype = W_Dtype(
             types.Complex64(),
             num=14,
             kind=COMPLEXLTR,
@@ -626,7 +612,7 @@
             w_box_type = space.gettypefor(interp_boxes.W_Complex64Box),
             float_type = self.w_float32dtype,
         )
-        self.w_complex128dtype = W_ComplexDtype(
+        self.w_complex128dtype = W_Dtype(
             types.Complex128(),
             num=15,
             kind=COMPLEXLTR,
@@ -637,7 +623,7 @@
             aliases=["complex"],
             float_type = self.w_float64dtype,
         )
-        self.w_complexlongdtype = W_ComplexDtype(
+        self.w_complexlongdtype = W_Dtype(
             types.ComplexLong(),
             num=16,
             kind=COMPLEXLTR,
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to