Author: Maciej Fijalkowski <[email protected]>
Branch: matrixmath
Changeset: r49870:7091e3500552
Date: 2011-11-28 08:21 +0200
http://bitbucket.org/pypy/pypy/changeset/7091e3500552/
Log: merge
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
@@ -227,7 +227,7 @@
self.strides = []
self.backstrides = []
for i in range(len(arr.shape)):
- if arr.shape[i]==1:
+ if arr.shape[i] == 1:
self.strides.append(0)
self.backstrides.append(0)
else:
@@ -721,6 +721,9 @@
def descr_getitem(self, space, w_idx):
if self._single_item_result(space, w_idx):
concrete = self.get_concrete()
+ if len(concrete.shape) < 1:
+ raise OperationError(space.w_IndexError, space.wrap(
+ "0-d arrays can't be indexed"))
item = concrete._index_of_single_item(space, w_idx)
return concrete.getitem(item).wrap(space)
chunks = self._prepare_slice_args(space, w_idx)
@@ -730,6 +733,9 @@
self.invalidated()
concrete = self.get_concrete()
if self._single_item_result(space, w_idx):
+ if len(concrete.shape) < 1:
+ raise OperationError(space.w_IndexError, space.wrap(
+ "0-d arrays can't be indexed"))
item = concrete._index_of_single_item(space, w_idx)
concrete.setitem_w(space, item, w_value)
return
@@ -816,17 +822,20 @@
self.start_iter(self.shape)).wrap(space)))
def descr_get_transpose(self, space):
+ concrete = self.get_concrete()
+ if len(concrete.shape) < 2:
+ return space.wrap(self)
new_sig = signature.Signature.find_sig([
NDimSlice.signature, self.signature
])
strides = []
backstrides = []
shape = []
- for i in range(len(self.shape) - 1, -1, -1):
- strides.append(self.strides[i])
- backstrides.append(self.backstrides[i])
- shape.append(self.shape[i])
- return space.wrap(NDimSlice(self, new_sig, self.start, strides[:],
+ for i in range(len(concrete.shape) - 1, -1, -1):
+ strides.append(concrete.strides[i])
+ backstrides.append(concrete.backstrides[i])
+ shape.append(concrete.shape[i])
+ return space.wrap(NDimSlice(concrete, new_sig, self.start, strides[:],
backstrides[:], shape[:]))
def descr_get_flatiter(self, space):
@@ -869,7 +878,7 @@
self.value = value
def find_size(self):
- raise ValueError
+ return 1
def get_concrete(self):
return self
@@ -878,7 +887,7 @@
return self.dtype
def getitem(self, item):
- return self.value
+ raise NotImplementedError
def eval(self, iter):
return self.value
@@ -889,8 +898,6 @@
def to_str(self, space, comma, builder, indent=' ', use_ellipsis=False):
builder.append(self.dtype.str_format(self.value))
- def setshape(self, space, new_shape):
- pass
class VirtualArray(BaseArray):
"""
@@ -1339,7 +1346,9 @@
)
def descr_new_flatiter(space, w_object):
- assert isinstance(w_object,BaseArray)
+ if not isinstance(w_object, BaseArray):
+ raise OperationError(space.w_TypeError, space.wrap(
+ "cannot create 'numpypy.flatiter' instances"))
i = FlatIterator(w_object)
return i
@@ -1356,11 +1365,11 @@
def descr_next(self, space):
if self.iter.done():
- raise OperationError(space.w_StopIteration,space.wrap(''))
+ raise OperationError(space.w_StopIteration, space.wrap(''))
retVal = self.arr.eval(self.iter)
self.iter = self.iter.next(self.shapelen)
return retVal.wrap(space)
-
+
FlatIterator.typedef = TypeDef(
'flatiter',
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
@@ -214,9 +214,11 @@
from numpypy import array
a = array(range(5))
assert a[3] == 3
- a = array(1)
- assert a[0] == 1
- assert a.shape == ()
+ #Wrong on two counts: numpy does not allow assigning to Scalar,
+ # and Scalar.shape is not a test of iterator_init, is it?
+ #a = array(1)
+ #assert a[0] == 1
+ #assert a.shape == ()
def test_getitem(self):
from numpypy import array
@@ -304,7 +306,10 @@
def test_scalar(self):
from numpypy import array
a = array(3)
- assert a[0] == 3
+ #assert a[0] == 3
+ raises(IndexError, "a[0]")
+ assert a.size == 1
+ assert a.shape == ()
def test_len(self):
from numpypy import array
@@ -983,16 +988,23 @@
assert(b[0, :, 0] == [0, 3]).all()
b[:, 0, 0] = 1000
assert(a[0, 0, :] == [1000, 1000, 1000]).all()
+ a = array(range(5))
+ b = a.T
+ assert(b == range(5)).all()
+ a = numpypy.array((range(10), range(20, 30)))
+ b = a.T
+ assert(b[:, 0] == a[0, :]).all()
def test_flatiter(self):
- from numpypy import array
- a = array([[10,30],[40,60]])
+ from numpypy import array, flatiter
+ a = array([[10, 30], [40, 60]])
f_iter = a.flat
assert f_iter.next() == 10
assert f_iter.next() == 30
assert f_iter.next() == 40
assert f_iter.next() == 60
raises(StopIteration, "f_iter.next()")
+ raises(TypeError, "flatiter()")
class AppTestSupport(object):
@@ -1117,7 +1129,7 @@
assert a.dtype is dtype(int)
a = arange(3, 7, 2)
assert (a == [3, 5]).all()
- a = arange(3,dtype=float)
+ a = arange(3, dtype=float)
assert (a == [0., 1., 2.]).all()
assert a.dtype is dtype(float)
a = arange(0, 0.8, 0.1)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit