[pypy-commit] pypy numpy-dtype: unary functions actually aren't working. Simplified the Call1 class.

justinpeel noreply at buildbot.pypy.org
Thu Sep 1 06:52:40 CEST 2011


Author: Justin Peel <notmuchtotell at gmail.com>
Branch: numpy-dtype
Changeset: r46970:2062025cf412
Date: 2011-08-24 00:17 -0600
http://bitbucket.org/pypy/pypy/changeset/2062025cf412/

Log:	unary functions actually aren't working. Simplified the Call1 class.

diff --git a/pypy/module/micronumpy/__init__.py b/pypy/module/micronumpy/__init__.py
--- a/pypy/module/micronumpy/__init__.py
+++ b/pypy/module/micronumpy/__init__.py
@@ -24,7 +24,7 @@
         #'maximum': 'interp_ufuncs.maximum',
         #'minimum': 'interp_ufuncs.minimum',
         #'multiply': 'interp_ufuncs.multiply',
-        #'negative': 'interp_ufuncs.negative',
+        'negative': 'interp_ufuncs.negative',
         #'reciprocal': 'interp_ufuncs.reciprocal',
         #'sign': 'interp_ufuncs.sign',
         #'subtract': 'interp_ufuncs.subtract',
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
@@ -59,14 +59,14 @@
         return self
 
     descr_neg = _unaryop_impl(interp_ufuncs.negative)
-    descr_abs = _unaryop_impl(interp_ufuncs.absolute)
+    #descr_abs = _unaryop_impl(interp_ufuncs.absolute)
 
     def _binop_impl(w_ufunc):
         def impl(self, space, w_other):
             return w_ufunc(space, self, w_other)
         return func_with_new_name(impl, "binop_%s_impl" % w_ufunc.__name__)
 
-    descr_add = _binop_impl(interp_ufuncs.add)
+    #descr_add = _binop_impl(interp_ufuncs.add)
     #descr_sub = _binop_impl(interp_ufuncs.subtract)
     #descr_mul = _binop_impl(interp_ufuncs.multiply)
     #descr_div = _binop_impl(interp_ufuncs.divide)
@@ -273,7 +273,7 @@
             #        w_value = new_numarray(space, w_value, self.dtype)
             #else:
             w_value = convert_to_array(space, w_value)
-            concrete.setslice(space, start, stop, step, 
+            concrete.setslice(start, stop, step, 
                                                 slice_length, w_value)
 
     def descr_mean(self, space):
@@ -328,10 +328,8 @@
     """
     Class for representing virtual arrays, such as binary ops or ufuncs
     """
-    def __init__(self, signature):
+    def __init__(self):
         BaseArray.__init__(self)
-        self.forced_result = None
-        self.signature = signature
 
     def _del_sources(self):
         # Function for deleting references to source arrays, to allow garbage-collecting them
@@ -352,38 +350,17 @@
     #        i += 1
     #    return result
 
-    def force_if_needed(self):
-        if self.forced_result is None:
-            self.forced_result = self.compute()
-            self._del_sources()
-
-    def get_concrete(self):
-        self.force_if_needed()
-        return self.forced_result
-
-    def eval(self, i):
-        if self.forced_result is not None:
-            return self.forced_result.eval(i)
-        return self._eval(i)
-
-    def find_size(self):
-        if self.forced_result is not None:
-            # The result has been computed and sources may be unavailable
-            return self.forced_result.find_size()
-        return self._find_size()
-
-    def find_dtype(self):
-        return self.dtype
-
 def make_call1(_dtype):
     class Call1(VirtualArray):
         _immutable_fields_ = ["function", "values"]
 
         dtype = _dtype
         def __init__(self, function, values, signature):
-            VirtualArray.__init__(self, signature)
+            VirtualArray.__init__(self)
             self.function = function
             self.values = values
+            self.forced_result = None
+            self.signature = signature
 
         def _del_sources(self):
             self.values = None
@@ -393,17 +370,41 @@
             signature = self.signature
             result_size = self.find_size()
             result = create_sdarray(result_size, _dtype)
-            while i < result_size:
-                #numpy_driver.jit_merge_point(signature=signature,
-                #                             result_size=result_size, i=i,
-                #                             self=self, result=result)
-                result.setitem(i, self.eval(i))
-                i += 1
+            result.setslice(0, result_size, 1, result_size, self)
+            #while i < result_size:
+            #    #numpy_driver.jit_merge_point(signature=signature,
+            #    #                             result_size=result_size, i=i,
+            #    #                             self=self, result=result)
+            #    result.setitem(i, self.eval(i))
+            #    i += 1
             return result
 
         def _find_size(self):
             return self.values.find_size()
 
+        def force_if_needed(self):
+            if self.forced_result is None:
+                self.forced_result = self.compute()
+                self._del_sources()
+
+        def get_concrete(self):
+            self.force_if_needed()
+            return self.forced_result
+
+        def eval(self, i):
+            if self.forced_result is not None:
+                return self.forced_result.eval(i)
+            return self._eval(i)
+
+        def find_size(self):
+            if self.forced_result is not None:
+                # The result has been computed and sources may be unavailable
+                return self.forced_result.find_size()
+            return self._find_size()
+
+        def find_dtype(self):
+            return self.dtype
+
         def _eval(self, i):
             return self.function(_dtype.convval(self.values.eval(i)))
     Call1.__name__ = "Call1_" + Call1.dtype.name
@@ -423,12 +424,14 @@
 
         dtype = _dtype
         def __init__(self, function, left, right, signature):
-            VirtualArray.__init__(self, signature)
+            VirtualArray.__init__(self)
             self.left = left
             self.right = right
             dtype1 = self.left.find_dtype()
             dtype2 = self.right.find_dtype()
             self.function = function
+            self.forced_result = None
+            self.signature = signature
             #if dtype1.num != _dtype.num:
             #    self.cast1 = _dtype.convval
             #else:
@@ -466,12 +469,38 @@
                 result.setitem(i, self.eval(i))
                 i += 1
             return result
+
         def _find_size(self):
             try:
                 return self.left.find_size()
             except:
                 return self.right.find_size()
 
+        def force_if_needed(self):
+            if self.forced_result is None:
+                self.forced_result = self.compute()
+                self._del_sources()
+
+        def get_concrete(self):
+            self.force_if_needed()
+            return self.forced_result
+
+        def eval(self, i):
+            if self.forced_result is not None:
+                return self.forced_result.eval(i)
+            return self._eval(i)
+
+        def find_size(self):
+            if self.forced_result is not None:
+                # The result has been computed and sources may be unavailable
+                return self.forced_result.find_size()
+            return self._find_size()
+
+        def find_dtype(self):
+            return self.dtype
+
+
+
         def _eval(self, i):
             lhs, rhs = _dtype.convval(self.left.eval(i)), _dtype.convval(self.right.eval(i))
             return self.function(lhs, rhs)
@@ -550,12 +579,12 @@
     def find_size(self):
         return self.size
 
-    def setslice(self, space, start, stop, step, slice_length, arr):
+    def setslice(self, start, stop, step, slice_length, arr):
         start = self.calc_index(start)
         if stop != -1:
             stop = self.calc_index(stop)
         step = self.step * step
-        self.parent.setslice(space, start, stop, step, slice_length, arr)
+        self.parent.setslice(start, stop, step, slice_length, arr)
 
     def calc_index(self, item):
         return (self.start + item * self.step)
@@ -653,7 +682,7 @@
                 j += 1
                 i += step
 
-        def setslice(self, space, start, stop, step, slice_length, arr):
+        def setslice(self, start, stop, step, slice_length, arr):
             if step > 0:
                 self._sliceloop1(start, stop, step, arr)
             else:
@@ -732,8 +761,8 @@
 
     __pos__ = interp2app(BaseArray.descr_pos),
     __neg__ = interp2app(BaseArray.descr_neg),
-    __abs__ = interp2app(BaseArray.descr_abs),
-    __add__ = interp2app(BaseArray.descr_add),
+    #__abs__ = interp2app(BaseArray.descr_abs),
+    #__add__ = interp2app(BaseArray.descr_add),
     #__sub__ = interp2app(BaseArray.descr_sub),
     #__mul__ = interp2app(BaseArray.descr_mul),
     #__div__ = interp2app(BaseArray.descr_div),
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
@@ -19,31 +19,31 @@
             return space.wrap(func(space.float_w(w_obj)))
     return func_with_new_name(impl, "%s_dispatcher" % func.__name__)
 
-def ufunc2(func):
-    signature = Signature()
-    def impl(space, w_lhs, w_rhs):
-        from pypy.module.micronumpy.interp_numarray import pick_call2, convert_to_array
-        if space.issequence_w(w_lhs) or space.issequence_w(w_rhs):
-            w_lhs_arr = convert_to_array(space, w_lhs)
-            w_rhs_arr = convert_to_array(space, w_rhs)
-            new_sig = w_lhs_arr.signature.transition(signature).transition(w_rhs_arr.signature)
-            w_res = pick_call2(w_lhs_arr.dtype, w_rhs_arr.dtype)(func, w_lhs_arr, w_rhs_arr, new_sig)
-            w_lhs_arr.invalidates.append(w_res)
-            w_rhs_arr.invalidates.append(w_res)
-            return w_res
-        else:
-            return space.wrap(func(space.float_w(w_lhs), space.float_w(w_rhs)))
-    return func_with_new_name(impl, "%s_dispatcher" % func.__name__)
+#def ufunc2(func):
+#    signature = Signature()
+#    def impl(space, w_lhs, w_rhs):
+#        from pypy.module.micronumpy.interp_numarray import pick_call2, convert_to_array
+#        if space.issequence_w(w_lhs) or space.issequence_w(w_rhs):
+#            w_lhs_arr = convert_to_array(space, w_lhs)
+#            w_rhs_arr = convert_to_array(space, w_rhs)
+#            new_sig = w_lhs_arr.signature.transition(signature).transition(w_rhs_arr.signature)
+#            w_res = pick_call2(w_lhs_arr.dtype, w_rhs_arr.dtype)(func, w_lhs_arr, w_rhs_arr, new_sig)
+#            w_lhs_arr.invalidates.append(w_res)
+#            w_rhs_arr.invalidates.append(w_res)
+#            return w_res
+#        else:
+#            return space.wrap(func(space.float_w(w_lhs), space.float_w(w_rhs)))
+#    return func_with_new_name(impl, "%s_dispatcher" % func.__name__)
 
- at ufunc
- at specialize.argtype(0)
-def absolute(value):
-    return abs(value)
+#@ufunc
+#@specialize.argtype(1)
+#def absolute(value):
+#    return abs(value)
 
- at ufunc2
- at specialize.argtype(0,1)
-def add(lvalue, rvalue):
-    return lvalue + rvalue
+#@specialize.argtype(1,2)
+#@ufunc2
+#def add(lvalue, rvalue):
+#    return lvalue + rvalue
 
 #@ufunc2
 #def copysign(lvalue, rvalue):


More information about the pypy-commit mailing list