[pypy-commit] pypy unsigned-dtypes: (alex gaynor) add a proper Float32 dtype and drop the fake Float96 dtype.

justinpeel noreply at buildbot.pypy.org
Fri Sep 2 21:24:10 CEST 2011


Author: Justin Peel <notmuchtotell at gmail.com>
Branch: unsigned-dtypes
Changeset: r47030:84e2299f2a7c
Date: 2011-09-02 13:23 -0600
http://bitbucket.org/pypy/pypy/changeset/84e2299f2a7c/

Log:	(alex gaynor) add a proper Float32 dtype and drop the fake Float96
	dtype.

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
@@ -7,7 +7,7 @@
 from pypy.interpreter.typedef import TypeDef, interp_attrproperty, GetSetProperty
 from pypy.module.micronumpy import signature
 from pypy.objspace.std.floatobject import float2string
-from pypy.rlib import rfloat
+from pypy.rlib import rarithmetic, rfloat
 from pypy.rlib.rarithmetic import LONG_BIT, widen
 from pypy.rlib.objectmodel import specialize, enforceargs
 from pypy.rlib.unroll import unrolling_iterable
@@ -62,7 +62,10 @@
             self.val = val
 
         def wrap(self, space):
-            return space.wrap(self.val)
+            val = self.val
+            if valtype is rarithmetic.r_singlefloat:
+                val = float(val)
+            return space.wrap(val)
 
         def convert_to(self, dtype):
             return dtype.adapt_val(self.val)
@@ -178,8 +181,14 @@
 class FloatArithmeticDtype(ArithmaticTypeMixin):
     _mixin_ = True
 
+    def unwrap(self, space, w_item):
+        return self.adapt_val(space.float_w(space.float(w_item)))
+
     def for_computation(self, v):
-        return v
+        return float(v)
+
+    def str_format(self, item):
+        return float2string(self.for_computation(self.unbox(item)), 'g', rfloat.DTSF_STR_PRECISION)
 
     @binop
     def mod(self, v1, v2):
@@ -246,6 +255,9 @@
     def for_computation(self, v):
         return widen(v)
 
+    def str_format(self, item):
+        return str(widen(self.unbox(item)))
+
     @binop
     def mod(self, v1, v2):
         return v1 % v2
@@ -260,8 +272,6 @@
             assert v == 0
             return 0
 
-    def str_format(self, item):
-        return str(widen(self.unbox(item)))
 
 W_BoolDtype = create_low_level_dtype(
     num = 0, kind = BOOLLTR, name = "bool",
@@ -390,18 +400,14 @@
 
 W_Float32Dtype = create_low_level_dtype(
     num = 11, kind = FLOATINGLTR, name = "float32",
-    aliases = ["f"],
+    aliases = ["f", "float32"],
     applevel_types = [],
-    T = lltype.Float, # SingleFloat
-    valtype = float, # r_singlefloat
-    expected_size = 8, # 4
+    T = lltype.SingleFloat,
+    valtype = rarithmetic.r_singlefloat,
+    expected_size = 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)
+    pass
 
 W_Float64Dtype = create_low_level_dtype(
     num = 12, kind = FLOATINGLTR, name = "float64",
@@ -412,33 +418,25 @@
     expected_size = 8,
 )
 class W_Float64Dtype(FloatArithmeticDtype, W_Float64Dtype):
-    def unwrap(self, space, w_item):
-        return self.adapt_val(space.float_w(space.float(w_item)))
+    pass
 
-    def str_format(self, item):
-        return float2string(self.unbox(item), 'g', rfloat.DTSF_STR_PRECISION)
-
-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)))
-
-    def str_format(self, item):
-        return float2string(self.unbox(item), 'g', rfloat.DTSF_STR_PRECISION)
+#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):
+#    pass
 
 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_Float32Dtype, W_Float64Dtype, W_Float96Dtype,
+    W_Float32Dtype, W_Float64Dtype, #W_Float96Dtype,
 ]
 
 dtypes_by_alias = unrolling_iterable([
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
@@ -95,7 +95,7 @@
 
     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')
+        types = ('?','b','B','h','H','i','I','l','L','q','Q','f','d')#,'g')
         N = len(types)
         a = array([True], '?')
         for t in types:
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -310,4 +310,4 @@
         assert add.reduce([1, 2, 3]) == 6
         assert maximum.reduce([1]) == 1
         assert maximum.reduce([1, 2, 3]) == 3
-        raises(ValueError, maximum.reduce, [])
\ No newline at end of file
+        raises(ValueError, maximum.reduce, [])


More information about the pypy-commit mailing list