[pypy-commit] pypy ufuncapi: work around nditer shape issues instead of fixing nditer(opaxes=...) for now
mattip
noreply at buildbot.pypy.org
Thu Jan 15 20:55:50 CET 2015
Author: mattip <matti.picus at gmail.com>
Branch: ufuncapi
Changeset: r75361:5958b6623b29
Date: 2015-01-15 21:51 +0200
http://bitbucket.org/pypy/pypy/changeset/5958b6623b29/
Log: work around nditer shape issues instead of fixing nditer(opaxes=...)
for now
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
@@ -231,6 +231,9 @@
backstrides = imp.backstrides
r = calculate_broadcast_strides(strides, backstrides, imp.shape,
shape, backward)
+ if len(shape) != len(r[0]):
+ # shape can be shorter when using an external loop, just return a view
+ return ConcreteIter(imp, imp.get_size(), imp.shape, r[0], r[1], op_flags, base)
return ConcreteIter(imp, imp.get_size(), shape, r[0], r[1], op_flags, base)
def calculate_ndim(op_in, oa_ndim):
@@ -418,7 +421,11 @@
out_shape = shape_agreement_multiple(space, [self.seq[i] for i in outargs])
else:
out_shape = None
- self.shape = shape_agreement_multiple(space, self.seq,
+ if space.isinstance_w(w_itershape, space.w_tuple) or \
+ space.isinstance_w(w_itershape, space.w_list):
+ self.shape = [space.int_w(i) for i in space.listview(w_itershape)]
+ else:
+ self.shape = shape_agreement_multiple(space, self.seq,
shape=out_shape)
if len(outargs) > 0:
# Make None operands writeonly and flagged for allocation
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
@@ -325,6 +325,9 @@
def test_itershape(self):
# Check that allocated outputs work with a specified shape
from numpy import nditer, arange
+ import sys
+ if '__pypy__' in sys.builtin_module_names:
+ skip("op_axes not totally supported yet")
a = arange(6, dtype='i2').reshape(2,3)
i = nditer([a, None], [], [['readonly'], ['writeonly','allocate']],
op_axes=[[0,1,None], None],
diff --git a/pypy/module/micronumpy/ufuncs.py b/pypy/module/micronumpy/ufuncs.py
--- a/pypy/module/micronumpy/ufuncs.py
+++ b/pypy/module/micronumpy/ufuncs.py
@@ -890,7 +890,7 @@
if n < len(iter_shape):
#Broadcast over the len(iter_shape) - n dims of iter_shape
broadcast_dims = len(iter_shape) - n
- arg_shapes.append(iter_shape[:-broadcast_dims] + [1] * broadcast_dims + dims_to_match)
+ arg_shapes.append(iter_shape[:n] + [1] * broadcast_dims + dims_to_match)
else:
arg_shapes.append(iter_shape + dims_to_match)
# TODO once we support obejct dtypes,
More information about the pypy-commit
mailing list