[pypy-svn] r66278 - in pypy/branch/pyjitpl5/pypy/module/micronumpy: . test
fijal at codespeak.net
fijal at codespeak.net
Thu Jul 16 13:49:10 CEST 2009
Author: fijal
Date: Thu Jul 16 13:49:08 2009
New Revision: 66278
Modified:
pypy/branch/pyjitpl5/pypy/module/micronumpy/numarray.py
pypy/branch/pyjitpl5/pypy/module/micronumpy/test/test_numpy.py
Log:
Support a couple more operations
Modified: pypy/branch/pyjitpl5/pypy/module/micronumpy/numarray.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/module/micronumpy/numarray.py (original)
+++ pypy/branch/pyjitpl5/pypy/module/micronumpy/numarray.py Thu Jul 16 13:49:08 2009
@@ -12,12 +12,31 @@
self.storage = [0] * dim[0]
def descr_getitem(self, space, index):
- return space.wrap(self.storage[index])
+ try:
+ return space.wrap(self.storage[index])
+ except IndexError:
+ raise OperationError(space.w_IndexError,
+ space.wrap("list index out of range"))
descr_getitem.unwrap_spec = ['self', ObjSpace, int]
+ def descr_setitem(self, space, index, value):
+ try:
+ self.storage[index] = value
+ except IndexError:
+ raise OperationError(space.w_IndexError,
+ space.wrap("list index out of range"))
+ return space.w_None
+ descr_setitem.unwrap_spec = ['self', ObjSpace, int, int]
+
+ def descr_len(self, space):
+ return space.wrap(len(self.storage))
+ descr_len.unwrap_spec = ['self', ObjSpace]
+
NumArray.typedef = TypeDef(
'NumArray',
__getitem__ = interp2app(NumArray.descr_getitem),
+ __setitem__ = interp2app(NumArray.descr_setitem),
+ __len__ = interp2app(NumArray.descr_len),
)
def unpack_dim(space, w_dim):
Modified: pypy/branch/pyjitpl5/pypy/module/micronumpy/test/test_numpy.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/module/micronumpy/test/test_numpy.py (original)
+++ pypy/branch/pyjitpl5/pypy/module/micronumpy/test/test_numpy.py Thu Jul 16 13:49:08 2009
@@ -10,3 +10,14 @@
ar = zeros(3, dtype=int)
assert ar[0] == 0
+ def test_setitem_getitem(self):
+ from numpy import zeros
+ ar = zeros(8, dtype=int)
+ assert ar[0] == 0
+ ar[1] = 3
+ assert ar[1] == 3
+ raises((TypeError, ValueError), ar.__getitem__, 'xyz')
+ raises(IndexError, ar.__getitem__, 38)
+ assert ar[-2] == 0
+ assert ar[-7] == 3
+ assert len(ar) == 8
More information about the Pypy-commit
mailing list