Author: Maciej Fijalkowski <[email protected]>
Branch: matrixmath
Changeset: r49872:e03f83291da1
Date: 2011-11-28 08:28 +0200
http://bitbucket.org/pypy/pypy/changeset/e03f83291da1/
Log: Remove the notion of reshape/set_shape and clean up the branch
diff --git a/pypy/module/micronumpy/__init__.py
b/pypy/module/micronumpy/__init__.py
--- a/pypy/module/micronumpy/__init__.py
+++ b/pypy/module/micronumpy/__init__.py
@@ -13,6 +13,7 @@
'empty': 'interp_numarray.zeros',
'ones': 'interp_numarray.ones',
'fromstring': 'interp_support.fromstring',
+ 'flatiter': 'interp_numarray.FlatIterator',
'True_': 'space.w_True',
'False_': 'space.w_False',
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
@@ -497,43 +497,7 @@
def descr_get_shape(self, space):
return space.newtuple([space.wrap(i) for i in self.shape])
-
- def descr_set_shape(self, space, w_iterable):
- concrete = self.get_concrete()
- new_size = 0
- new_shape = []
- if not space.issequence_w(w_iterable):
- new_size = space.int_w(w_iterable)
- if new_size < 0:
- new_size = self.find_size()
- new_shape = [new_size, ]
- else:
- neg_dim = -1
- batch = space.listview(w_iterable)
- new_size = 1
- if len(batch) < 1:
- new_size = 0
- new_shape = []
- i = 0
- for elem in batch:
- s = space.int_w(elem)
- if s < 0:
- if neg_dim >= 0:
- raise OperationError(space.w_ValueError, space.wrap(
- "can only specify one unknown dimension"))
- s = 1
- neg_dim = i
- new_size *= s
- new_shape.append(s)
- i += 1
- if neg_dim >= 0:
- new_shape[neg_dim] = self.find_size() / new_size
- new_size *= new_shape[neg_dim]
- if new_size != self.find_size():
- raise OperationError(space.w_ValueError,
- space.wrap("total size of new array must be unchanged"))
- concrete.setshape(space, new_shape)
-
+
def descr_get_size(self, space):
return space.wrap(self.find_size())
@@ -789,25 +753,6 @@
return NDimSlice(self, new_sig, start, strides[:], backstrides[:],
shape[:])
- def descr_reshape(self, space, w_iterable):
- new_sig = signature.Signature.find_sig([
- NDimSlice.signature, self.signature,
- ])
- concrete = self.get_concrete()
- #concrete = self
- ndims = len(self.shape)
- strides = [0]*ndims
- backstrides = [0]*ndims
- shape = []*ndims
- for i in range(len(concrete.shape)):
- strides[i] = concrete.strides[i]
- backstrides[i] = concrete.backstrides[i]
- shape[i] = concrete.shape[i]
- arr = NDimSlice(self, new_sig, self.start, strides,
- backstrides, shape)
- arr.descr_set_shape(space, w_iterable)
- return arr
-
def descr_mean(self, space):
return space.wrap(space.float_w(self.descr_sum(space)) /
self.find_size())
@@ -1324,7 +1269,7 @@
__str__ = interp2app(BaseArray.descr_str),
dtype = GetSetProperty(BaseArray.descr_get_dtype),
- shape = GetSetProperty(BaseArray.descr_get_shape,
BaseArray.descr_set_shape),
+ shape = GetSetProperty(BaseArray.descr_get_shape),
size = GetSetProperty(BaseArray.descr_get_size),
T = GetSetProperty(BaseArray.descr_get_transpose),
@@ -1342,14 +1287,11 @@
dot = interp2app(BaseArray.descr_dot),
copy = interp2app(BaseArray.descr_copy),
- reshape = interp2app(BaseArray.descr_reshape),
)
class FlatIterator(Wrappable):
- _attrs_ = ["next"]
-
- _immutable_fields_ = ['shapelen', ]
+ _immutable_fields_ = ['shapelen', 'arr']
def __init__(self, arr):
self.arr = arr.get_concrete()
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
@@ -326,43 +326,6 @@
c = a[:3]
assert c.shape == (3,)
- def test_set_shape(self):
- from numpypy import array, zeros
- a = array([])
- a.shape = []
- a = array(range(12))
- a.shape = (3, 4)
- assert (a == [range(4), range(4, 8), range(8, 12)]).all()
- a.shape = (3, 2, 2)
- assert a[1, 1, 1] == 7
- a.shape = (3, -1, 2)
- assert a.shape == (3, 2, 2)
- a.shape = 12
- assert a.shape == (12, )
- exc = raises(ValueError, "a.shape = 10")
- assert str(exc.value) == "total size of new array must be unchanged"
- def test_reshape(self):
- from numpypy import array, zeros
- a = array(range(12))
- exc = raises(ValueError, "b = a.reshape((3, 10))")
- assert str(exc.value) == "total size of new array must be unchanged"
- b = a.reshape((3, 4))
- assert (b == [range(4), range(4, 8), range(8, 12)]).all()
- b[:, 0] = 1000
- assert (a == [1000, 1, 2, 3, 1000, 5, 6, 7, 1000, 9, 10, 11]).all()
- a = zeros((4, 2, 3))
- a.shape = (12, 2)
- def test_slice_reshape(self):
- from numpypy import array, zeros
- a = array(range(12))
- b = a[::2, :, :]
- b.shape = (2,6)
- exc = raises(AttributeError, "b.shape = 12")
- assert str(exc.value) == \
- "incompatible shape for a non-contiguous array"
- b.shape = (2, 6)
- a = array(range(12))
-
def test_add(self):
from numpypy import array
a = array(range(5))
@@ -991,7 +954,7 @@
a = array(range(5))
b = a.T
assert(b == range(5)).all()
- a = numpypy.array((range(10), range(20, 30)))
+ a = array((range(10), range(20, 30)))
b = a.T
assert(b[:, 0] == a[0, :]).all()
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit