[pypy-commit] pypy fix-result-types: Rename promote_types() to w_promote_types() and _promote_types() to promote_types()

rlamy noreply at buildbot.pypy.org
Thu May 28 20:30:07 CEST 2015


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: fix-result-types
Changeset: r77664:0b8c4fbfdaa2
Date: 2015-05-28 19:15 +0100
http://bitbucket.org/pypy/pypy/changeset/0b8c4fbfdaa2/

Log:	Rename promote_types() to w_promote_types() and _promote_types() to
	promote_types()

diff --git a/pypy/module/micronumpy/__init__.py b/pypy/module/micronumpy/__init__.py
--- a/pypy/module/micronumpy/__init__.py
+++ b/pypy/module/micronumpy/__init__.py
@@ -24,7 +24,7 @@
         'result_type': 'casting.result_type',
         'can_cast': 'casting.can_cast',
         'min_scalar_type': 'casting.min_scalar_type',
-        'promote_types': 'casting.promote_types',
+        'promote_types': 'casting.w_promote_types',
 
         'set_string_function': 'appbridge.set_string_function',
         'typeinfo': 'descriptor.get_dtype_cache(space).w_typeinfo',
diff --git a/pypy/module/micronumpy/casting.py b/pypy/module/micronumpy/casting.py
--- a/pypy/module/micronumpy/casting.py
+++ b/pypy/module/micronumpy/casting.py
@@ -49,12 +49,12 @@
             if result is None:
                 result = w_array.get_dtype()
             else:
-                result = _promote_types(space, result, w_array.get_dtype())
+                result = promote_types(space, result, w_array.get_dtype())
         for dtype in dtypes_w:
             if result is None:
                 result = dtype
             else:
-                result = _promote_types(space, result, dtype)
+                result = promote_types(space, result, dtype)
     else:
         small_unsigned = False
         for w_array in arrays_w:
@@ -213,19 +213,21 @@
     else:
         return dtype
 
-def promote_types(space, w_type1, w_type2):
+def w_promote_types(space, w_type1, w_type2):
     dt1 = as_dtype(space, w_type1, allow_None=False)
     dt2 = as_dtype(space, w_type2, allow_None=False)
-    return _promote_types(space, dt1, dt2)
+    return promote_types(space, dt1, dt2)
 
 def find_binop_result_dtype(space, dt1, dt2):
     if dt2 is None:
         return dt1
     if dt1 is None:
         return dt2
-    return _promote_types(space, dt1, dt2)
+    return promote_types(space, dt1, dt2)
 
-def _promote_types(space, dt1, dt2):
+def promote_types(space, dt1, dt2):
+    """Return the smallest dtype to which both input dtypes can be safely cast"""
+    # Equivalent to PyArray_PromoteTypes
     num = promotion_table[dt1.num][dt2.num]
     if num != -1:
         return num2dtype(space, num)
@@ -270,7 +272,7 @@
     raise oefmt(space.w_TypeError, "invalid type promotion")
 
 def _promote_types_su(space, dt1, dt2, su1, su2):
-    """Like _promote_types(), but handles the small_unsigned flag as well"""
+    """Like promote_types(), but handles the small_unsigned flag as well"""
     if su1:
         if dt2.is_bool() or dt2.is_unsigned():
             dt1 = dt1.as_unsigned(space)
@@ -287,7 +289,7 @@
         su = su1 and su2
     else:
         su = su1 and (su2 or not dt2.is_signed())
-    return _promote_types(space, dt1, dt2), su
+    return promote_types(space, dt1, dt2), su
 
 def scalar2dtype(space, w_obj):
     from .boxes import W_GenericBox
diff --git a/pypy/module/micronumpy/test/test_casting.py b/pypy/module/micronumpy/test/test_casting.py
--- a/pypy/module/micronumpy/test/test_casting.py
+++ b/pypy/module/micronumpy/test/test_casting.py
@@ -1,7 +1,7 @@
 from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest
 from pypy.module.micronumpy.descriptor import get_dtype_cache, num2dtype
 from pypy.module.micronumpy.casting import (
-    find_binop_result_dtype, can_cast_type, _promote_types_su)
+    promote_types, can_cast_type, _promote_types_su)
 import pypy.module.micronumpy.constants as NPY
 
 
@@ -173,7 +173,7 @@
 
 
 class TestCoercion(object):
-    def test_binops(self, space):
+    def test_promote_types(self, space):
         bool_dtype = get_dtype_cache(space).w_booldtype
         int8_dtype = get_dtype_cache(space).w_int8dtype
         int32_dtype = get_dtype_cache(space).w_int32dtype
@@ -183,11 +183,11 @@
         cld_dtype = get_dtype_cache(space).w_complexlongdtype
         fld_dtype = get_dtype_cache(space).w_floatlongdtype
 
-        assert find_binop_result_dtype(space, bool_dtype, bool_dtype) is bool_dtype
-        assert find_binop_result_dtype(space, bool_dtype, float64_dtype) is float64_dtype
-        assert find_binop_result_dtype(space, float64_dtype, bool_dtype) is float64_dtype
-        assert find_binop_result_dtype(space, int32_dtype, int8_dtype) is int32_dtype
-        assert find_binop_result_dtype(space, int32_dtype, bool_dtype) is int32_dtype
-        assert find_binop_result_dtype(space, c64_dtype, float64_dtype) is c128_dtype
-        #assert find_binop_result_dtype(space, c64_dtype, fld_dtype) == cld_dtype
-        #assert find_binop_result_dtype(space, c128_dtype, fld_dtype) == cld_dtype
+        assert promote_types(space, bool_dtype, bool_dtype) is bool_dtype
+        assert promote_types(space, bool_dtype, float64_dtype) is float64_dtype
+        assert promote_types(space, float64_dtype, bool_dtype) is float64_dtype
+        assert promote_types(space, int32_dtype, int8_dtype) is int32_dtype
+        assert promote_types(space, int32_dtype, bool_dtype) is int32_dtype
+        assert promote_types(space, c64_dtype, float64_dtype) is c128_dtype
+        #assert promote_types(space, c64_dtype, fld_dtype) == cld_dtype
+        #assert promote_types(space, c128_dtype, fld_dtype) == cld_dtype
diff --git a/pypy/module/micronumpy/ufuncs.py b/pypy/module/micronumpy/ufuncs.py
--- a/pypy/module/micronumpy/ufuncs.py
+++ b/pypy/module/micronumpy/ufuncs.py
@@ -20,7 +20,7 @@
 from pypy.module.micronumpy.strides import shape_agreement
 from pypy.module.micronumpy.support import (_parse_signature, product,
         get_storage_as_int, is_rhs_priority_higher)
-from .casting import can_cast_type, find_result_type, _promote_types
+from .casting import can_cast_type, find_result_type, promote_types
 from .boxes import W_GenericBox, W_ObjectBox
 
 def done_if_true(dtype, val):
@@ -659,7 +659,7 @@
     def find_specialization(self, space, l_dtype, r_dtype, out, casting):
         if self.simple_binary:
             if out is None and not (l_dtype.is_object() or r_dtype.is_object()):
-                dtype = _promote_types(space, l_dtype, r_dtype)
+                dtype = promote_types(space, l_dtype, r_dtype)
                 return dtype, dtype, self.func
         return self._find_specialization(space, l_dtype, r_dtype, out, casting)
 


More information about the pypy-commit mailing list