Author: Maciej Fijalkowski <[email protected]>
Branch: numpy-refactor
Changeset: r57284:701c787a11bc
Date: 2012-09-11 15:40 +0200
http://bitbucket.org/pypy/pypy/changeset/701c787a11bc/

Log:    rpython fixes

diff --git a/pypy/module/micronumpy/arrayimpl/scalar.py 
b/pypy/module/micronumpy/arrayimpl/scalar.py
--- a/pypy/module/micronumpy/arrayimpl/scalar.py
+++ b/pypy/module/micronumpy/arrayimpl/scalar.py
@@ -25,8 +25,8 @@
 
 class Scalar(base.BaseArrayImplementation):
     def __init__(self, dtype, value=None):
+        self.dtype = dtype
         self.value = value
-        self.dtype = dtype
 
     def is_scalar(self):
         return True
diff --git a/pypy/module/micronumpy/interp_numarray.py 
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -259,9 +259,11 @@
             if self.is_scalar():
                 return self.get_scalar_value().item(space)
             if self.get_size() == 1:
-                return self.descr_getitem(space,
-                                          space.newtuple([space.wrap(0) for i
-                            in range(len(self.get_shape()))])).item(space)
+                w_obj = self.descr_getitem(space,
+                                           space.newtuple([space.wrap(0) for i
+                                      in range(len(self.get_shape()))]))
+                assert isinstance(w_obj, interp_boxes.W_GenericBox)
+                return w_obj.item(space)
             raise OperationError(space.w_IndexError,
                                  space.wrap("index out of bounds"))
         if space.isinstance_w(w_arg, space.w_int):
@@ -339,11 +341,9 @@
 
     def _binop_right_impl(ufunc_name):
         def impl(self, space, w_other, w_out=None):
-            w_other = W_NDimArray.new_scalar(space,
-                interp_ufuncs.find_dtype_for_scalar(space, w_other,
-                                                    self.get_dtype()),
-                w_other
-            )
+            dtype = interp_ufuncs.find_dtype_for_scalar(space, w_other,
+                                                        self.get_dtype())
+            w_other = W_NDimArray.new_scalar(space, dtype, w_other)
             return getattr(interp_ufuncs.get(space), ufunc_name).call(space, 
[w_other, self, w_out])
         return func_with_new_name(impl, "binop_right_%s_impl" % ufunc_name)
 
@@ -373,6 +373,7 @@
             return self.descr_mul(space, other)
         elif len(self.get_shape()) < 2 and len(other.get_shape()) < 2:
             w_res = self.descr_mul(space, other)
+            assert isinstance(w_res, W_NDimArray)
             return w_res.descr_sum(space, space.wrap(-1))
         dtype = interp_ufuncs.find_binop_result_dtype(space,
                                      self.get_dtype(), other.get_dtype())
@@ -565,9 +566,9 @@
                                   order)
     if isinstance(w_object, W_NDimArray):
         if (not space.is_w(w_dtype, space.w_None) and
-            w_object.dtype is not w_dtype):
-            raise operationerrfmt(space.w_NotImplementedError,
-                                  "copying over different dtypes unsupported")
+            w_object.get_dtype() is not w_dtype):
+            raise OperationError(space.w_NotImplementedError, space.wrap(
+                                  "copying over different dtypes unsupported"))
         if copy:
             return w_object.descr_copy(space)
         return w_object
diff --git a/pypy/module/micronumpy/interp_ufuncs.py 
b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -316,10 +316,10 @@
                 if out.is_scalar():
                     out.set_scalar_value(arr)
                 else:
-                    out.fill(space, arr)
+                    out.fill(arr)
             else:
                 out = arr
-            return space.wrap(out)
+            return out
         new_shape = shape_agreement(space, w_lhs.get_shape(), w_rhs)
         new_shape = shape_agreement(space, new_shape, out, 
broadcast_down=False)
         return loop.call2(new_shape, self.func, self.name, calc_dtype,
diff --git a/pypy/rlib/rawstorage.py b/pypy/rlib/rawstorage.py
--- a/pypy/rlib/rawstorage.py
+++ b/pypy/rlib/rawstorage.py
@@ -3,10 +3,12 @@
 from pypy.rpython.lltypesystem import lltype, rffi, llmemory
 from pypy.annotation import model as annmodel
 from pypy.rlib.rgc import lltype_is_gc
+from pypy.rlib.objectmodel import specialize
 
 RAW_STORAGE = rffi.CCHARP.TO
 RAW_STORAGE_PTR = rffi.CCHARP
 
[email protected](1, 2)
 def alloc_raw_storage(size, track_allocation=True, zero=False):
     return lltype.malloc(RAW_STORAGE, size, flavor='raw',
                          add_memory_pressure=True,
@@ -22,6 +24,7 @@
     TP = rffi.CArrayPtr(lltype.typeOf(item))
     rffi.cast(TP, rffi.ptradd(storage, index))[0] = item
 
[email protected](1)
 def free_raw_storage(storage, track_allocation=True):
     lltype.free(storage, flavor='raw', track_allocation=track_allocation)
 
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to