[pypy-commit] pypy default: cleanups
bdkearns
noreply at buildbot.pypy.org
Fri Feb 28 00:41:14 CET 2014
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r69527:88373c4f78f1
Date: 2014-02-27 18:33 -0500
http://bitbucket.org/pypy/pypy/changeset/88373c4f78f1/
Log: cleanups
diff --git a/pypy/module/micronumpy/concrete.py b/pypy/module/micronumpy/concrete.py
--- a/pypy/module/micronumpy/concrete.py
+++ b/pypy/module/micronumpy/concrete.py
@@ -8,7 +8,7 @@
from pypy.module.micronumpy import support, loop
from pypy.module.micronumpy.base import convert_to_array, W_NDimArray, \
ArrayArgumentException
-from pypy.module.micronumpy.iterators import ArrayIterator, AxisIterator
+from pypy.module.micronumpy.iterators import ArrayIter
from pypy.module.micronumpy.strides import (Chunk, Chunks, NewAxisChunk,
RecordChunk, calc_strides, calc_new_strides, shape_agreement,
calculate_broadcast_strides, calculate_dot_strides)
@@ -284,19 +284,14 @@
self.get_backstrides(),
self.get_shape(), shape,
backward_broadcast)
- return ArrayIterator(self, support.product(shape), shape,
- r[0], r[1])
- return ArrayIterator(self, self.get_size(), self.shape,
- self.strides, self.backstrides)
-
- def create_axis_iter(self, shape, dim, cum):
- return AxisIterator(self, shape, dim, cum)
+ return ArrayIter(self, support.product(shape), shape, r[0], r[1])
+ return ArrayIter(self, self.get_size(), self.shape,
+ self.strides, self.backstrides)
def create_dot_iter(self, shape, skip):
r = calculate_dot_strides(self.get_strides(), self.get_backstrides(),
shape, skip)
- return ArrayIterator(self, support.product(shape), shape,
- r[0], r[1])
+ return ArrayIter(self, support.product(shape), shape, r[0], r[1])
def swapaxes(self, space, orig_arr, axis1, axis2):
shape = self.get_shape()[:]
diff --git a/pypy/module/micronumpy/iterators.py b/pypy/module/micronumpy/iterators.py
--- a/pypy/module/micronumpy/iterators.py
+++ b/pypy/module/micronumpy/iterators.py
@@ -45,7 +45,7 @@
from pypy.module.micronumpy.base import W_NDimArray
-class PureShapeIterator(object):
+class PureShapeIter(object):
def __init__(self, shape, idx_w):
self.shape = shape
self.shapelen = len(shape)
@@ -78,7 +78,7 @@
return [space.wrap(self.indexes[i]) for i in range(shapelen)]
-class ArrayIterator(object):
+class ArrayIter(object):
_immutable_fields_ = ['array', 'size', 'ndim_m1', 'shape_m1',
'strides', 'backstrides']
@@ -141,7 +141,7 @@
self.array.setitem(self.offset, elem)
-def AxisIterator(array, shape, axis, cumulative):
+def AxisIter(array, shape, axis, cumulative):
strides = array.get_strides()
backstrides = array.get_backstrides()
if not cumulative:
@@ -152,14 +152,14 @@
else:
strides = strides[:axis] + [0] + strides[axis:]
backstrides = backstrides[:axis] + [0] + backstrides[axis:]
- return ArrayIterator(array, support.product(shape), shape, strides, backstrides)
+ return ArrayIter(array, support.product(shape), shape, strides, backstrides)
-def AllButAxisIterator(array, axis):
+def AllButAxisIter(array, axis):
size = array.get_size()
shape = array.get_shape()[:]
backstrides = array.backstrides[:]
if size:
size /= shape[axis]
shape[axis] = backstrides[axis] = 0
- return ArrayIterator(array, size, shape, array.strides, backstrides)
+ return ArrayIter(array, size, shape, array.strides, backstrides)
diff --git a/pypy/module/micronumpy/loop.py b/pypy/module/micronumpy/loop.py
--- a/pypy/module/micronumpy/loop.py
+++ b/pypy/module/micronumpy/loop.py
@@ -8,7 +8,7 @@
from rpython.rtyper.lltypesystem import lltype, rffi
from pypy.module.micronumpy import support, constants as NPY
from pypy.module.micronumpy.base import W_NDimArray
-from pypy.module.micronumpy.iterators import PureShapeIterator
+from pypy.module.micronumpy.iterators import PureShapeIter, AxisIter
call2_driver = jit.JitDriver(name='numpy_call2',
@@ -203,9 +203,9 @@
def do_axis_reduce(space, shape, func, arr, dtype, axis, out, identity, cumulative,
temp):
- out_iter = out.create_axis_iter(arr.get_shape(), axis, cumulative)
+ out_iter = AxisIter(out.implementation, arr.get_shape(), axis, cumulative)
if cumulative:
- temp_iter = temp.create_axis_iter(arr.get_shape(), axis, False)
+ temp_iter = AxisIter(temp.implementation, arr.get_shape(), axis, False)
else:
temp_iter = out_iter # hack
arr_iter = arr.create_iter()
@@ -286,9 +286,9 @@
right_skip = range(len(left_shape) - 1)
result_skip = [len(result.get_shape()) - (len(right_shape) > 1)]
assert result.get_dtype() == dtype
- outi = result.create_dot_iter(broadcast_shape, result_skip)
- lefti = left.create_dot_iter(broadcast_shape, left_skip)
- righti = right.create_dot_iter(broadcast_shape, right_skip)
+ outi = result.implementation.create_dot_iter(broadcast_shape, result_skip)
+ lefti = left.implementation.create_dot_iter(broadcast_shape, left_skip)
+ righti = right.implementation.create_dot_iter(broadcast_shape, right_skip)
while not outi.done():
dot_driver.jit_merge_point(dtype=dtype)
lval = lefti.getitem().convert_to(space, dtype)
@@ -476,7 +476,7 @@
prefixlen = len(prefix_w)
indexlen = len(indexes_w)
dtype = arr.get_dtype()
- iter = PureShapeIterator(iter_shape, indexes_w)
+ iter = PureShapeIter(iter_shape, indexes_w)
indexlen = len(indexes_w)
while not iter.done():
getitem_int_driver.jit_merge_point(shapelen=shapelen, indexlen=indexlen,
@@ -505,7 +505,7 @@
indexlen = len(indexes_w)
prefixlen = len(prefix_w)
dtype = arr.get_dtype()
- iter = PureShapeIterator(iter_shape, indexes_w)
+ iter = PureShapeIter(iter_shape, indexes_w)
while not iter.done():
setitem_int_driver.jit_merge_point(shapelen=shapelen, indexlen=indexlen,
dtype=dtype, prefixlen=prefixlen)
@@ -630,7 +630,7 @@
def diagonal_array(space, arr, out, offset, axis1, axis2, shape):
out_iter = out.create_iter()
- iter = PureShapeIterator(shape, [])
+ iter = PureShapeIter(shape, [])
shapelen_minus_1 = len(shape) - 1
assert shapelen_minus_1 >= 0
if axis1 < axis2:
diff --git a/pypy/module/micronumpy/ndarray.py b/pypy/module/micronumpy/ndarray.py
--- a/pypy/module/micronumpy/ndarray.py
+++ b/pypy/module/micronumpy/ndarray.py
@@ -286,12 +286,6 @@
return self.implementation.create_iter(
shape=shape, backward_broadcast=backward_broadcast)
- def create_axis_iter(self, shape, dim, cum):
- return self.implementation.create_axis_iter(shape, dim, cum)
-
- def create_dot_iter(self, shape, skip):
- return self.implementation.create_dot_iter(shape, skip)
-
def is_scalar(self):
return len(self.get_shape()) == 0
diff --git a/pypy/module/micronumpy/sort.py b/pypy/module/micronumpy/sort.py
--- a/pypy/module/micronumpy/sort.py
+++ b/pypy/module/micronumpy/sort.py
@@ -8,7 +8,7 @@
from rpython.rtyper.lltypesystem import rffi, lltype
from pypy.module.micronumpy import descriptor, types, constants as NPY
from pypy.module.micronumpy.base import W_NDimArray
-from pypy.module.micronumpy.iterators import AllButAxisIterator
+from pypy.module.micronumpy.iterators import AllButAxisIter
INT_SIZE = rffi.sizeof(lltype.Signed)
@@ -148,9 +148,9 @@
if axis < 0 or axis >= len(shape):
raise OperationError(space.w_IndexError, space.wrap(
"Wrong axis %d" % axis))
- arr_iter = AllButAxisIterator(arr, axis)
+ arr_iter = AllButAxisIter(arr, axis)
index_impl = index_arr.implementation
- index_iter = AllButAxisIterator(index_impl, axis)
+ index_iter = AllButAxisIter(index_impl, axis)
stride_size = arr.strides[axis]
index_stride_size = index_impl.strides[axis]
axis_size = arr.shape[axis]
@@ -293,7 +293,7 @@
if axis < 0 or axis >= len(shape):
raise OperationError(space.w_IndexError, space.wrap(
"Wrong axis %d" % axis))
- arr_iter = AllButAxisIterator(arr, axis)
+ arr_iter = AllButAxisIter(arr, axis)
stride_size = arr.strides[axis]
axis_size = arr.shape[axis]
while not arr_iter.done():
diff --git a/pypy/module/micronumpy/test/test_iterators.py b/pypy/module/micronumpy/test/test_iterators.py
--- a/pypy/module/micronumpy/test/test_iterators.py
+++ b/pypy/module/micronumpy/test/test_iterators.py
@@ -1,5 +1,5 @@
from pypy.module.micronumpy import support
-from pypy.module.micronumpy.iterators import ArrayIterator
+from pypy.module.micronumpy.iterators import ArrayIter
class MockArray(object):
@@ -14,8 +14,8 @@
strides = [5, 1]
backstrides = [x * (y - 1) for x,y in zip(strides, shape)]
assert backstrides == [10, 4]
- i = ArrayIterator(MockArray, support.product(shape), shape,
- strides, backstrides)
+ i = ArrayIter(MockArray, support.product(shape), shape,
+ strides, backstrides)
i.next()
i.next()
i.next()
@@ -33,8 +33,8 @@
strides = [1, 3]
backstrides = [x * (y - 1) for x,y in zip(strides, shape)]
assert backstrides == [2, 12]
- i = ArrayIterator(MockArray, support.product(shape), shape,
- strides, backstrides)
+ i = ArrayIter(MockArray, support.product(shape), shape,
+ strides, backstrides)
i.next()
i.next()
i.next()
@@ -54,8 +54,8 @@
strides = [5, 1]
backstrides = [x * (y - 1) for x,y in zip(strides, shape)]
assert backstrides == [10, 4]
- i = ArrayIterator(MockArray, support.product(shape), shape,
- strides, backstrides)
+ i = ArrayIter(MockArray, support.product(shape), shape,
+ strides, backstrides)
i.next_skip_x(2)
i.next_skip_x(2)
i.next_skip_x(2)
@@ -78,8 +78,8 @@
strides = [1, 3]
backstrides = [x * (y - 1) for x,y in zip(strides, shape)]
assert backstrides == [2, 12]
- i = ArrayIterator(MockArray, support.product(shape), shape,
- strides, backstrides)
+ i = ArrayIter(MockArray, support.product(shape), shape,
+ strides, backstrides)
i.next_skip_x(2)
i.next_skip_x(2)
i.next_skip_x(2)
More information about the pypy-commit
mailing list