[pypy-commit] pypy default: fixes for ulong dtype and some small other cleanups
alex_gaynor
noreply at buildbot.pypy.org
Thu Dec 15 21:40:00 CET 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r50594:2b3d72c181dd
Date: 2011-12-15 14:39 -0600
http://bitbucket.org/pypy/pypy/changeset/2b3d72c181dd/
Log: fixes for ulong dtype and some small other cleanups
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
@@ -133,7 +133,7 @@
descr__new__, get_dtype = new_dtype_getter("long")
class W_ULongBox(W_UnsignedIntegerBox, PrimitiveBox):
- pass
+ descr__new__, get_dtype = new_dtype_getter("ulong")
class W_Int64Box(W_SignedIntegerBox, PrimitiveBox):
descr__new__, get_dtype = new_dtype_getter("int64")
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
@@ -1197,10 +1197,12 @@
cls.w_fdata = cls.space.wrap(struct.pack('f', 2.3))
cls.w_float32val = cls.space.wrap(struct.pack('f', 5.2))
cls.w_float64val = cls.space.wrap(struct.pack('d', 300.4))
+ cls.w_ulongval = cls.space.wrap(struct.pack('L', 12))
def test_fromstring(self):
+ import sys
from numpypy import fromstring, array, uint8, float32, int32
- import sys
+
a = fromstring(self.data)
for i in range(4):
assert a[i] == i + 1
@@ -1261,12 +1263,11 @@
assert (u == [1]).all()
else:
assert (u == [1, 0]).all()
-
+
def test_fromstring_types(self):
- from numpypy import fromstring
- from numpypy import int8, int16, int32, int64
- from numpypy import uint8, uint16, uint32
- from numpypy import float32, float64
+ from numpypy import (fromstring, int8, int16, int32, int64, uint8,
+ uint16, uint32, float32, float64)
+
a = fromstring('\xFF', dtype=int8)
assert a[0] == -1
b = fromstring('\xFF', dtype=uint8)
@@ -1285,8 +1286,10 @@
assert h[0] == float32(5.2)
i = fromstring(self.float64val, dtype=float64)
assert i[0] == float64(300.4)
-
-
+ j = fromstring(self.ulongval, dtype='L')
+ assert j[0] == 12
+
+
def test_fromstring_invalid(self):
from numpypy import fromstring, uint16, uint8, int32
#default dtype is 64-bit float, so 3 bytes should fail
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
@@ -56,8 +56,7 @@
class Primitive(object):
_mixin_ = True
- format_code = '?'
-
+
def get_element_size(self):
return rffi.sizeof(self.T)
@@ -173,7 +172,7 @@
class Bool(BaseType, Primitive):
T = lltype.Bool
BoxType = interp_boxes.W_BoolBox
- format_code = '?'
+ format_code = "?"
True = BoxType(True)
False = BoxType(False)
@@ -202,7 +201,7 @@
def for_computation(self, v):
return int(v)
-
+
def default_fromstring(self, space):
return self.box(False)
@@ -218,7 +217,7 @@
def for_computation(self, v):
return widen(v)
-
+
def default_fromstring(self, space):
return self.box(0)
@@ -287,11 +286,12 @@
class Long(BaseType, Integer):
T = rffi.LONG
BoxType = interp_boxes.W_LongBox
- format_code = 'l'
+ format_code = "l"
class ULong(BaseType, Integer):
T = rffi.ULONG
BoxType = interp_boxes.W_ULongBox
+ format_code = "L"
class Int64(BaseType, Integer):
T = rffi.LONGLONG
More information about the pypy-commit
mailing list