Author: Alex Gaynor <[email protected]>
Branch: numpy-dtype-alt
Changeset: r46647:25d4e78f0948
Date: 2011-08-19 12:31 -0500
http://bitbucket.org/pypy/pypy/changeset/25d4e78f0948/
Log: It RTypes. Doesn't fully translate because I broke some JitDrivers,
but small potatos!
diff --git a/pypy/module/micronumpy/interp_dtype.py
b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -6,6 +6,7 @@
from pypy.interpreter.typedef import TypeDef, interp_attrproperty
from pypy.objspace.std.floatobject import float2string
from pypy.rlib import rfloat
+from pypy.rlib.rarithmetic import widen
from pypy.rlib.objectmodel import specialize, enforceargs
from pypy.rlib.unroll import unrolling_iterable
from pypy.rpython.lltypesystem import lltype, llmemory, rffi
@@ -97,9 +98,6 @@
def adapt_val(self, val):
return self.box(rffi.cast(TP.TO.OF, val))
- def str_format(self, item):
- return str(self.unbox(item))
-
W_LowLevelDtype.__name__ = "W_%sDtype" % name.capitalize()
W_LowLevelDtype.num = num
W_LowLevelDtype.kind = kind
@@ -213,6 +211,11 @@
def bool(self, v):
return bool(self.unbox(v))
+class IntegerArithmeticDtype(object):
+ _mixin_ = True
+
+ def str_format(self, item):
+ return str(widen(self.unbox(item)))
W_BoolDtype = create_low_level_dtype(
num = 0, kind = BOOLLTR, name = "bool",
@@ -225,6 +228,9 @@
def unwrap(self, space, w_item):
return self.adapt_val(space.is_true(w_item))
+ def str_format(self, item):
+ return str(self.unbox(item))
+
@binop
def add(self, v1, v2):
return bool(int(v1) + int(v2))
@@ -236,7 +242,7 @@
T = rffi.SIGNEDCHAR,
valtype = rffi.SIGNEDCHAR._type,
)
-class W_Int8Dtype(W_Int8Dtype):
+class W_Int8Dtype(IntegerArithmeticDtype, W_Int8Dtype):
def unwrap(self, space, w_item):
return self.adapt_val(space.int_w(space.int(w_item)))
@@ -247,7 +253,7 @@
T = rffi.INT,
valtype = rffi.INT._type,
)
-class W_Int32Dtype(W_Int32Dtype):
+class W_Int32Dtype(IntegerArithmeticDtype, W_Int32Dtype):
def unwrap(self, space, w_item):
return self.adapt_val(space.int_w(space.int(w_item)))
@@ -258,7 +264,7 @@
T = rffi.LONGLONG,
valtype = rffi.LONGLONG._type,
)
-class W_Int64Dtype(W_Int64Dtype):
+class W_Int64Dtype(IntegerArithmeticDtype, W_Int64Dtype):
def unwrap(self, space, w_item):
return self.adapt_val(space.int_w(space.int(w_item)))
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
@@ -15,7 +15,7 @@
numpy_driver = jit.JitDriver(greens = ['signature'],
reds = ['result_size', 'i', 'self', 'result'])
-all_driver = jit.JitDriver(greens=['signature'], reds=['i', 'size', 'self'])
+all_driver = jit.JitDriver(greens=['signature'], reds=['i', 'size', 'self',
'dtype'])
any_driver = jit.JitDriver(greens=['signature'], reds=['i', 'size', 'self'])
slice_driver1 = jit.JitDriver(greens=['signature'], reds=['i', 'j', 'step',
'stop', 'source', 'dest'])
slice_driver2 = jit.JitDriver(greens=['signature'], reds=['i', 'j', 'step',
'stop', 'source', 'dest'])
@@ -157,7 +157,7 @@
dtype = self.find_dtype()
i = 0
while i < size:
- all_driver.jit_merge_point(signature=self.signature, self=self,
size=size, i=i)
+ all_driver.jit_merge_point(signature=self.signature, self=self,
dtype=dtype, size=size, i=i)
if not dtype.bool(self.eval(i)):
return False
i += 1
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
@@ -77,11 +77,15 @@
assert str((2*a)[:]) == "[0.0 2.0 4.0 6.0 8.0]"
a = zeros(1001)
assert str(a) == "[0.0 0.0 0.0 ..., 0.0 0.0 0.0]"
- a = array(range(5), long)
+
+ a = array(range(5), dtype=long)
assert str(a) == "[0 1 2 3 4]"
- a = array([True, False, True, False], "?")
+ a = array([True, False, True, False], dtype="?")
assert str(a) == "[True False True False]"
+ a = array(range(5), dtype="int8")
+ assert str(a) == "[0 1 2 3 4]"
+
def test_str_slice(self):
from numpy import array, zeros
a = array(range(5))
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit