[pypy-commit] pypy unsigned-dtypes: Add dtypes tests and fix some things
justinpeel
noreply at buildbot.pypy.org
Thu Sep 1 21:07:28 CEST 2011
Author: Justin Peel <notmuchtotell at gmail.com>
Branch: unsigned-dtypes
Changeset: r47000:eec948d816bc
Date: 2011-09-01 13:05 -0600
http://bitbucket.org/pypy/pypy/changeset/eec948d816bc/
Log: Add dtypes tests and fix some things
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
@@ -390,8 +390,8 @@
W_Float64Dtype = create_low_level_dtype(
num = 12, kind = FLOATINGLTR, name = "float64",
- aliases = [],
- applevel_types = ["d", "float"],
+ aliases = ["d"],
+ applevel_types = ["float"],
T = lltype.Float,
valtype = float,
expected_size = 8,
@@ -403,14 +403,25 @@
def str_format(self, item):
return float2string(self.unbox(item), 'g', rfloat.DTSF_STR_PRECISION)
+# these are really just stand-ins for now until we get them fully working
+class W_Float32Dtype(W_Float64Dtype):
+ pass
+W_Float32Dtype.num = 11
+W_Float32Dtype.aliases = ["f"]
+W_Float32Dtype.applevel_types = []
+
+class W_Float96Dtype(W_Float64Dtype):
+ pass
+W_Float96Dtype.num = 13
+W_Float96Dtype.aliases = ["g"]
+W_Float96Dtype.applevel_types = []
+
ALL_DTYPES = [
W_BoolDtype,
W_Int8Dtype, W_UInt8Dtype, W_Int16Dtype, W_UInt16Dtype,
W_Int32Dtype, W_UInt32Dtype, W_LongDtype, W_ULongDtype,
W_Int64Dtype, W_UInt64Dtype,
- W_Float64Dtype, #float32 fill-in for now
- W_Float64Dtype,
- W_Float64Dtype, #float96 fill-in for now
+ W_Float32Dtype, W_Float64Dtype, W_Float96Dtype,
]
dtypes_by_alias = unrolling_iterable([
diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -178,20 +178,20 @@
return dt2
# for now this means mixing signed and unsigned
- if dt2.kind == interp_dtype.SIGNEDLTR
+ if dt2.kind == interp_dtype.SIGNEDLTR:
if dt1.num_bytes < dt2.num_bytes:
return dt2
# we need to promote both dtypes
dtypenum = dt2.num + 2
else:
dtypenum = dt2.num + 1
- newdtype = interp_dtype.ALL_DTYPE[dtypenum]
+ newdtype = interp_dtype.ALL_DTYPES[dtypenum]
if newdtype.num_bytes > dt2.num_bytes or newdtype.kind == interp_dtype.FLOATINGLTR:
return newdtype
else:
# we only promoted to long on 32-bit or to longlong on 64-bit
- return interp_dtype.ALL_DTYPE[dtypenum + 2]
+ return interp_dtype.ALL_DTYPES[dtypenum + 2]
def find_unaryop_result_dtype(space, dt, promote_to_float=False,
promote_bools=False, promote_to_largest=False):
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
@@ -17,6 +17,7 @@
from numpy import dtype
assert dtype(bool).num == 0
+ assert dtype(int).num == 7
assert dtype(long).num == 9
assert dtype(float).num == 12
@@ -81,6 +82,36 @@
assert isinstance(a[i], (int, long))
assert a[1] == 1
+ def test_overflow(self):
+ from numpy import array
+ assert array([128], 'b')[0] == -128
+ assert array([256], 'B')[0] == 0
+ assert array([32768], 'h')[0] == -32768
+ assert array([65536], 'H')[0] == 0
+ raises(OverflowError, "array([2147483648], 'i')")
+ raises(OverflowError, "array([4294967296], 'I')")
+ raises(OverflowError, "array([9223372036854775808], 'q')")
+ raises(OverflowError, "array([18446744073709551616], 'Q')")
+
+ def test_bool_binop_types(self):
+ from numpy import array, dtype
+ types = ('?','b','B','h','H','i','I','l','L','q','Q','f','d','g')
+ dtypes = [dtype(t) for t in types]
+ N = len(types)
+ a = array([True], '?')
+ for i in xrange(N):
+ assert (a + array([0], types[i])).dtype is dtypes[i]
+
+ def test_binop_types(self):
+ from numpy import array, dtype
+ tests = (('b','B','h'), ('b','h','h'), ('b','H','i'), ('b','I','q'),
+ ('b','Q','d'), ('B','H','H'), ('B','I','I'), ('B','Q','Q'),
+ ('B','h','h'), ('h','H','i'), ('h','i','i'), ('H','i','i'),
+ ('H','I','I'), ('i','I','q'), ('I','q','q'), ('q','Q','d'),
+ ('i','f','f'), ('q','f','d'), ('q','d','d'), ('Q','f','d'))
+ for d1, d2, dout in tests:
+ assert (array([1], d1) + array([1], d2)).dtype is dtype(dout)
+
def test_add_int8(self):
from numpy import array, dtype
More information about the pypy-commit
mailing list