[pypy-commit] pypy numpy-dtype-refactor: major progress towards translating
alex_gaynor
noreply at buildbot.pypy.org
Fri Nov 11 21:18:21 CET 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: numpy-dtype-refactor
Changeset: r49345:a86f783b009d
Date: 2011-11-11 15:18 -0500
http://bitbucket.org/pypy/pypy/changeset/a86f783b009d/
Log: major progress towards translating
diff --git a/pypy/module/micronumpy/compile.py b/pypy/module/micronumpy/compile.py
--- a/pypy/module/micronumpy/compile.py
+++ b/pypy/module/micronumpy/compile.py
@@ -177,8 +177,9 @@
def execute(self, interp):
arr = interp.variables[self.name]
- w_index = self.index.execute(interp).eval(0)
- w_val = self.expr.execute(interp).eval(0)
+ w_index = self.index.execute(interp)
+ w_val = self.expr.execute(interp)
+ assert isinstance(arr, BaseArray)
arr.descr_setitem(interp.space, w_index, w_val)
def __repr__(self):
diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -31,10 +31,14 @@
return space.wrap(self.get_dtype(space).itemtype.str_format(self))
def descr_int(self, space):
- return space.wrap(self.convert_to(W_LongBox.get_dtype(space)).value)
+ box = self.convert_to(W_LongBox.get_dtype(space))
+ assert isinstance(box, W_LongBox)
+ return space.wrap(box.value)
def descr_float(self, space):
- return space.wrap(self.convert_to(W_Float64Box.get_dtype(space)).value)
+ box = self.convert_to(W_Float64Box.get_dtype(space))
+ assert isinstance(box, W_Float64Box)
+ return space.wrap(box.value)
def _binop_impl(ufunc_name):
def impl(self, space, w_other):
@@ -71,7 +75,7 @@
pass
class W_NumberBox(W_GenericBox):
- pass
+ _attrs_ = ()
class W_IntegerBox(W_NumberBox):
pass
@@ -113,10 +117,10 @@
pass
class W_InexactBox(W_NumberBox):
- pass
+ _attrs_ = ()
class W_FloatingBox(W_InexactBox):
- pass
+ _attrs_ = ()
class W_Float32Box(W_FloatingBox, PrimitiveBox):
get_dtype = dtype_getter("float32")
diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -1,8 +1,8 @@
from pypy.jit.metainterp.test.support import LLJitMixin
-from pypy.module.micronumpy import interp_ufuncs, signature
+from pypy.module.micronumpy import interp_boxes, interp_ufuncs, signature
from pypy.module.micronumpy.compile import (FakeSpace,
FloatObject, IntObject, numpy_compile, BoolObject)
-from pypy.module.micronumpy.interp_numarray import (SingleDimArray,
+from pypy.module.micronumpy.interp_numarray import (BaseArray, SingleDimArray,
SingleDimSlice)
from pypy.rlib.nonconst import NonConstant
from pypy.rpython.annlowlevel import llstr, hlstr
@@ -15,21 +15,22 @@
class TestNumpyJIt(LLJitMixin):
graph = None
interp = None
-
+
def run(self, code):
space = FakeSpace()
-
+
def f(code):
interp = numpy_compile(hlstr(code))
interp.run(space)
res = interp.results[-1]
- w_res = res.eval(0).wrap(interp.space)
- if isinstance(w_res, BoolObject):
- return float(w_res.boolval)
- elif isinstance(w_res, FloatObject):
- return w_res.floatval
- elif isinstance(w_res, IntObject):
- return w_res.intval
+ assert isinstance(res, BaseArray)
+ w_res = res.eval(0)
+ if isinstance(w_res, interp_boxes.W_BoolBox):
+ return float(w_res.value)
+ elif isinstance(w_res, interp_boxes.W_Float64Box):
+ return w_res.value
+ elif isinstance(w_res, interp_boxes.W_LongBox):
+ return w_res.value
else:
return -42.
@@ -186,10 +187,10 @@
def setup_class(cls):
from pypy.module.micronumpy.compile import FakeSpace
from pypy.module.micronumpy.interp_dtype import W_Float64Dtype
-
+
cls.space = FakeSpace()
cls.float64_dtype = cls.space.fromcache(W_Float64Dtype)
-
+
def test_slice(self):
def f(i):
step = 3
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -3,6 +3,7 @@
from pypy.module.micronumpy import interp_boxes
from pypy.objspace.std.floatobject import float2string
from pypy.rlib import rfloat
+from pypy.rlib.objectmodel import specialize
from pypy.rlib.rarithmetic import LONG_BIT
from pypy.rpython.lltypesystem import lltype, rffi
@@ -30,6 +31,7 @@
def get_element_size(self):
return rffi.sizeof(self.T)
+ @specialize.argtype(1)
def box(self, value):
return self.BoxType(rffi.cast(self.T, value))
@@ -115,6 +117,7 @@
True = BoxType(True)
False = BoxType(False)
+ @specialize.argtype(1)
def box(self, value):
box = Primitive.box(self, value)
if box.value:
More information about the pypy-commit
mailing list