Author: Brian Kearns <bdkea...@gmail.com> Branch: Changeset: r67453:7c0362505295 Date: 2013-10-17 01:16 -0400 http://bitbucket.org/pypy/pypy/changeset/7c0362505295/
Log: fix reciprocal of numpy int(0) 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 @@ -323,11 +323,10 @@ reference = [0, -1, 0, 1, 0] if dtype[0] == 'u': reference[1] = 0 - # XXX need to fix specialization issue in types.py first - #elif dtype == 'int32': - # reference[2] = -2147483648 - #elif dtype == 'int64': - # reference[2] = -9223372036854775808 + elif dtype == 'int32': + reference[2] = -2147483648 + elif dtype == 'int64': + reference[2] = -9223372036854775808 a = array([-2, -1, 0, 1, 2], dtype) b = reciprocal(a) assert (b == reference).all() 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 @@ -12,7 +12,7 @@ from rpython.rlib.rawstorage import (alloc_raw_storage, raw_storage_setitem, raw_storage_getitem) from rpython.rlib.objectmodel import specialize -from rpython.rlib.rarithmetic import widen, byteswap, r_ulonglong +from rpython.rlib.rarithmetic import widen, byteswap, r_ulonglong, most_neg_value_of from rpython.rtyper.lltypesystem import lltype, rffi from rpython.rlib.rstruct.runpack import runpack from rpython.rlib.rstruct.nativefmttable import native_is_bigendian @@ -521,18 +521,17 @@ def invert(self, v): return ~v - @simple_unary_op + @specialize.argtype(1) def reciprocal(self, v): - if v == 0: + raw = self.for_computation(self.unbox(v)) + ans = 0 + if raw == 0: # XXX good place to warn - # XXX can't do the following, func is specialized only on argtype(v) - # (which is the same for all int classes) - #if self.T in (rffi.INT, rffi.LONG): - # return most_neg_value_of(self.T) - return 0 - if abs(v) == 1: - return v - return 0 + if self.T is rffi.INT or self.T is rffi.LONG: + ans = most_neg_value_of(self.T) + elif abs(raw) == 1: + ans = raw + return self.box(ans) @specialize.argtype(1) def round(self, v, decimals=0): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit