[pypy-commit] pypy unsigned-dtypes: fix unaryop promote_to_float and some test_base tests
justinpeel
noreply at buildbot.pypy.org
Fri Sep 2 01:15:11 CEST 2011
Author: Justin Peel <notmuchtotell at gmail.com>
Branch: unsigned-dtypes
Changeset: r47002:96b92594e41c
Date: 2011-09-01 15:13 -0600
http://bitbucket.org/pypy/pypy/changeset/96b92594e41c/
Log: fix unaryop promote_to_float and some test_base tests
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
@@ -388,6 +388,21 @@
W_ULongDtype.num = 8
W_ULongDtype.aliases = ["L"]
+W_Float32Dtype = create_low_level_dtype(
+ num = 11, kind = FLOATINGLTR, name = "float32",
+ aliases = ["f"],
+ applevel_types = [],
+ T = lltype.Float, # SingleFloat
+ valtype = float, # r_singlefloat
+ expected_size = 8, # 4
+)
+class W_Float32Dtype(FloatArithmeticDtype, W_Float32Dtype):
+ def unwrap(self, space, w_item):
+ return self.adapt_val(space.float_w(space.float(w_item)))
+
+ def str_format(self, item):
+ return float2string(self.unbox(item), 'g', rfloat.DTSF_STR_PRECISION)
+
W_Float64Dtype = create_low_level_dtype(
num = 12, kind = FLOATINGLTR, name = "float64",
aliases = ["d"],
@@ -403,20 +418,20 @@
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.name = "float32"
-W_Float32Dtype.aliases = ["f"]
-W_Float32Dtype.applevel_types = []
+W_Float96Dtype = create_low_level_dtype(
+ num = 13, kind = FLOATINGLTR, name = "float96",
+ aliases = ["g"],
+ applevel_types = [],
+ T = lltype.Float, # LongFloat
+ valtype = float, # r_longfloat
+ expected_size = 8, # 12
+)
+class W_Float96Dtype(FloatArithmeticDtype, W_Float96Dtype):
+ def unwrap(self, space, w_item):
+ return self.adapt_val(space.float_w(space.float(w_item)))
-class W_Float96Dtype(W_Float64Dtype):
- pass
-W_Float96Dtype.num = 13
-W_Float96Dtype.name = "float96"
-W_Float96Dtype.aliases = ["g"]
-W_Float96Dtype.applevel_types = []
+ def str_format(self, item):
+ return float2string(self.unbox(item), 'g', rfloat.DTSF_STR_PRECISION)
ALL_DTYPES = [
W_BoolDtype,
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
@@ -204,8 +204,10 @@
if promote_bools and (dt.kind == interp_dtype.BOOLLTR):
return space.fromcache(interp_dtype.W_Int8Dtype)
if promote_to_float:
+ if dt.kind == interp_dtype.FLOATINGLTR:
+ return dt
for bytes, dtype in interp_dtype.dtypes_by_num_bytes:
- if dtype.kind == interp_dtype.FLOATINGLTR and dtype.num_bytes >= dt.num_bytes:
+ if dtype.kind == interp_dtype.FLOATINGLTR and dtype.num_bytes > dt.num_bytes:
return space.fromcache(dtype)
if promote_to_largest:
if dt.kind == interp_dtype.BOOLLTR or dt.kind == interp_dtype.SIGNEDLTR:
diff --git a/pypy/module/micronumpy/test/test_base.py b/pypy/module/micronumpy/test/test_base.py
--- a/pypy/module/micronumpy/test/test_base.py
+++ b/pypy/module/micronumpy/test/test_base.py
@@ -64,7 +64,9 @@
def test_unaryops(self, space):
bool_dtype = space.fromcache(interp_dtype.W_BoolDtype)
int8_dtype = space.fromcache(interp_dtype.W_Int8Dtype)
+ int16_dtype = space.fromcache(interp_dtype.W_Int16Dtype)
int32_dtype = space.fromcache(interp_dtype.W_Int32Dtype)
+ float32_dtype = space.fromcache(interp_dtype.W_Float32Dtype)
float64_dtype = space.fromcache(interp_dtype.W_Float64Dtype)
# Normal rules, everythign returns itself
@@ -75,7 +77,8 @@
# Coerce to floats, some of these will eventually be float16, or
# whatever our smallest float type is.
- assert find_unaryop_result_dtype(space, bool_dtype, promote_to_float=True) is float64_dtype
- assert find_unaryop_result_dtype(space, int8_dtype, promote_to_float=True) is float64_dtype
+ assert find_unaryop_result_dtype(space, bool_dtype, promote_to_float=True) is float32_dtype # will be float16 if we ever put that in
+ assert find_unaryop_result_dtype(space, int8_dtype, promote_to_float=True) is float32_dtype # will be float16 if we ever put that in
+ assert find_unaryop_result_dtype(space, int16_dtype, promote_to_float=True) is float32_dtype
assert find_unaryop_result_dtype(space, int32_dtype, promote_to_float=True) is float64_dtype
- assert find_unaryop_result_dtype(space, float64_dtype, promote_to_float=True) is float64_dtype
\ No newline at end of file
+ assert find_unaryop_result_dtype(space, float64_dtype, promote_to_float=True) is float64_dtype
More information about the pypy-commit
mailing list