Author: Ronan Lamy <[email protected]>
Branch: fix-result-types
Changeset: r77401:f50a26cd48a6
Date: 2015-05-19 19:04 +0100
http://bitbucket.org/pypy/pypy/changeset/f50a26cd48a6/
Log: Create np.promote_types(), with failing tests
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,6 +24,7 @@
'result_type': 'casting.result_type',
'can_cast': 'casting.can_cast',
'min_scalar_type': 'casting.min_scalar_type',
+ 'promote_types': 'casting.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
@@ -129,6 +129,11 @@
else:
return dtype
+def 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)
+
@jit.unroll_safe
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_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
@@ -124,6 +124,13 @@
# XXX: np.asarray(2**64) fails with OverflowError
# assert np.min_scalar_type(2**64) == np.dtype('O')
+ def test_promote_types(self):
+ import numpy as np
+ assert np.promote_types('f4', 'f8') == np.dtype('float64')
+ assert np.promote_types('i8', 'f4') == np.dtype('float64')
+ assert np.promote_types('>i8', '<c8') == np.dtype('complex128')
+ assert np.promote_types('i4', 'S8') == np.dtype('S11')
+
def test_can_cast_same_type(space):
dt_bool = get_dtype_cache(space).w_booldtype
assert can_cast_type(space, dt_bool, dt_bool, 'no')
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit