[pypy-commit] pypy numpypy-out: progress: move on to binfunc
mattip
noreply at buildbot.pypy.org
Sun Feb 19 00:36:51 CET 2012
Author: mattip
Branch: numpypy-out
Changeset: r52625:e2f97194b36f
Date: 2012-02-18 22:27 +0200
http://bitbucket.org/pypy/pypy/changeset/e2f97194b36f/
Log: progress: move on to binfunc
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
@@ -265,7 +265,7 @@
if not broadcast_shape or broadcast_shape != out.shape:
raise operationerrfmt(space.w_ValueError,
'output parameter shape mismatch, could not broadcast [%s]' +
- ' , to [%s]',
+ ' to [%s]',
",".join([str(x) for x in w_obj.shape]),
",".join([str(x) for x in out.shape]),
)
@@ -327,11 +327,21 @@
))
new_shape = shape_agreement(space, w_lhs.shape, w_rhs.shape)
# Test correctness of out.shape
+ if out and out.shape != shape_agreement(space, new_shape, out.shape):
+ raise operationerrfmt(space.w_ValueError,
+ 'output parameter shape mismatch, could not broadcast [%s]' +
+ ' to [%s]',
+ ",".join([str(x) for x in new_shape]),
+ ",".join([str(x) for x in out.shape]),
+ )
w_res = Call2(self.func, self.name,
new_shape, calc_dtype,
res_dtype, w_lhs, w_rhs, out)
w_lhs.add_invalidates(w_res)
w_rhs.add_invalidates(w_res)
+ if out:
+ #out.add_invalidates(w_res) #causes a recursion loop
+ w_res.get_concrete()
return w_res
diff --git a/pypy/module/micronumpy/test/test_outarg.py b/pypy/module/micronumpy/test/test_outarg.py
--- a/pypy/module/micronumpy/test/test_outarg.py
+++ b/pypy/module/micronumpy/test/test_outarg.py
@@ -60,6 +60,16 @@
b = zeros((1,4))
raises(ValueError, 'negative(a, out=b)')
+ def test_binfunc_out(self):
+ from _numpypy import array, add
+ a = array([[1, 2], [3, 4]])
+ out = array([[1, 2], [3, 4]])
+ c = add(a, a, out=out)
+ assert (c == out).all()
+ assert c.shape == a.shape
+ assert c.dtype is a.dtype
+ raises(ValueError, 'c = add(a, a, out=out[1])')
+
def test_ufunc_cast(self):
from _numpypy import array, negative
cast_error = raises(TypeError, negative, array(16,dtype=float),
More information about the pypy-commit
mailing list