Author: Alex Gaynor <[email protected]>
Branch:
Changeset: r67376:261f84f41858
Date: 2013-10-15 00:08 +0200
http://bitbucket.org/pypy/pypy/changeset/261f84f41858/
Log: merged upstream
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
@@ -136,6 +136,11 @@
assert isinstance(box, W_LongBox)
return space.wrap(box.value)
+ def descr_long(self, space):
+ box = self.convert_to(W_Int64Box._get_dtype(space))
+ assert isinstance(box, W_Int64Box)
+ return space.wrap(box.value)
+
def descr_float(self, space):
box = self.convert_to(W_Float64Box._get_dtype(space))
assert isinstance(box, W_Float64Box)
@@ -470,6 +475,7 @@
__repr__ = interp2app(W_GenericBox.descr_str),
__format__ = interp2app(W_GenericBox.descr_format),
__int__ = interp2app(W_GenericBox.descr_int),
+ __long__ = interp2app(W_GenericBox.descr_long),
__float__ = interp2app(W_GenericBox.descr_float),
__nonzero__ = interp2app(W_GenericBox.descr_nonzero),
diff --git a/pypy/module/micronumpy/interp_numarray.py
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -894,6 +894,15 @@
return space.int(self.descr_getitem(space, space.wrap(0)))
raise OperationError(space.w_TypeError, space.wrap("only length-1
arrays can be converted to Python scalars"))
+ def descr_long(self, space):
+ shape = self.get_shape()
+ if len(shape) == 0:
+ assert isinstance(self.implementation, scalar.Scalar)
+ return
space.long(space.wrap(self.implementation.get_scalar_value()))
+ if shape == [1]:
+ return space.int(self.descr_getitem(space, space.wrap(0)))
+ raise OperationError(space.w_TypeError, space.wrap("only length-1
arrays can be converted to Python scalars"))
+
def descr_float(self, space):
shape = self.get_shape()
if len(shape) == 0:
@@ -1020,6 +1029,7 @@
__repr__ = interp2app(W_NDimArray.descr_repr),
__str__ = interp2app(W_NDimArray.descr_str),
__int__ = interp2app(W_NDimArray.descr_int),
+ __long__ = interp2app(W_NDimArray.descr_long),
__float__ = interp2app(W_NDimArray.descr_float),
__pos__ = interp2app(W_NDimArray.descr_pos),
diff --git a/pypy/module/micronumpy/test/test_numarray.py
b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -1896,6 +1896,15 @@
b = array([1, 2, 3, 4])
assert (a == b) == False
+ def test__long__(self):
+ from numpypy import array
+ assert long(array(1)) == 1
+ assert long(array([1])) == 1
+ assert isinstance(long(array([1])), long)
+ assert isinstance(long(array([1, 2][0])), long)
+ assert raises(TypeError, "long(array([1, 2]))")
+ assert long(array([1.5])) == 1
+
def test__int__(self):
from numpypy import array
assert int(array(1)) == 1
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit