Author: Alex Gaynor <[email protected]>
Branch: numpy-exp
Changeset: r44173:498abbcc393e
Date: 2011-05-14 21:30 -0500
http://bitbucket.org/pypy/pypy/changeset/498abbcc393e/
Log: Fixed a bug with invalidation of calls and generalized ufunc logic.
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
@@ -1,10 +1,16 @@
from pypy.interpreter.gateway import unwrap_spec
from pypy.module.micronumpy.interp_numarray import BaseArray, Call
+from pypy.tool.sourcetools import func_with_new_name
-def negative_impl(value):
- return -value
+def ufunc(func):
+ @unwrap_spec(array=BaseArray)
+ def impl(space, array):
+ w_res = Call(func, array)
+ array.invalidates.append(w_res)
+ return w_res
+ return func_with_new_name(impl, "%s_dispatcher" % func.__name__)
-@unwrap_spec(array=BaseArray)
-def negative(space, array):
- return Call(negative_impl, array)
\ No newline at end of file
+@ufunc
+def negative(value):
+ return -value
\ No newline at end of file
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py
b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -8,4 +8,9 @@
a = array([-5.0, 0.0, 1.0])
b = negative(a)
for i in range(3):
- assert b[i] == -a[i]
\ No newline at end of file
+ assert b[i] == -a[i]
+
+ a = array([-5.0, 1.0])
+ b = negative(a)
+ a[0] = 5.0
+ assert b[0] == 5.0
\ No newline at end of file
diff --git a/pypy/module/micronumpy/test/test_zjit.py
b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -1,7 +1,7 @@
from pypy.jit.metainterp.test.support import LLJitMixin
from pypy.module.micronumpy.interp_numarray import (SingleDimArray, BinOp,
FloatWrapper, Call)
-from pypy.module.micronumpy.interp_ufuncs import negative_impl
+from pypy.module.micronumpy.interp_ufuncs import negative
class FakeSpace(object):
@@ -69,7 +69,7 @@
def f(i):
ar = SingleDimArray(i)
v1 = BinOp('a', ar, ar)
- v2 = Call(negative_impl, v1)
+ v2 = negative(space, v1)
return v2.get_concrete().storage[3]
result = self.meta_interp(f, [5], listops=True, backendopt=True)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit