Justin Peel avatar Justin Peel committed 2062025

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

Comments (0)

Files changed (3)

pypy/module/micronumpy/__init__.py

         #'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',

pypy/module/micronumpy/interp_numarray.py

         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)
             #        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):
     """
     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
     #        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
             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
 
         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:
                 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)
     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)
                 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:
 
     __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),

pypy/module/micronumpy/interp_ufuncs.py

             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__)
 
-@ufunc
-@specialize.argtype(0)
-def absolute(value):
-    return abs(value)
+#@ufunc
+#@specialize.argtype(1)
+#def absolute(value):
+#    return abs(value)
 
-@ufunc2
-@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):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.