[pypy-commit] pypy win64-stage1: Merge with default
ctismer
noreply at buildbot.pypy.org
Tue Mar 13 02:18:28 CET 2012
Author: Christian Tismer <tismer at stackless.com>
Branch: win64-stage1
Changeset: r53405:488a554c2c72
Date: 2012-03-12 18:17 -0700
http://bitbucket.org/pypy/pypy/changeset/488a554c2c72/
Log: Merge with default
diff --git a/pypy/annotation/builtin.py b/pypy/annotation/builtin.py
--- a/pypy/annotation/builtin.py
+++ b/pypy/annotation/builtin.py
@@ -301,7 +301,7 @@
def robjmodel_instantiate(s_clspbc):
assert isinstance(s_clspbc, SomePBC)
clsdef = None
- more_than_one = len(s_clspbc.descriptions)
+ more_than_one = len(s_clspbc.descriptions) > 1
for desc in s_clspbc.descriptions:
cdef = desc.getuniqueclassdef()
if more_than_one:
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
@@ -89,6 +89,9 @@
("multiply", "multiply"),
("negative", "negative"),
("not_equal", "not_equal"),
+ ("radians", "radians"),
+ ("degrees", "degrees"),
+ ("deg2rad", "radians"),
("reciprocal", "reciprocal"),
("sign", "sign"),
("sin", "sin"),
@@ -111,6 +114,7 @@
('log2', 'log2'),
('log10', 'log10'),
('log1p', 'log1p'),
+ ('power', 'power'),
]:
interpleveldefs[exposed] = "interp_ufuncs.get(space).%s" % impl
diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -443,6 +443,9 @@
("arccosh", "arccosh", 1, {"promote_to_float": True}),
("arctanh", "arctanh", 1, {"promote_to_float": True}),
+ ("radians", "radians", 1, {"promote_to_float": True}),
+ ("degrees", "degrees", 1, {"promote_to_float": True}),
+
("log", "log", 1, {"promote_to_float": True}),
("log2", "log2", 1, {"promote_to_float": True}),
("log10", "log10", 1, {"promote_to_float": True}),
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
@@ -376,6 +376,45 @@
assert math.isnan(sqrt(-1))
assert math.isnan(sqrt(nan))
+ def test_radians(self):
+ import math
+ from _numpypy import radians, array
+ a = array([
+ -181, -180, -179,
+ 181, 180, 179,
+ 359, 360, 361,
+ 400, -1, 0, 1,
+ float('inf'), float('-inf')])
+ b = radians(a)
+ for i in range(len(a)):
+ assert b[i] == math.radians(a[i])
+
+ def test_deg2rad(self):
+ import math
+ from _numpypy import deg2rad, array
+ a = array([
+ -181, -180, -179,
+ 181, 180, 179,
+ 359, 360, 361,
+ 400, -1, 0, 1,
+ float('inf'), float('-inf')])
+ b = deg2rad(a)
+ for i in range(len(a)):
+ assert b[i] == math.radians(a[i])
+
+ def test_degrees(self):
+ import math
+ from _numpypy import degrees, array
+ a = array([
+ -181, -180, -179,
+ 181, 180, 179,
+ 359, 360, 361,
+ 400, -1, 0, 1,
+ float('inf'), float('-inf')])
+ b = degrees(a)
+ for i in range(len(a)):
+ assert b[i] == math.degrees(a[i])
+
def test_reduce_errors(self):
from _numpypy import sin, add
@@ -504,3 +543,17 @@
assert log1p(v) == float("-inf")
assert log1p(float('inf')) == float('inf')
assert (log1p([0, 1e-50, math.e - 1]) == [0, 1e-50, 1]).all()
+
+ def test_power(self):
+ import math
+ from _numpypy import power, array
+ a = array([1., 2., 3.])
+ b = power(a, 3)
+ for i in range(len(a)):
+ assert b[i] == a[i] ** 3
+
+ a = array([1., 2., 3.])
+ b = array([1., 2., 3.])
+ c = power(a, b)
+ for i in range(len(a)):
+ assert c[i] == a[i] ** b[i]
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
@@ -10,6 +10,8 @@
from pypy.rpython.lltypesystem import lltype, rffi
from pypy.rlib.rstruct.runpack import runpack
+degToRad = math.pi / 180.0
+log2 = math.log(2)
def simple_unary_op(func):
specialize.argtype(1)(func)
@@ -426,7 +428,7 @@
@simple_binary_op
def floordiv(self, v1, v2):
try:
- return v1 // v2
+ return math.floor(v1 / v2)
except ZeroDivisionError:
if v1 == v2 == 0.0:
return rfloat.NAN
@@ -549,6 +551,15 @@
return rfloat.isinf(v)
@simple_unary_op
+ def radians(self, v):
+ return v * degToRad
+ deg2rad = radians
+
+ @simple_unary_op
+ def degrees(self, v):
+ return v / degToRad
+
+ @simple_unary_op
def log(self, v):
try:
return math.log(v)
@@ -562,7 +573,7 @@
@simple_unary_op
def log2(self, v):
try:
- return math.log(v, 2)
+ return math.log(v) / log2
except ValueError:
if v == 0.0:
# CPython raises ValueError here, so we have to check
diff --git a/pypy/objspace/std/stringobject.py b/pypy/objspace/std/stringobject.py
--- a/pypy/objspace/std/stringobject.py
+++ b/pypy/objspace/std/stringobject.py
@@ -56,9 +56,18 @@
return w_self._value
def unicode_w(w_self, space):
- # XXX should this use the default encoding?
- from pypy.objspace.std.unicodetype import plain_str2unicode
- return plain_str2unicode(space, w_self._value)
+ # Use the default encoding.
+ from pypy.objspace.std.unicodetype import unicode_from_string, \
+ decode_object
+ w_defaultencoding = space.call_function(space.sys.get(
+ 'getdefaultencoding'))
+ from pypy.objspace.std.unicodetype import _get_encoding_and_errors, \
+ unicode_from_string, decode_object
+ encoding, errors = _get_encoding_and_errors(space, w_defaultencoding,
+ space.w_None)
+ if encoding is None and errors is None:
+ return space.unicode_w(unicode_from_string(space, w_self))
+ return space.unicode_w(decode_object(space, w_self, encoding, errors))
registerimplementation(W_StringObject)
diff --git a/pypy/objspace/std/test/test_stringobject.py b/pypy/objspace/std/test/test_stringobject.py
--- a/pypy/objspace/std/test/test_stringobject.py
+++ b/pypy/objspace/std/test/test_stringobject.py
@@ -501,6 +501,35 @@
raises(TypeError, ''.join, [1])
raises(TypeError, ''.join, [[1]])
+ def test_unicode_join_str_arg_ascii(self):
+ raises(UnicodeDecodeError, u''.join, ['\xc3\xa1'])
+
+ def test_unicode_join_str_arg_utf8(self):
+ # Need default encoding utf-8, but sys.setdefaultencoding
+ # is removed after startup.
+ import sys
+ old_encoding = sys.getdefaultencoding()
+ # Duplicate unittest.test_support.CleanImport logic because it won't
+ # import.
+ self.original_modules = sys.modules.copy()
+ try:
+ import sys as temp_sys
+ module_name = 'sys'
+ if module_name in sys.modules:
+ module = sys.modules[module_name]
+ # It is possible that module_name is just an alias for
+ # another module (e.g. stub for modules renamed in 3.x).
+ # In that case, we also need delete the real module to
+ # clear the import cache.
+ if module.__name__ != module_name:
+ del sys.modules[module.__name__]
+ del sys.modules[module_name]
+ temp_sys.setdefaultencoding('utf-8')
+ assert u''.join(['\xc3\xa1']) == u'\xe1'
+ finally:
+ temp_sys.setdefaultencoding(old_encoding)
+ sys.modules.update(self.original_modules)
+
def test_unicode_join_endcase(self):
# This class inserts a Unicode object into its argument's natural
# iteration, in the 3rd position.
More information about the pypy-commit
mailing list