[pypy-svn] r66256 - in pypy/branch/pyjitpl5/pypy/module/micronumpy: . test
fijal at codespeak.net
fijal at codespeak.net
Wed Jul 15 22:27:03 CEST 2009
Author: fijal
Date: Wed Jul 15 22:27:03 2009
New Revision: 66256
Added:
pypy/branch/pyjitpl5/pypy/module/micronumpy/ (props changed)
pypy/branch/pyjitpl5/pypy/module/micronumpy/__init__.py (contents, props changed)
pypy/branch/pyjitpl5/pypy/module/micronumpy/numarray.py (contents, props changed)
pypy/branch/pyjitpl5/pypy/module/micronumpy/test/ (props changed)
pypy/branch/pyjitpl5/pypy/module/micronumpy/test/__init__.py (contents, props changed)
pypy/branch/pyjitpl5/pypy/module/micronumpy/test/test_numpy.py (contents, props changed)
Log:
A start of 'micronumpy' module. This module is supposed to provide enough
interface of numpy to show interesting properties of the jit.
Added: pypy/branch/pyjitpl5/pypy/module/micronumpy/__init__.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/module/micronumpy/__init__.py Wed Jul 15 22:27:03 2009
@@ -0,0 +1,12 @@
+
+from pypy.interpreter.mixedmodule import MixedModule
+
+class Module(MixedModule):
+
+ applevel_name = 'numpy'
+
+ interpleveldefs = {
+ 'zeros' : 'numarray.zeros',
+ }
+
+ appleveldefs = {}
Added: pypy/branch/pyjitpl5/pypy/module/micronumpy/numarray.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/module/micronumpy/numarray.py Wed Jul 15 22:27:03 2009
@@ -0,0 +1,39 @@
+
+from pypy.interpreter.baseobjspace import ObjSpace, W_Root, Wrappable
+from pypy.interpreter.error import OperationError
+from pypy.interpreter.typedef import TypeDef
+from pypy.interpreter.gateway import interp2app, NoneNotWrapped
+
+class NumArray(Wrappable):
+ def __init__(self, space, dim, dtype):
+ self.dim = dim
+ # ignore dtype for now
+ assert len(dim) == 1
+ self.storage = [0] * dim[0]
+
+ def descr_getitem(self, space, index):
+ return space.wrap(self.storage[index])
+ descr_getitem.unwrap_spec = ['self', ObjSpace, int]
+
+NumArray.typedef = TypeDef(
+ 'NumArray',
+ __getitem__ = interp2app(NumArray.descr_getitem),
+)
+
+def unpack_dim(space, w_dim):
+ if space.is_true(space.isinstance(w_dim, space.w_int)):
+ return [space.int_w(w_dim)]
+ else:
+ raise NotImplementedError
+
+def unpack_dtype(space, w_dtype):
+ if space.is_w(w_dtype, space.w_int):
+ return 'i'
+ else:
+ raise NotImplementedError
+
+def zeros(space, w_dim, w_dtype):
+ dim = unpack_dim(space, w_dim)
+ dtype = unpack_dtype(space, w_dtype)
+ return space.wrap(NumArray(space, dim, dtype))
+zeros.unwrap_spec = [ObjSpace, W_Root, W_Root]
Added: pypy/branch/pyjitpl5/pypy/module/micronumpy/test/__init__.py
==============================================================================
Added: pypy/branch/pyjitpl5/pypy/module/micronumpy/test/test_numpy.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/module/micronumpy/test/test_numpy.py Wed Jul 15 22:27:03 2009
@@ -0,0 +1,12 @@
+
+from pypy.conftest import gettestobjspace
+
+class AppTestNumpy(object):
+ def setup_class(cls):
+ cls.space = gettestobjspace(usemodules=('micronumpy',))
+
+ def test_zeroes(self):
+ from numpy import zeros
+ ar = zeros(3, dtype=int)
+ assert ar[0] == 0
+
More information about the Pypy-commit
mailing list