[pypy-svn] r76195 - pypy/branch/micronumpy/pypy/module/micronumpy

dan at codespeak.net dan at codespeak.net
Wed Jul 14 11:51:16 CEST 2010


Author: dan
Date: Wed Jul 14 11:51:14 2010
New Revision: 76195

Modified:
   pypy/branch/micronumpy/pypy/module/micronumpy/array.py
   pypy/branch/micronumpy/pypy/module/micronumpy/mdarray.py
   pypy/branch/micronumpy/pypy/module/micronumpy/microarray.py
   pypy/branch/micronumpy/pypy/module/micronumpy/sdarray.py
Log:
More cleaning, time to start passing tests again.

Modified: pypy/branch/micronumpy/pypy/module/micronumpy/array.py
==============================================================================
--- pypy/branch/micronumpy/pypy/module/micronumpy/array.py	(original)
+++ pypy/branch/micronumpy/pypy/module/micronumpy/array.py	Wed Jul 14 11:51:14 2010
@@ -58,20 +58,5 @@
 class BaseNumArray(Wrappable):
     pass
 
-def descr_new(space, w_cls, w_shape, w_dtype=NoneNotWrapped,
-              w_buffer=NoneNotWrapped, w_offset=NoneNotWrapped,
-              w_strides=NoneNotWrapped, order='C'):
-    shape_w = unpack_shape(space, w_shape)
-    dtype_w = get_dtype(space, w_dtype)
-    result = construct_array(space, shape_w, dtype_w)
-    #TODO: load from buffer?
-    return space.wrap(result)
-descr_new.unwrap_spec = [ObjSpace, W_Root, W_Root, W_Root,
-                         W_Root, W_Root,
-                         W_Root, str]
-
-BaseNumArray.typedef = TypeDef("ndarray",
-                       __new__ = interp2app(descr_new),
-                      )
-base_typedef = BaseNumArray.typedef
+BaseNumArray.typedef = TypeDef("ndarray")
 ndarray = BaseNumArray

Modified: pypy/branch/micronumpy/pypy/module/micronumpy/mdarray.py
==============================================================================
--- pypy/branch/micronumpy/pypy/module/micronumpy/mdarray.py	(original)
+++ pypy/branch/micronumpy/pypy/module/micronumpy/mdarray.py	Wed Jul 14 11:51:14 2010
@@ -8,17 +8,8 @@
 from pypy.rlib.debug import make_sure_not_resized
 
 from pypy.module.micronumpy.array import BaseNumArray
-from pypy.module.micronumpy.array import base_typedef
 from pypy.module.micronumpy.array import construct_array, infer_shape
-from pypy.module.micronumpy.array import array as array_fromseq
 from pypy.module.micronumpy.array import validate_index
-from pypy.module.micronumpy.array import \
-        mul_operation, div_operation, add_operation, sub_operation
-
-from pypy.module.micronumpy.dtype import unwrap_int, coerce_int
-from pypy.module.micronumpy.dtype import unwrap_float, coerce_float
-from pypy.module.micronumpy.dtype import create_factory, result_mapping
-from pypy.module.micronumpy.dtype import retrieve_dtype
 
 def compute_pos(space, indexes, dim):
     current = 1
@@ -192,11 +183,6 @@
 def descr_shape(space, self):
     return space.newtuple([space.wrap(dim) for dim in self.shape])
 
-mul = mul_operation()
-div = div_operation()
-add = add_operation()
-sub = sub_operation()
-
 def create_mdarray(data_type, unwrap, coerce):
 
     def create_math_operation(f):
@@ -464,7 +450,7 @@
         descr_str.unwrap_spec = ['self']
 
     MultiDimArray.typedef = \
-            TypeDef('ndarray', base_typedef,
+            TypeDef('mdarray', #XXX: condemned
                     __len__ = interp2app(MultiDimArray.descr_len),
                     __getitem__ = interp2app(MultiDimArray.descr_getitem),
                     __setitem__ = interp2app(MultiDimArray.descr_setitem),
@@ -485,8 +471,3 @@
                     shape = GetSetProperty(descr_shape, cls = MultiDimArray),
                    )
     return MultiDimArray
-
-MultiDimIntArray = create_mdarray(int, unwrap_int, coerce_int)
-MultiDimFloatArray = create_mdarray(float, unwrap_float, coerce_float)
-
-mdresult = create_factory({'i': MultiDimIntArray, 'd': MultiDimFloatArray})

Modified: pypy/branch/micronumpy/pypy/module/micronumpy/microarray.py
==============================================================================
--- pypy/branch/micronumpy/pypy/module/micronumpy/microarray.py	(original)
+++ pypy/branch/micronumpy/pypy/module/micronumpy/microarray.py	Wed Jul 14 11:51:14 2010
@@ -1,21 +1,17 @@
 from pypy.interpreter.baseobjspace import ObjSpace
+from pypy.interpreter.baseobjspace import Wrappable
+from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.error import OperationError
+
 from pypy.interpreter.typedef import TypeDef, GetSetProperty
 from pypy.interpreter.gateway import interp2app
 from pypy.interpreter.gateway import NoneNotWrapped
 
-from pypy.interpreter.baseobjspace import Wrappable
-from pypy.interpreter.baseobjspace import W_Root, UnpackValueError
-from pypy.objspace.std.sliceobject import W_SliceObject
-from pypy.objspace.std.listobject import W_ListObject
-from pypy.objspace.std.tupleobject import W_TupleObject
 from pypy.rlib.debug import make_sure_not_resized
 
 from pypy.module import micronumpy
 from pypy.module.micronumpy.array import BaseNumArray
-from pypy.module.micronumpy.array import base_typedef
 from pypy.module.micronumpy.array import construct_array, infer_shape
-from pypy.module.micronumpy.array import validate_index
 
 def size_from_shape(shape):
     size = 1
@@ -254,6 +250,19 @@
 def descr_get_shape(space, self):
     return space.newtuple([space.wrap(x) for x in self.shape])
 
+#TODO: add to typedef when ready
+def descr_new(space, w_cls, w_shape, w_dtype=NoneNotWrapped,
+              w_buffer=NoneNotWrapped, w_offset=NoneNotWrapped,
+              w_strides=NoneNotWrapped, order='C'):
+    shape_w = unpack_shape(space, w_shape)
+    dtype_w = get_dtype(space, w_dtype)
+    result = construct_array(space, shape_w, dtype_w)
+    #TODO: load from buffer
+    return space.wrap(result)
+descr_new.unwrap_spec = [ObjSpace, W_Root, W_Root, W_Root,
+                         W_Root, W_Root,
+                         W_Root, str]
+
 MicroArray.typedef = TypeDef('uarray',
                              dtype = GetSetProperty(descr_get_dtype, cls=MicroArray),
                              shape = GetSetProperty(descr_get_shape, cls=MicroArray),
@@ -268,38 +277,10 @@
     assert a == b, "Invalid assertion I think" # FIXME
     return a
 
-#def infer_shape(space, w_xs):
-def infer_shape_slow(space, w_xs): # gonna kill this after it's been svn for one revision
-    length = 0
-    shape = []
-    old = None
-    try:
-        w_i = space.iter(w_xs)
-        while True:
-            element = space.next(w_i)
-            try:
-                shape = infer_shape(space, element)
-            except OperationError, e:
-                if e.match(space, space.w_TypeError): pass
-                else: raise
-
-            if old is not None:
-                shape = reconcile_shapes(space, old, shape) # use to process jagged arrays, if Numpy even allows them
-                
-            length += 1
-            old = shape
-    except OperationError, e:
-        if e.match(space, space.w_StopIteration):
-            return [length] + shape
-        else:
-            raise
-
-#XXX: don't like having to pass around setitem
 app_fill_array = gateway.applevel("""
     def fill_array(start, a, b):
         i = 0
         for x in b:
-            print i
             try:
                 fill_array(start + [i], a, x)
             except TypeError, e:

Modified: pypy/branch/micronumpy/pypy/module/micronumpy/sdarray.py
==============================================================================
--- pypy/branch/micronumpy/pypy/module/micronumpy/sdarray.py	(original)
+++ pypy/branch/micronumpy/pypy/module/micronumpy/sdarray.py	Wed Jul 14 11:51:14 2010
@@ -7,11 +7,6 @@
 from pypy.objspace.std.sliceobject import W_SliceObject
 from pypy.objspace.std.tupleobject import W_TupleObject
 
-from pypy.module.micronumpy.array import BaseNumArray
-from pypy.module.micronumpy.array import base_typedef
-from pypy.module.micronumpy.array import \
-        mul_operation, div_operation, add_operation, sub_operation
-
 #TODO: merge unwrap_spec decorator
 # from pypy.interpreter.gateway import unwrap_spec
 



More information about the Pypy-commit mailing list