[pypy-commit] pypy numpy-dtype-refactor: Fix tests, expose int{16, 32} at app level, add a test for __int__
alex_gaynor
noreply at buildbot.pypy.org
Fri Dec 2 18:40:24 CET 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: numpy-dtype-refactor
Changeset: r50068:f1d05c0a4b16
Date: 2011-12-02 12:40 -0500
http://bitbucket.org/pypy/pypy/changeset/f1d05c0a4b16/
Log: Fix tests, expose int{16,32} at app level, add a test for __int__
diff --git a/pypy/module/micronumpy/REVIEW b/pypy/module/micronumpy/REVIEW
--- a/pypy/module/micronumpy/REVIEW
+++ b/pypy/module/micronumpy/REVIEW
@@ -1,3 +1,1 @@
-* why int16/int32 are not exported in __init__.py?
-* W_GenericBox.descr_int is not tested
* setitem_w no longer calls invalidated(), why? doesn't it break some stuff?
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
@@ -25,6 +25,8 @@
'signedinteger': 'interp_boxes.W_SignedIntegerBox',
'bool_': 'interp_boxes.W_BoolBox',
'int8': 'interp_boxes.W_Int8Box',
+ 'int16': 'interp_boxes.W_Int16Box',
+ 'int32': 'interp_boxes.W_Int32Box',
'int64': 'interp_boxes.W_Int64Box',
'int_': 'interp_boxes.W_LongBox',
'inexact': 'interp_boxes.W_InexactBox',
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
@@ -122,7 +122,7 @@
descr__new__, get_dtype = new_dtype_getter("uint16")
class W_Int32Box(W_SignedIntegerBox, PrimitiveBox):
- pass
+ descr__new__, get_dtype = new_dtype_getter("int32")
class W_UInt32Box(W_UnsignedIntgerBox, PrimitiveBox):
descr__new__, get_dtype = new_dtype_getter("uint32")
@@ -211,6 +211,7 @@
W_Int16Box.typedef = TypeDef("int16", W_SignedIntegerBox.typedef,
__module__ = "numpypy",
+ __new__ = interp2app(W_Int16Box.descr__new__.im_func),
)
W_UInt16Box.typedef = TypeDef("uint16", W_UnsignedIntgerBox.typedef,
@@ -219,6 +220,7 @@
W_Int32Box.typedef = TypeDef("int32", W_SignedIntegerBox.typedef,
__module__ = "numpypy",
+ __new__ = interp2app(W_Int32Box.descr__new__.im_func),
)
W_UInt32Box.typedef = TypeDef("uint32", W_UnsignedIntgerBox.typedef,
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
@@ -30,7 +30,7 @@
def test_repr_str(self):
from numpypy import dtype
- assert repr(dtype) == "<type 'numpy.dtype'>"
+ assert repr(dtype) == "<type 'numpypy.dtype'>"
d = dtype('?')
assert repr(d) == "dtype('bool')"
assert str(d) == "bool"
@@ -173,7 +173,7 @@
raises(TypeError, numpy.number, 0)
raises(TypeError, numpy.integer, 0)
exc = raises(TypeError, numpy.signedinteger, 0)
- assert str(exc.value) == "cannot create 'numpy.signedinteger' instances"
+ assert str(exc.value) == "cannot create 'numpypy.signedinteger' instances"
raises(TypeError, numpy.floating, 0)
raises(TypeError, numpy.inexact, 0)
@@ -207,6 +207,21 @@
assert type(x) is numpy.int8
assert repr(x) == "-128"
+ assert type(int(x)) is int
+ assert int(x) == -128
+
+ def test_int16(self):
+ import numpypy as numpy
+
+ x = numpy.int16(3)
+ assert x == 3
+
+ def test_int32(self):
+ import numpypy as numpy
+
+ x = numpy.int32(23)
+ assert x == 23
+
def test_int_(self):
import numpypy as numpy
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
@@ -8,7 +8,7 @@
assert isinstance(add, ufunc)
assert repr(add) == "<ufunc 'add'>"
- assert repr(ufunc) == "<type 'numpy.ufunc'>"
+ assert repr(ufunc) == "<type 'numpypy.ufunc'>"
def test_ufunc_attrs(self):
from numpypy import add, multiply, sin
More information about the pypy-commit
mailing list