Author: Ronan Lamy <ronan.l...@gmail.com> Branch: fix-result-types Changeset: r77295:5436f4d8b598 Date: 2015-05-12 05:45 +0100 http://bitbucket.org/pypy/pypy/changeset/5436f4d8b598/
Log: Fix casting table 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 @@ -90,7 +90,7 @@ if origin.kind in kind_ordering and target.kind in kind_ordering: return kind_ordering[origin.kind] <= kind_ordering[target.kind] return False - else: + else: # 'safe' return origin.can_cast_to(target) def can_cast_array(space, w_from, target, casting): 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 from pypy.module.micronumpy.casting import ( - find_unaryop_result_dtype, find_binop_result_dtype) + find_unaryop_result_dtype, find_binop_result_dtype, can_cast_type) class AppTestNumSupport(BaseNumpyAppTest): @@ -27,6 +27,7 @@ assert np.can_cast(np.int32, np.int64) assert np.can_cast(np.float64, complex) assert not np.can_cast(np.complex64, float) + assert np.can_cast(np.bool_, np.bool_) assert np.can_cast('i8', 'f8') assert not np.can_cast('i8', 'f4') @@ -123,6 +124,15 @@ # XXX: np.asarray(2**64) fails with OverflowError # assert np.min_scalar_type(2**64) == np.dtype('O') +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') + assert can_cast_type(space, dt_bool, dt_bool, 'equiv') + assert can_cast_type(space, dt_bool, dt_bool, 'safe') + assert can_cast_type(space, dt_bool, dt_bool, 'same_kind') + assert can_cast_type(space, dt_bool, dt_bool, 'unsafe') + + class TestCoercion(object): def test_binops(self, space): bool_dtype = get_dtype_cache(space).w_booldtype diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py --- a/pypy/module/micronumpy/types.py +++ b/pypy/module/micronumpy/types.py @@ -2439,7 +2439,7 @@ casting_table = [[False] * NPY.NTYPES for _ in range(NPY.NTYPES)] number_types = int_types + float_types + complex_types -all_types = number_types + [ObjectType, StringType, UnicodeType, VoidType] +all_types = [Bool] + number_types + [ObjectType, StringType, UnicodeType, VoidType] def enable_cast(type1, type2): casting_table[type1.num][type2.num] = True _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit