[pypy-commit] pypy default: merge with default
dripton
noreply at buildbot.pypy.org
Tue Mar 13 18:25:36 CET 2012
Author: David Ripton <dripton at ripton.net>
Branch:
Changeset: r53447:ac8028838f6d
Date: 2012-03-13 10:17 -0700
http://bitbucket.org/pypy/pypy/changeset/ac8028838f6d/
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/annotation/model.py b/pypy/annotation/model.py
--- a/pypy/annotation/model.py
+++ b/pypy/annotation/model.py
@@ -786,12 +786,15 @@
#
# safety check that no-one is trying to make annotation and translation
# faster by providing the -O option to Python.
-try:
- assert False
-except AssertionError:
- pass # fine
-else:
- raise RuntimeError("The annotator relies on 'assert' statements from the\n"
+import os
+if "WINGDB_PYTHON" not in os.environ:
+ # ...but avoiding this boring check in the IDE
+ try:
+ assert False
+ except AssertionError:
+ pass # fine
+ else:
+ raise RuntimeError("The annotator relies on 'assert' statements from the\n"
"\tannotated program: you cannot run it with 'python -O'.")
# this has the side-effect of registering the unary and binary operations
diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py b/pypy/interpreter/astcompiler/test/test_compiler.py
--- a/pypy/interpreter/astcompiler/test/test_compiler.py
+++ b/pypy/interpreter/astcompiler/test/test_compiler.py
@@ -58,7 +58,8 @@
w_res = pyco_expr.exec_host_bytecode(w_dict, w_dict)
res = space.str_w(space.repr(w_res))
if not isinstance(expected, float):
- assert res == repr(expected)
+ noL = lambda expr: expr.replace('L', '')
+ assert noL(res) == noL(repr(expected))
else:
# Float representation can vary a bit between interpreter
# versions, compare the numbers instead.
diff --git a/pypy/interpreter/test/test_compiler.py b/pypy/interpreter/test/test_compiler.py
--- a/pypy/interpreter/test/test_compiler.py
+++ b/pypy/interpreter/test/test_compiler.py
@@ -794,7 +794,7 @@
def test_tuple_constants(self):
ns = {}
exec "x = (1, 0); y = (1L, 0L)" in ns
- assert isinstance(ns["x"][0], int)
+ assert isinstance(ns["x"][0], (int, long))
assert isinstance(ns["y"][0], long)
def test_division_folding(self):
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,8 @@
('log2', 'log2'),
('log10', 'log10'),
('log1p', 'log1p'),
+ ('power', 'power'),
+ ('floor_divide', 'floor_divide'),
]:
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,24 @@
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]
+
+ def test_floordiv(self):
+ from _numpypy import floor_divide, array
+ a = array([1., 2., 3., 4., 5., 6., 6.01])
+ b = floor_divide(a, 2.5)
+ for i in range(len(a)):
+ assert b[i] == a[i] // 2.5
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
More information about the pypy-commit
mailing list