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

dan at codespeak.net dan at codespeak.net
Thu Jul 15 01:04:23 CEST 2010


Author: dan
Date: Thu Jul 15 01:04:21 2010
New Revision: 76218

Modified:
   pypy/branch/micronumpy/pypy/module/micronumpy/__init__.py
   pypy/branch/micronumpy/pypy/module/micronumpy/dtype.py
   pypy/branch/micronumpy/pypy/module/micronumpy/microarray.py
   pypy/branch/micronumpy/pypy/module/micronumpy/ufunc.py
Log:
checkmodule.py approved

Modified: pypy/branch/micronumpy/pypy/module/micronumpy/__init__.py
==============================================================================
--- pypy/branch/micronumpy/pypy/module/micronumpy/__init__.py	(original)
+++ pypy/branch/micronumpy/pypy/module/micronumpy/__init__.py	Thu Jul 15 01:04:21 2010
@@ -1,6 +1,5 @@
 
 from pypy.interpreter.mixedmodule import MixedModule 
-import dtype
 
 class Module(MixedModule):
     def __init__(self, space, w_name):
@@ -16,7 +15,7 @@
         'array'    : 'microarray.array',
         'zeros'    : 'microarray.zeros',
         'ndarray'  : 'array.ndarray',
-        'minimum'  : 'ufunc.minimum',
-        'dot'      : 'ufunc.dot',
+        #'minimum'  : 'ufunc.minimum',
+        #'dot'      : 'ufunc.dot',
         }
 

Modified: pypy/branch/micronumpy/pypy/module/micronumpy/dtype.py
==============================================================================
--- pypy/branch/micronumpy/pypy/module/micronumpy/dtype.py	(original)
+++ pypy/branch/micronumpy/pypy/module/micronumpy/dtype.py	Thu Jul 15 01:04:21 2010
@@ -40,7 +40,10 @@
                             __eq__ = interp2app(TypeDescr.descr_eq),
                             __repr__ = interp2app(TypeDescr.descr_repr),
                            )
-                            
+
+storage_type = lltype.Ptr(lltype.Array(lltype.Char))                           
+null_storage = lltype.nullptr(storage_type.TO)
+
 class DescrBase(object): pass
 
 _typeindex = {}
@@ -76,7 +79,9 @@
             array[index] = value # XXX: let's see if this works
 
         def alloc(self, count):
-            return lltype.malloc(arraytype, count, flavor='raw')
+            #return lltype.malloc(arraytype, count, flavor='raw')
+            mem = lltype.malloc(arraytype, count, flavor='raw')
+            return rffi.cast(storage_type, mem)
 
         def free(self, data):
             lltype.free(data, flavor='raw')
@@ -136,12 +141,16 @@
                 }
 
 def result(a, b):
+    assert isinstance(a, DescrBase)
+    assert isinstance(b, DescrBase)
     a = a.typeid
     b = b.typeid
     c = _result_types[(a, b)]
     return _descriptors[c]
 
 def w_result(w_a, w_b):
+    assert isinstance(w_a, TypeDescr)
+    assert isinstance(w_b, TypeDescr)
     return result(w_a.dtype, w_b.dtype).wrappable_dtype()
 
 def from_typecode(s):

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	Thu Jul 15 01:04:21 2010
@@ -12,6 +12,7 @@
 from pypy.module import micronumpy
 from pypy.module.micronumpy.array import BaseNumArray
 from pypy.module.micronumpy.array import construct_array, infer_shape
+from pypy.module.micronumpy.dtype import null_storage
 
 def size_from_shape(shape):
     size = 1
@@ -79,7 +80,7 @@
         elif parent is not None:
             self.data = parent.data
         else:
-            self.data = None
+            self.data = null_storage
 
     def descr_len(self, space):
         return space.wrap(self.shape[0])

Modified: pypy/branch/micronumpy/pypy/module/micronumpy/ufunc.py
==============================================================================
--- pypy/branch/micronumpy/pypy/module/micronumpy/ufunc.py	(original)
+++ pypy/branch/micronumpy/pypy/module/micronumpy/ufunc.py	Thu Jul 15 01:04:21 2010
@@ -1,4 +1,4 @@
-from pypy.module.micronumpy.array import array, zeros, ndarray
+from pypy.module.micronumpy.microarray import array, zeros
 from pypy.module.micronumpy.array import construct_array
 
 from pypy.interpreter.baseobjspace import ObjSpace, W_Root
@@ -15,7 +15,8 @@
         raise OperationError(space.w_ValueError,
                              space.wrap("minimum of arrays of different length"))
 
-    result_type = w_a.dtype.result(w_b.dtype)
+    from pypy.module.micronumpy.dtype import result
+    result_type = result(w_a.dtype, w_b.dtype)
 
     result = MicroArray(w_a.shape, result_type)
 
@@ -32,30 +33,29 @@
 minimum.unwrap_spec = [ObjSpace, W_Root, W_Root]
 
 def dot(space, w_a, w_b):
-    if not isinstance(w_a, ndarray) or not isinstance(w_b, ndarray):
+    if not isinstance(w_a, MicroArray) or not isinstance(w_b, MicroArray):
         raise OperationError(space.w_TypeError,
                 space.wrap("expecting ndarray object"))
 
     if len(w_b.shape) == 1:
-        the_b = mdresult(space, w_b.dtype)(space, [w_b.shape[0], 1], w_b.dtype)
-        the_b.storage[:] = w_b.storage
+        the_b = MicroArray([w_b.shape[0], 1], w_b.dtype)
+        #the_b.storage[:] = w_b.storage #FIXME: copy storage
         w_b = the_b
 
     if len(w_a.shape)%2:
-        the_a = mdresult(space, w_a.dtype)(space, [1]+w_a.shape, w_a.dtype)
-        the_a.storage[:] = w_a.storage
+        the_a = MicroArray([1]+w_a.shape, w_a.dtype)
+        #the_a.storage[:] = w_a.storage #FIXME: ditto
         w_a = the_a
     ah, aw = w_a.shape[0], w_a.shape[1]
     als = len(w_a.shape)
 
     if len(w_b.shape)%2:
-        the_b = mdresult(space, w_b.dtype)(space, [1]+w_b.shape, w_b.dtype)
-        the_b.storage[:] = w_b.storage
+        the_b = MicroArray([1]+w_b.shape, w_b.dtype)
+        #the_b.storage[:] = w_b.storage #FIXME: and again
         w_b = the_b
     bh, bw = w_a.shape[0], w_a.shape[1]
     bls = len(w_b.shape)
 
-
     if aw == bh == 1:
         return dot(space, w_b, w_a)
 
@@ -68,8 +68,8 @@
     if als != bls:
         raise shapemismatch
     
-
-    data = _dotit(space, w_a, w_b, als, [], [])
+    #data = _dotit(space, w_a, w_b, als, [], []) #FIXME: ok this definitely won't work here
+    data = [0] #FIXME: obviously wrong...
     if len(data) == 1:
         return space.wrap(data[0])
     shape = make_sure_not_resized([0]*als)
@@ -77,10 +77,11 @@
         shape[i] = w_a.shape[i]
         shape[i+1] = w_b.shape[i+1]
 
-    dtype = result_mapping(space, (w_a.dtype, w_b.dtype))
+    from pypy.module.micronumpy.dtype import w_result
+    dtype = w_result(w_a.dtype, w_b.dtype)
 
-    res = construct_array(space, shape, retrieve_dtype(space, dtype))
-    res.storage[:] = data
+    res = construct_array(space, shape, dtype)
+    #res.storage[:] = data #FIXME: more copying
     return space.wrap(res)
 dot.unwrap_spec = [ObjSpace, W_Root, W_Root]
 



More information about the Pypy-commit mailing list