[pypy-commit] pypy default: merge heads
arigo
noreply at buildbot.pypy.org
Tue Dec 13 21:17:19 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r50473:585211322729
Date: 2011-12-13 21:16 +0100
http://bitbucket.org/pypy/pypy/changeset/585211322729/
Log: merge heads
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
@@ -1,9 +1,19 @@
from pypy.interpreter.mixedmodule import MixedModule
+class PyPyModule(MixedModule):
+ interpleveldefs = {
+ 'debug_repr': 'interp_extras.debug_repr',
+ }
+ appleveldefs = {}
+
class Module(MixedModule):
applevel_name = 'numpypy'
+ submodules = {
+ 'pypy': PyPyModule
+ }
+
interpleveldefs = {
'ndarray': 'interp_numarray.W_NDimArray',
'dtype': 'interp_dtype.W_Dtype',
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
@@ -86,6 +86,7 @@
descr_ge = _binop_impl("greater_equal")
descr_radd = _binop_right_impl("add")
+ descr_rsub = _binop_right_impl("subtract")
descr_rmul = _binop_right_impl("multiply")
descr_neg = _unaryop_impl("negative")
@@ -170,7 +171,8 @@
__mul__ = interp2app(W_GenericBox.descr_mul),
__div__ = interp2app(W_GenericBox.descr_div),
- __radd__ = interp2app(W_GenericBox.descr_add),
+ __radd__ = interp2app(W_GenericBox.descr_radd),
+ __rsub__ = interp2app(W_GenericBox.descr_rsub),
__rmul__ = interp2app(W_GenericBox.descr_rmul),
__eq__ = interp2app(W_GenericBox.descr_eq),
diff --git a/pypy/module/micronumpy/interp_extras.py b/pypy/module/micronumpy/interp_extras.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/micronumpy/interp_extras.py
@@ -0,0 +1,7 @@
+from pypy.interpreter.gateway import unwrap_spec
+from pypy.module.micronumpy.interp_numarray import BaseArray
+
+
+ at unwrap_spec(array=BaseArray)
+def debug_repr(space, array):
+ return space.wrap(array.debug_repr())
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
@@ -925,9 +925,6 @@
def start_iter(self, res_shape=None):
raise NotImplementedError
- def descr_debug_repr(self, space):
- return space.wrap(self.debug_repr())
-
def descr_array_iface(self, space):
concrete = self.get_concrete()
storage = concrete.get_storage(space)
@@ -1466,7 +1463,6 @@
__repr__ = interp2app(BaseArray.descr_repr),
__str__ = interp2app(BaseArray.descr_str),
- __debug_repr__ = interp2app(BaseArray.descr_debug_repr),
__array_interface__ = GetSetProperty(BaseArray.descr_array_iface),
dtype = GetSetProperty(BaseArray.descr_get_dtype),
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
@@ -491,6 +491,11 @@
for i in range(5):
assert b[i] == i - 5
+ def test_scalar_subtract(self):
+ from numpypy import int32
+ assert int32(2) - 1 == 1
+ assert 1 - int32(2) == -1
+
def test_mul(self):
import numpypy
@@ -868,16 +873,17 @@
def test_debug_repr(self):
from numpypy import zeros, sin
+ from numpypy.pypy import debug_repr
a = zeros(1)
- assert a.__debug_repr__() == 'Array'
- assert (a + a).__debug_repr__() == 'Call2(add, Array, Array)'
- assert (a[::2]).__debug_repr__() == 'Slice(Array)'
- assert (a + 2).__debug_repr__() == 'Call2(add, Array, Scalar)'
- assert (a + a.flat).__debug_repr__() == 'Call2(add, Array, FlatIter(Array))'
- assert sin(a).__debug_repr__() == 'Call1(sin, Array)'
+ assert debug_repr(a) == 'Array'
+ assert debug_repr(a + a) == 'Call2(add, Array, Array)'
+ assert debug_repr(a[::2]) == 'Slice(Array)'
+ assert debug_repr(a + 2) == 'Call2(add, Array, Scalar)'
+ assert debug_repr(a + a.flat) == 'Call2(add, Array, FlatIter(Array))'
+ assert debug_repr(sin(a)) == 'Call1(sin, Array)'
b = a + a
b[0] = 3
- assert b.__debug_repr__() == 'Call2(add, forced=Array)'
+ assert debug_repr(b) == 'Call2(add, forced=Array)'
def test_tolist_scalar(self):
from numpypy import int32, bool_
diff --git a/pypy/objspace/std/specialisedtupleobject.py b/pypy/objspace/std/specialisedtupleobject.py
--- a/pypy/objspace/std/specialisedtupleobject.py
+++ b/pypy/objspace/std/specialisedtupleobject.py
@@ -177,52 +177,55 @@
_specialisations = []
Cls_ii = make_specialised_class((int, int))
-Cls_is = make_specialised_class((int, str))
-Cls_io = make_specialised_class((int, object))
-Cls_si = make_specialised_class((str, int))
-Cls_ss = make_specialised_class((str, str))
-Cls_so = make_specialised_class((str, object))
-Cls_oi = make_specialised_class((object, int))
-Cls_os = make_specialised_class((object, str))
+#Cls_is = make_specialised_class((int, str))
+#Cls_io = make_specialised_class((int, object))
+#Cls_si = make_specialised_class((str, int))
+#Cls_ss = make_specialised_class((str, str))
+#Cls_so = make_specialised_class((str, object))
+#Cls_oi = make_specialised_class((object, int))
+#Cls_os = make_specialised_class((object, str))
Cls_oo = make_specialised_class((object, object))
Cls_ff = make_specialised_class((float, float))
-Cls_ooo = make_specialised_class((object, object, object))
+#Cls_ooo = make_specialised_class((object, object, object))
def makespecialisedtuple(space, list_w):
if len(list_w) == 2:
w_arg1, w_arg2 = list_w
w_type1 = space.type(w_arg1)
- w_type2 = space.type(w_arg2)
+ #w_type2 = space.type(w_arg2)
#
if w_type1 is space.w_int:
+ w_type2 = space.type(w_arg2)
if w_type2 is space.w_int:
return Cls_ii(space, w_arg1, w_arg2)
- elif w_type2 is space.w_str:
- return Cls_is(space, w_arg1, w_arg2)
- else:
- return Cls_io(space, w_arg1, w_arg2)
+ #elif w_type2 is space.w_str:
+ # return Cls_is(space, w_arg1, w_arg2)
+ #else:
+ # return Cls_io(space, w_arg1, w_arg2)
#
- elif w_type1 is space.w_str:
- if w_type2 is space.w_int:
- return Cls_si(space, w_arg1, w_arg2)
- elif w_type2 is space.w_str:
- return Cls_ss(space, w_arg1, w_arg2)
- else:
- return Cls_so(space, w_arg1, w_arg2)
+ #elif w_type1 is space.w_str:
+ # if w_type2 is space.w_int:
+ # return Cls_si(space, w_arg1, w_arg2)
+ # elif w_type2 is space.w_str:
+ # return Cls_ss(space, w_arg1, w_arg2)
+ # else:
+ # return Cls_so(space, w_arg1, w_arg2)
#
- elif w_type1 is space.w_float and w_type2 is space.w_float:
- return Cls_ff(space, w_arg1, w_arg2)
+ elif w_type1 is space.w_float:
+ w_type2 = space.type(w_arg2)
+ if w_type2 is space.w_float:
+ return Cls_ff(space, w_arg1, w_arg2)
#
- else:
- if w_type2 is space.w_int:
- return Cls_oi(space, w_arg1, w_arg2)
- elif w_type2 is space.w_str:
- return Cls_os(space, w_arg1, w_arg2)
- else:
- return Cls_oo(space, w_arg1, w_arg2)
+ #else:
+ # if w_type2 is space.w_int:
+ # return Cls_oi(space, w_arg1, w_arg2)
+ # elif w_type2 is space.w_str:
+ # return Cls_os(space, w_arg1, w_arg2)
+ # else:
+ return Cls_oo(space, w_arg1, w_arg2)
#
- elif len(list_w) == 3:
- return Cls_ooo(space, list_w[0], list_w[1], list_w[2])
+ #elif len(list_w) == 3:
+ # return Cls_ooo(space, list_w[0], list_w[1], list_w[2])
else:
raise NotSpecialised
diff --git a/pypy/objspace/std/test/test_specialisedtupleobject.py b/pypy/objspace/std/test/test_specialisedtupleobject.py
--- a/pypy/objspace/std/test/test_specialisedtupleobject.py
+++ b/pypy/objspace/std/test/test_specialisedtupleobject.py
@@ -33,15 +33,15 @@
N_space = gettestobjspace(**{"objspace.std.withspecialisedtuple": False})
S_space = gettestobjspace(**{"objspace.std.withspecialisedtuple": True})
- def hash_test(values):
+ def hash_test(values, must_be_specialized=True):
N_values_w = [N_space.wrap(value) for value in values]
S_values_w = [S_space.wrap(value) for value in values]
N_w_tuple = N_space.newtuple(N_values_w)
S_w_tuple = S_space.newtuple(S_values_w)
-
- assert isinstance(S_w_tuple, W_SpecialisedTupleObject)
+
+ if must_be_specialized:
+ assert isinstance(S_w_tuple, W_SpecialisedTupleObject)
assert isinstance(N_w_tuple, W_TupleObject)
- assert not N_space.is_true(N_space.eq(N_w_tuple, S_w_tuple))
assert S_space.is_true(S_space.eq(N_w_tuple, S_w_tuple))
assert S_space.is_true(S_space.eq(N_space.hash(N_w_tuple), S_space.hash(S_w_tuple)))
@@ -53,7 +53,7 @@
hash_test([1,(1,2)])
hash_test([1,('a',2)])
hash_test([1,()])
- hash_test([1,2,3])
+ hash_test([1,2,3], must_be_specialized=False)
class AppTestW_SpecialisedTupleObject:
@@ -83,6 +83,8 @@
return ("SpecialisedTupleObject" + expected) in r
def test_createspecialisedtuple(self):
+ have = ['ii', 'ff', 'oo']
+ #
spec = {int: 'i',
float: 'f',
str: 's',
@@ -92,14 +94,14 @@
for y in [43, 4.3, "bar", []]:
expected1 = spec[type(x)]
expected2 = spec[type(y)]
- if (expected1 == 'f') ^ (expected2 == 'f'):
- if expected1 == 'f': expected1 = 'o'
- if expected2 == 'f': expected2 = 'o'
+ if expected1 + expected2 not in have:
+ expected1 = expected2 = 'o'
obj = (x, y)
assert self.isspecialised(obj, '_' + expected1 + expected2)
#
- obj = (1, 2, 3)
- assert self.isspecialised(obj, '_ooo')
+ if 'ooo' in have:
+ obj = (1, 2, 3)
+ assert self.isspecialised(obj, '_ooo')
def test_delegation(self):
t = self.forbid_delegation((42, 43))
@@ -214,6 +216,8 @@
raises(IndexError, "t[-3]")
def test_three_tuples(self):
+ if not self.isspecialised((1, 2, 3)):
+ skip("don't have specialization for 3-tuples")
b = self.forbid_delegation((1, 2, 3))
c = (1,)
d = c + (2, 3)
@@ -221,6 +225,16 @@
assert b == d
def test_mongrel(self):
+ a = self.forbid_delegation((2.2, '333'))
+ assert self.isspecialised(a)
+ assert len(a) == 2
+ assert a[0] == 2.2 and a[1] == '333'
+ b = ('333',)
+ assert a == (2.2,) + b
+ assert not a != (2.2,) + b
+ #
+ if not self.isspecialised((1, 2, 3)):
+ skip("don't have specialization for 3-tuples")
a = self.forbid_delegation((1, 2.2, '333'))
assert self.isspecialised(a)
assert len(a) == 3
More information about the pypy-commit
mailing list