Author: Maciej Fijalkowski <[email protected]>
Branch: virtual-arguments
Changeset: r56229:a4da9e06f8bf
Date: 2012-07-19 18:41 +0200
http://bitbucket.org/pypy/pypy/changeset/a4da9e06f8bf/
Log: fixes for numpy
diff --git a/pypy/module/micronumpy/interp_iter.py
b/pypy/module/micronumpy/interp_iter.py
--- a/pypy/module/micronumpy/interp_iter.py
+++ b/pypy/module/micronumpy/interp_iter.py
@@ -214,6 +214,7 @@
def next(self, shapelen):
shapelen = jit.promote(len(self.res_shape))
offset = self.offset
+ assert shapelen >= 0
indices = [0] * shapelen
for i in range(shapelen):
indices[i] = self.indices[i]
@@ -241,6 +242,7 @@
def next_skip_x(self, shapelen, step):
shapelen = jit.promote(len(self.res_shape))
offset = self.offset
+ assert shapelen >= 0
indices = [0] * shapelen
for i in range(shapelen):
indices[i] = self.indices[i]
@@ -305,6 +307,7 @@
def next(self, shapelen):
offset = self.offset
first_line = self.first_line
+ assert shapelen >= 0
indices = [0] * shapelen
for i in range(shapelen):
indices[i] = self.indices[i]
@@ -342,7 +345,9 @@
class SkipLastAxisIterator(object):
def __init__(self, arr):
self.arr = arr
- self.indices = [0] * (len(arr.shape) - 1)
+ lgt = (len(arr.shape) - 1)
+ assert lgt >= 0
+ self.indices = [0] * lgt
self.done = False
self.offset = arr.start
diff --git a/pypy/module/micronumpy/interp_numarray.py
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -797,6 +797,7 @@
loop.compute(ra)
if self.res:
broadcast_dims = len(self.res.shape) - len(self.shape)
+ assert broadcast_dims >= 0
chunks = [Chunk(0,0,0,0)] * broadcast_dims + \
[Chunk(0, i, 1, i) for i in self.shape]
return Chunks(chunks).apply(self.res)
@@ -1270,10 +1271,9 @@
shapelen = len(shape)
if w_ndmin is not None and not space.is_w(w_ndmin, space.w_None):
ndmin = space.int_w(w_ndmin)
- if ndmin > shapelen:
- lgt = (ndmin - shapelen) + shape
- assert lgt >= 0
- shape = [1] * lgt
+ lgt = (ndmin - shapelen)
+ if lgt > 0:
+ shape = [1] * lgt + shape
shapelen = ndmin
arr = W_NDimArray(shape[:], dtype=dtype, order=order)
arr_iter = arr.create_iter()
diff --git a/pypy/module/micronumpy/strides.py
b/pypy/module/micronumpy/strides.py
--- a/pypy/module/micronumpy/strides.py
+++ b/pypy/module/micronumpy/strides.py
@@ -43,8 +43,12 @@
else:
rstrides.append(strides[i])
rbackstrides.append(backstrides[i])
- rstrides = [0] * (len(res_shape) - len(orig_shape)) + rstrides
- rbackstrides = [0] * (len(res_shape) - len(orig_shape)) + rbackstrides
+ lgt = (len(res_shape) - len(orig_shape))
+ assert lgt >= 0
+ rstrides = [0] * lgt + rstrides
+ lgt = (len(res_shape) - len(orig_shape))
+ assert lgt >= 0
+ rbackstrides = [0] * lgt + rbackstrides
return rstrides, rbackstrides
def is_single_elem(space, w_elem, is_rec_type):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit