[pypy-commit] pypy default: whitespace and other small codecleanups
alex_gaynor
noreply at buildbot.pypy.org
Tue Dec 6 19:38:36 CET 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r50217:1a419a40ed62
Date: 2011-12-06 13:38 -0500
http://bitbucket.org/pypy/pypy/changeset/1a419a40ed62/
Log: whitespace and other small codecleanups
diff --git a/pypy/module/micronumpy/app_numpy.py b/pypy/module/micronumpy/app_numpy.py
--- a/pypy/module/micronumpy/app_numpy.py
+++ b/pypy/module/micronumpy/app_numpy.py
@@ -37,10 +37,11 @@
i += step
return arr
+
def reshape(a, shape):
'''reshape(a, newshape)
Gives a new shape to an array without changing its data.
-
+
Parameters
----------
a : array_like
@@ -50,21 +51,21 @@
an integer, then the result will be a 1-D array of that length.
One shape dimension can be -1. In this case, the value is inferred
from the length of the array and remaining dimensions.
-
+
Returns
-------
reshaped_array : ndarray
This will be a new view object if possible; otherwise, it will
be a copy.
-
-
+
+
See Also
--------
ndarray.reshape : Equivalent method.
-
+
Notes
-----
-
+
It is not always possible to change the shape of an array without
copying the data. If you want an error to be raise if the data is copied,
you should assign the new shape to the shape attribute of the array
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
@@ -105,17 +105,17 @@
new_size = space.int_w(w_iterable)
if new_size < 0:
new_size = old_size
- new_shape = [new_size, ]
+ new_shape = [new_size]
else:
neg_dim = -1
batch = space.listview(w_iterable)
- #Allow for shape = (1,2,3) or shape = ((1,2,3))
+ # Allow for shape = (1,2,3) or shape = ((1,2,3),)
if len(batch) > 1 and space.issequence_w(batch[0]):
batch = space.listview(batch[0])
new_size = 1
if len(batch) < 1:
if old_size == 1:
- #Scalars can have an empty size.
+ # Scalars can have an empty size.
new_size = 1
else:
new_size = 0
@@ -140,16 +140,16 @@
space.wrap("total size of new array must be unchanged"))
return new_shape
-#Recalculating strides. Find the steps that the iteration does for each
-#dimension, given the stride and shape. Then try to create a new stride that
-#fits the new shape, using those steps. If there is a shape/step mismatch
-#(meaning that the realignment of elements crosses from one step into another)
-#return None so that the caller can raise an exception.
+# Recalculating strides. Find the steps that the iteration does for each
+# dimension, given the stride and shape. Then try to create a new stride that
+# fits the new shape, using those steps. If there is a shape/step mismatch
+# (meaning that the realignment of elements crosses from one step into another)
+# return None so that the caller can raise an exception.
def calc_new_strides(new_shape, old_shape, old_strides):
- #Return the proper strides for new_shape, or None
- # if the mapping crosses stepping boundaries
+ # Return the proper strides for new_shape, or None if the mapping crosses
+ # stepping boundaries
- #Assumes that prod(old_shape) ==prod(new_shape), len(old_shape) > 1 and
+ # Assumes that prod(old_shape) == prod(new_shape), len(old_shape) > 1, and
# len(new_shape) > 0
steps = []
last_step = 1
@@ -589,7 +589,7 @@
def descr_set_shape(self, space, w_iterable):
concrete = self.get_concrete()
- new_shape = get_shape_from_iterable(space,
+ new_shape = get_shape_from_iterable(space,
concrete.find_size(), w_iterable)
concrete.setshape(space, new_shape)
@@ -848,25 +848,26 @@
def descr_reshape(self, space, w_args):
"""reshape(...)
a.reshape(shape)
-
+
Returns an array containing the same data with a new shape.
-
- Refer to `%s.reshape` for full documentation.
-
+
+ Refer to `numpypy.reshape` for full documentation.
+
See Also
--------
- numpy.reshape : equivalent function
-""" % 'numpypy'
+ numpypy.reshape : equivalent function
+"""
concrete = self.get_concrete()
- new_shape = get_shape_from_iterable(space,
+ new_shape = get_shape_from_iterable(space,
concrete.find_size(), w_args)
- #Since we got to here, prod(new_shape) == self.size
- new_strides = calc_new_strides(new_shape,
+ # Since we got to here, prod(new_shape) == self.size
+ new_strides = calc_new_strides(new_shape,
concrete.shape, concrete.strides)
if new_strides:
- #We can create a view, strides somehow match up.
+ # We can create a view, strides somehow match up.
new_sig = signature.Signature.find_sig([
- W_NDimSlice.signature, self.signature, ])
+ W_NDimSlice.signature, self.signature
+ ])
ndims = len(new_shape)
new_backstrides = [0] * ndims
for nd in range(ndims):
@@ -874,7 +875,7 @@
arr = W_NDimSlice(self, new_sig, self.start, new_strides,
new_backstrides, new_shape)
else:
- #Create copy with contiguous data
+ # Create copy with contiguous data
arr = concrete.copy()
arr.setshape(space, new_shape)
return arr
@@ -975,7 +976,7 @@
return 'Scalar'
def setshape(self, space, new_shape):
- # In order to get here, we already checked that prod(new_shape)==1,
+ # In order to get here, we already checked that prod(new_shape) == 1,
# so in order to have a consistent API, let it go through.
pass
@@ -1175,8 +1176,8 @@
if len(self.shape) < 1:
return
elif len(self.shape) < 2:
- #TODO: this code could be refactored into calc_strides
- #but then calc_strides would have to accept a stepping factor
+ # TODO: this code could be refactored into calc_strides
+ # but then calc_strides would have to accept a stepping factor
strides = []
backstrides = []
s = self.strides[0]
diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -408,18 +408,19 @@
u = v.reshape(64)
assert y[1, 2, 1] == z[5, 1]
y[1, 2, 1] = 1000
- #z, y, w, v are views of eachother
+ # z, y, w, v are views of eachother
assert z[5, 1] == 1000
assert v[1, 1, 1] == 1000
assert w[41] == 1000
- #u is not a view, it is a copy!
+ # u is not a view, it is a copy!
assert u[25] == 41
def test_reshape_varargs(self):
- skip("How do I do varargs in rpython? reshape should accept a"
- " variable number of arguments")
+ skip("unimplemented yet")
+ from numpypy import arange
z = arange(96).reshape(12, -1)
y = z.reshape(4, 3, 8)
+ assert y.shape == (4, 3, 8)
def test_add(self):
from numpypy import array
diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -185,8 +185,7 @@
# sure it was optimized correctly.
# XXX the comment above is wrong now. We need preferrably a way to
# count the two loops separately
- py.test.skip("counting exact number of classes is nonsense")
- self.check_resops({'setarrayitem_raw': 4, 'guard_nonnull': 1, 'getfield_gc': 35,
+ self.check_resops({'setinteriorfield_raw': 4, 'guard_nonnull': 1, 'getfield_gc': 41,
'guard_class': 22, 'int_add': 8, 'float_mul': 2,
'guard_isnull': 2, 'jump': 4, 'int_ge': 4,
'getinteriorfield_raw': 4, 'float_add': 2, 'guard_false': 4,
More information about the pypy-commit
mailing list