[pypy-commit] pypy default: fix numpy int/uint conversions
bdkearns
noreply at buildbot.pypy.org
Thu Feb 20 20:29:10 CET 2014
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r69225:5dae92869ac0
Date: 2014-02-20 14:24 -0500
http://bitbucket.org/pypy/pypy/changeset/5dae92869ac0/
Log: fix numpy int/uint conversions
diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -44,7 +44,7 @@
w_arr = array(space, w_value, dtype, copy=False)
if len(w_arr.get_shape()) != 0:
return w_arr
- w_value = w_arr.get_scalar_value()
+ w_value = w_arr.get_scalar_value().item(space)
return dtype.itemtype.coerce_subtype(space, w_subtype, w_value)
def descr_reduce(self, space):
@@ -155,18 +155,22 @@
return space.index(self.item(space))
def descr_int(self, space):
- box = self.convert_to(space, W_LongBox._get_dtype(space))
- assert isinstance(box, W_LongBox)
- return space.wrap(box.value)
+ if isinstance(self, W_UnsignedIntegerBox):
+ box = self.convert_to(space, W_UInt64Box._get_dtype(space))
+ else:
+ box = self.convert_to(space, W_Int64Box._get_dtype(space))
+ return space.int(box.item(space))
def descr_long(self, space):
- box = self.convert_to(space, W_Int64Box._get_dtype(space))
- assert isinstance(box, W_Int64Box)
- return space.wrap(box.value)
+ if isinstance(self, W_UnsignedIntegerBox):
+ box = self.convert_to(space, W_UInt64Box._get_dtype(space))
+ else:
+ box = self.convert_to(space, W_Int64Box._get_dtype(space))
+ return space.long(box.item(space))
def descr_float(self, space):
box = self.convert_to(space, W_Float64Box._get_dtype(space))
- assert isinstance(box, W_Float64Box)
+ assert isinstance(box, PrimitiveBox)
return space.wrap(box.value)
def descr_oct(self, space):
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
@@ -572,6 +572,7 @@
raises(OverflowError, numpy.int64, 9223372036854775808)
raises(OverflowError, numpy.int64, 18446744073709551615)
raises(OverflowError, numpy.uint64, 18446744073709551616)
+ assert numpy.uint64((2<<63) - 1) == (2<<63) - 1
def test_float16(self):
import numpy
diff --git a/pypy/module/micronumpy/test/test_scalar.py b/pypy/module/micronumpy/test/test_scalar.py
--- a/pypy/module/micronumpy/test/test_scalar.py
+++ b/pypy/module/micronumpy/test/test_scalar.py
@@ -35,6 +35,7 @@
assert int(np.str_('12')) == 12
exc = raises(ValueError, "int(np.str_('abc'))")
assert exc.value.message.startswith('invalid literal for int()')
+ assert int(np.uint64((2<<63) - 1)) == (2<<63) - 1
assert oct(np.int32(11)) == '013'
assert oct(np.float32(11.6)) == '013'
assert oct(np.complex64(11-12j)) == '013'
More information about the pypy-commit
mailing list