Author: Brian Kearns <[email protected]>
Branch:
Changeset: r69502:f4dcfc98a4ab
Date: 2014-02-27 05:07 -0500
http://bitbucket.org/pypy/pypy/changeset/f4dcfc98a4ab/
Log: fix array.reshape(None)
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
@@ -61,7 +61,7 @@
def get_storage_size(self):
return self.size
- def reshape(self, space, orig_array, new_shape):
+ def reshape(self, orig_array, new_shape):
# Since we got to here, prod(new_shape) == self.size
new_strides = None
if self.size > 0:
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
@@ -343,14 +343,13 @@
def reshape(self, space, w_shape):
new_shape = get_shape_from_iterable(space, self.get_size(), w_shape)
- new_impl = self.implementation.reshape(space, self, new_shape)
+ new_impl = self.implementation.reshape(self, new_shape)
if new_impl is not None:
return wrap_impl(space, space.type(self), self, new_impl)
# Create copy with contiguous data
arr = self.descr_copy(space)
if arr.get_size() > 0:
- arr.implementation = arr.implementation.reshape(space, self,
- new_shape)
+ arr.implementation = arr.implementation.reshape(self, new_shape)
assert arr.implementation
else:
arr.implementation.shape = new_shape
@@ -384,6 +383,8 @@
raise OperationError(space.w_NotImplementedError, space.wrap(
"unsupported value for order"))
if len(args_w) == 1:
+ if space.is_none(args_w[0]):
+ return self.descr_view(space)
w_shape = args_w[0]
else:
w_shape = space.newtuple(args_w)
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
@@ -125,7 +125,7 @@
# note that it's fine ot pass None here as we're not going
# to pass the result around (None is the link to base in slices)
if arr.get_size() > 0:
- arr = arr.reshape(space, None, [arr.get_size()])
+ arr = arr.reshape(None, [arr.get_size()])
axis = 0
elif w_axis is None:
axis = -1
@@ -276,7 +276,7 @@
if w_axis is space.w_None:
# note that it's fine to pass None here as we're not going
# to pass the result around (None is the link to base in slices)
- arr = arr.reshape(space, None, [arr.get_size()])
+ arr = arr.reshape(None, [arr.get_size()])
axis = 0
elif w_axis is None:
axis = -1
diff --git a/pypy/module/micronumpy/test/test_ndarray.py
b/pypy/module/micronumpy/test/test_ndarray.py
--- a/pypy/module/micronumpy/test/test_ndarray.py
+++ b/pypy/module/micronumpy/test/test_ndarray.py
@@ -844,6 +844,12 @@
b = a.reshape(s)
assert b.shape == s
assert (b == [1]).all()
+ a = array(1.5)
+ b = a.reshape(None)
+ assert b is not a
+ assert b == a
+ b[...] = 2.5
+ assert a == 2.5
a = array(range(12))
exc = raises(ValueError, "b = a.reshape(())")
assert str(exc.value) == "total size of new array must be unchanged"
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit