[pypy-commit] pypy default: promote shape a bit everywhere
fijal
noreply at buildbot.pypy.org
Sat Oct 27 21:40:10 CEST 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch:
Changeset: r58517:f23ed5302cee
Date: 2012-10-27 21:37 +0200
http://bitbucket.org/pypy/pypy/changeset/f23ed5302cee/
Log: promote shape a bit everywhere
diff --git a/pypy/module/micronumpy/arrayimpl/concrete.py b/pypy/module/micronumpy/arrayimpl/concrete.py
--- a/pypy/module/micronumpy/arrayimpl/concrete.py
+++ b/pypy/module/micronumpy/arrayimpl/concrete.py
@@ -47,7 +47,7 @@
self.skip = array.strides[0]
self.dtype = array.dtype
self.index = 0
- self.size = array.shape[0]
+ self.size = array.get_shape()[0]
def next(self):
self.offset += self.skip
@@ -168,7 +168,9 @@
parent = None
def get_shape(self):
- return self.shape
+ shape = self.shape
+ jit.hint(shape, promote=True)
+ return shape
def getitem(self, index):
return self.dtype.getitem(self, index)
@@ -181,7 +183,7 @@
if impl.is_scalar():
self.fill(impl.get_scalar_value())
return
- shape = shape_agreement(space, self.shape, arr)
+ shape = shape_agreement(space, self.get_shape(), arr)
if impl.storage == self.storage:
impl = impl.copy()
loop.setslice(shape, self, impl)
@@ -193,7 +195,7 @@
# Since we got to here, prod(new_shape) == self.size
new_strides = None
if self.size > 0:
- new_strides = calc_new_strides(new_shape, self.shape,
+ new_strides = calc_new_strides(new_shape, self.get_shape(),
self.strides, self.order)
if new_strides:
# We can create a view, strides somehow match up.
@@ -216,10 +218,10 @@
raise IndexError
idx = int_w(space, w_index)
if idx < 0:
- idx = self.shape[i] + idx
- if idx < 0 or idx >= self.shape[i]:
+ idx = self.get_shape()[i] + idx
+ if idx < 0 or idx >= self.get_shape()[i]:
raise operationerrfmt(space.w_IndexError,
- "index (%d) out of range (0<=index<%d", i, self.shape[i],
+ "index (%d) out of range (0<=index<%d", i, self.get_shape()[i],
)
item += idx * self.strides[i]
return item
@@ -227,13 +229,14 @@
@jit.unroll_safe
def _lookup_by_unwrapped_index(self, space, lst):
item = self.start
- assert len(lst) == len(self.shape)
+ shape = self.get_shape()
+ assert len(lst) == len(shape)
for i, idx in enumerate(lst):
if idx < 0:
- idx = self.shape[i] + idx
- if idx < 0 or idx >= self.shape[i]:
+ idx = shape[i] + idx
+ if idx < 0 or idx >= shape[i]:
raise operationerrfmt(space.w_IndexError,
- "index (%d) out of range (0<=index<%d", i, self.shape[i],
+ "index (%d) out of range (0<=index<%d", i, shape[i],
)
item += idx * self.strides[i]
return item
@@ -255,7 +258,8 @@
raise IndexError
if isinstance(w_idx, W_NDimArray):
raise ArrayArgumentException
- shape_len = len(self.shape)
+ shape = self.get_shape()
+ shape_len = len(shape)
if shape_len == 0:
raise OperationError(space.w_IndexError, space.wrap(
"0-d arrays can't be indexed"))
@@ -299,7 +303,7 @@
return RecordChunk(idx)
if (space.isinstance_w(w_idx, space.w_int) or
space.isinstance_w(w_idx, space.w_slice)):
- return Chunks([Chunk(*space.decode_index4(w_idx, self.shape[0]))])
+ return Chunks([Chunk(*space.decode_index4(w_idx, self.get_shape()[0]))])
elif space.is_w(w_idx, space.w_None):
return Chunks([NewAxisChunk()])
result = []
@@ -309,7 +313,7 @@
result.append(NewAxisChunk())
else:
result.append(Chunk(*space.decode_index4(w_item,
- self.shape[i])))
+ self.get_shape()[i])))
i += 1
return Chunks(result)
@@ -333,24 +337,24 @@
view.implementation.setslice(space, w_value)
def transpose(self):
- if len(self.shape) < 2:
+ if len(self.get_shape()) < 2:
return self
strides = []
backstrides = []
shape = []
- for i in range(len(self.shape) - 1, -1, -1):
+ for i in range(len(self.get_shape()) - 1, -1, -1):
strides.append(self.strides[i])
backstrides.append(self.backstrides[i])
- shape.append(self.shape[i])
+ shape.append(self.get_shape()[i])
return SliceArray(self.start, strides,
backstrides, shape, self)
def copy(self):
- strides, backstrides = support.calc_strides(self.shape, self.dtype,
+ strides, backstrides = support.calc_strides(self.get_shape(), self.dtype,
self.order)
- impl = ConcreteArray(self.shape, self.dtype, self.order, strides,
+ impl = ConcreteArray(self.get_shape(), self.dtype, self.order, strides,
backstrides)
- return loop.setslice(self.shape, impl, self)
+ return loop.setslice(self.get_shape(), impl, self)
def create_axis_iter(self, shape, dim):
return AxisIterator(self, shape, dim)
@@ -361,7 +365,7 @@
return MultiDimViewIterator(self, self.start, r[0], r[1], shape)
def swapaxes(self, axis1, axis2):
- shape = self.shape[:]
+ shape = self.get_shape()[:]
strides = self.strides[:]
backstrides = self.backstrides[:]
shape[axis1], shape[axis2] = shape[axis2], shape[axis1]
@@ -384,10 +388,10 @@
self.backstrides = backstrides
def create_iter(self, shape):
- if shape == self.shape:
+ if shape == self.get_shape():
return ConcreteArrayIterator(self)
r = calculate_broadcast_strides(self.strides, self.backstrides,
- self.shape, shape)
+ self.get_shape(), shape)
return MultiDimViewIterator(self, 0, r[0], r[1], shape)
def fill(self, box):
@@ -421,18 +425,18 @@
loop.fill(self, box.convert_to(self.dtype))
def create_iter(self, shape):
- if shape != self.shape:
+ if shape != self.get_shape():
r = calculate_broadcast_strides(self.strides, self.backstrides,
- self.shape, shape)
+ self.get_shape(), shape)
return MultiDimViewIterator(self.parent,
self.start, r[0], r[1], shape)
- if len(self.shape) == 1:
+ if len(self.get_shape()) == 1:
return OneDimViewIterator(self)
return MultiDimViewIterator(self.parent, self.start, self.strides,
- self.backstrides, self.shape)
+ self.backstrides, self.get_shape())
def set_shape(self, space, new_shape):
- if len(self.shape) < 2 or self.size == 0:
+ if len(self.get_shape()) < 2 or self.size == 0:
# TODO: this code could be refactored into calc_strides
# but then calc_strides would have to accept a stepping factor
strides = []
@@ -451,7 +455,7 @@
new_shape.reverse()
return SliceArray(self.start, strides, backstrides, new_shape,
self)
- new_strides = calc_new_strides(new_shape, self.shape, self.strides,
+ new_strides = calc_new_strides(new_shape, self.get_shape(), self.strides,
self.order)
if new_strides is None:
raise OperationError(space.w_AttributeError, space.wrap(
More information about the pypy-commit
mailing list