[pypy-commit] pypy default: uint8 support
hakanardo
noreply at buildbot.pypy.org
Thu Sep 8 14:29:56 CEST 2011
Author: Hakan Ardo <hakan at debian.org>
Branch:
Changeset: r47160:12d91e2900e9
Date: 2011-09-08 14:29 +0200
http://bitbucket.org/pypy/pypy/changeset/12d91e2900e9/
Log: uint8 support
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
@@ -317,6 +317,17 @@
class W_Int8Dtype(IntegerArithmeticDtype, W_Int8Dtype):
pass
+W_UInt8Dtype = create_low_level_dtype(
+ num = 1, kind = SIGNEDLTR, name = "uint8",
+ aliases = ["uint8"],
+ applevel_types = [],
+ T = rffi.UCHAR,
+ valtype = rffi.UCHAR._type,
+ expected_size = 1,
+)
+class W_UInt8Dtype(IntegerArithmeticDtype, W_UInt8Dtype):
+ pass
+
W_Int16Dtype = create_low_level_dtype(
num = 3, kind = SIGNEDLTR, name = "int16",
aliases = ["int16"],
@@ -368,6 +379,7 @@
ALL_DTYPES = [
W_BoolDtype,
W_Int8Dtype, W_Int16Dtype, W_Int32Dtype, W_Int64Dtype,
+ W_UInt8Dtype,
W_Float64Dtype
]
diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -12,6 +12,7 @@
assert dtype(d) is d
assert dtype(None) is dtype(float)
raises(TypeError, dtype, 1042)
+ assert dtype('uint8').num == 1
def test_dtype_with_types(self):
from numpy import dtype
@@ -90,6 +91,15 @@
for i in range(5):
assert b[i] == i * 2
+ def test_add_uint8(self):
+ from numpy import array, dtype
+
+ a = array(range(5), dtype="uint8")
+ b = a + a
+ assert b.dtype is dtype("uint8")
+ for i in range(5):
+ assert b[i] == i * 2
+
def test_add_int16(self):
from numpy import array, dtype
@@ -109,3 +119,15 @@
# You can't subclass dtype
raises(TypeError, type, "Foo", (dtype,), {})
+
+ def test_int_ranges(self):
+ from numpy import array
+ for dtype, minval, maxval in [("int8", -128, 127),
+ ("uint8", 0, 255),
+ ("int16", -32768, 32767)]:
+ a = array([minval, maxval, minval-1, maxval+1], dtype)
+ assert a[0] == minval
+ assert a[1] == maxval
+ assert a[2] == maxval
+ assert a[3] == minval
+
More information about the pypy-commit
mailing list