Author: mattip <matti.pi...@gmail.com>
Branch: nditer-revisited
Changeset: r78677:bfac28c76c83
Date: 2015-07-26 23:32 +0300
http://bitbucket.org/pypy/pypy/changeset/bfac28c76c83/

Log:    do not buffer output arrays, fix exception formatting

diff --git a/pypy/module/micronumpy/nditer.py b/pypy/module/micronumpy/nditer.py
--- a/pypy/module/micronumpy/nditer.py
+++ b/pypy/module/micronumpy/nditer.py
@@ -424,8 +424,15 @@
                     self.seq[i] = W_NDimArray.from_shape(space, self.shape, 
out_dtype)
                 else:
                     if not self.op_flags[i].broadcast:
-                        # Raises if ooutput cannot be broadcast
-                        shape_agreement(space, self.shape, self.seq[i], False)
+                        # Raises if output cannot be broadcast
+                        try:
+                            shape_agreement(space, self.shape, self.seq[i], 
False)
+                        except OperationError as e:
+                            raise oefmt(space.w_ValueError, "non-broadcastable"
+                                " output operand with shape %s doesn't match "
+                                "the broadcast shape %s", 
+                                str(self.seq[i].get_shape()),
+                                str(self.shape)) 
 
         if self.tracked_index != "":
             if self.order == "K":
@@ -474,7 +481,10 @@
                                     space.str_w(seq_d.descr_repr(space)),
                                     i, self.casting)
         elif self.buffered:
-            self.seq = [s.descr_copy(space, w_order=space.wrap(self.order)) 
for s in self.seq]
+            for i in range(len(self.seq)):
+                if i not in outargs:
+                    self.seq[i] = self.seq[i].descr_copy(space,
+                                     w_order=space.wrap(self.order))
             self.dtypes = [s.get_dtype() for s in self.seq]
         else:
             #copy them from seq
diff --git a/pypy/module/micronumpy/test/test_nditer.py 
b/pypy/module/micronumpy/test/test_nditer.py
--- a/pypy/module/micronumpy/test/test_nditer.py
+++ b/pypy/module/micronumpy/test/test_nditer.py
@@ -229,7 +229,6 @@
         assert str(exc.value).startswith("Iterator operand 0 dtype could not 
be cast")
         r = []
         b = arange(6)
-        print 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
         exc = raises(TypeError, nditer, b, flags=['buffered'], 
op_dtypes=['float64'],
                                 op_flags=['readwrite'], casting='same_kind')
         assert str(exc.value).startswith("Iterator requested dtype could not 
be cast")
@@ -259,9 +258,6 @@
             return it.operands[1]
         assert (square1([1, 2, 3]) == [1, 4, 9]).all()
 
-        if '__pypy__' in sys.builtin_module_names:
-            raises(NotImplementedError, nditer, [1, 2], flags=['buffered'])
-            skip('nditer buffered not implmented')
         def square2(a, out=None):
             it = nditer([a, out], flags=['external_loop', 'buffered'],
                         op_flags=[['readonly'],
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to