Author: Armin Rigo <[email protected]>
Branch:
Changeset: r54195:057219807d73
Date: 2012-04-05 10:14 +0200
http://bitbucket.org/pypy/pypy/changeset/057219807d73/
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
@@ -105,6 +105,7 @@
("fmod", "fmod"),
("floor", "floor"),
("ceil", "ceil"),
+ ("trunc", "trunc"),
("greater", "greater"),
("greater_equal", "greater_equal"),
("less", "less"),
@@ -132,6 +133,8 @@
('bitwise_or', 'bitwise_or'),
('bitwise_xor', 'bitwise_xor'),
('bitwise_not', 'invert'),
+ ('left_shift', 'left_shift'),
+ ('right_shift', 'right_shift'),
('invert', 'invert'),
('isnan', 'isnan'),
('isinf', 'isinf'),
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
@@ -546,6 +546,7 @@
("fmod", "fmod", 2, {"promote_to_float": True}),
("floor", "floor", 1, {"promote_to_float": True}),
("ceil", "ceil", 1, {"promote_to_float": True}),
+ ("trunc", "trunc", 1, {"promote_to_float": True}),
("exp", "exp", 1, {"promote_to_float": True}),
("exp2", "exp2", 1, {"promote_to_float": True}),
("expm1", "expm1", 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
@@ -253,24 +253,17 @@
for i in range(3):
assert c[i] == a[i] - b[i]
- def test_floorceil(self):
- from _numpypy import array, floor, ceil
+ def test_floorceiltrunc(self):
+ from _numpypy import array, floor, ceil, trunc
import math
- reference = [-2.0, -2.0, -1.0, 0.0, 1.0, 1.0, 0]
- a = array([-1.4, -1.5, -1.0, 0.0, 1.0, 1.4, 0.5])
- b = floor(a)
- for i in range(5):
- assert b[i] == reference[i]
- reference = [-1.0, -1.0, -1.0, 0.0, 1.0, 2.0, 1.0]
- a = array([-1.4, -1.5, -1.0, 0.0, 1.0, 1.4, 0.5])
- b = ceil(a)
- assert (reference == b).all()
- inf = float("inf")
- data = [1.5, 2.9999, -1.999, inf]
- results = [math.floor(x) for x in data]
- assert (floor(data) == results).all()
- results = [math.ceil(x) for x in data]
- assert (ceil(data) == results).all()
+ ninf, inf = float("-inf"), float("inf")
+ a = array([ninf, -1.4, -1.5, -1.0, 0.0, 1.0, 1.4, 0.5, inf])
+ assert ([ninf, -2.0, -2.0, -1.0, 0.0, 1.0, 1.0, 0.0, inf] ==
floor(a)).all()
+ assert ([ninf, -1.0, -1.0, -1.0, 0.0, 1.0, 2.0, 1.0, inf] ==
ceil(a)).all()
+ assert ([ninf, -1.0, -1.0, -1.0, 0.0, 1.0, 1.0, 0.0, inf] ==
trunc(a)).all()
+ assert all([math.isnan(f(float("nan"))) for f in floor, ceil, trunc])
+ assert all([math.copysign(1, f(float("nan"))) == 1 for f in floor,
ceil, trunc])
+ assert all([math.copysign(1, f(float("-nan"))) == -1 for f in floor,
ceil, trunc])
def test_copysign(self):
from _numpypy import array, copysign
@@ -597,6 +590,13 @@
assert (bitwise_not(a) == ~a).all()
assert (invert(a) == ~a).all()
+ def test_shift(self):
+ from _numpypy import left_shift, right_shift
+ import sys
+
+ assert (left_shift([5, 1], [2, 31]) == [20, 2**31]).all()
+ assert (right_shift(10, range(5)) == [10, 5, 2, 1, 0]).all()
+
def test_comparisons(self):
import operator
from _numpypy import equal, not_equal, less, less_equal, greater,
greater_equal
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
@@ -668,6 +668,13 @@
return math.ceil(v)
@simple_unary_op
+ def trunc(self, v):
+ if v < 0:
+ return math.ceil(v)
+ else:
+ return math.floor(v)
+
+ @simple_unary_op
def exp(self, v):
try:
return math.exp(v)
diff --git a/pypy/rlib/rsre/rsre_re.py b/pypy/rlib/rsre/rsre_re.py
--- a/pypy/rlib/rsre/rsre_re.py
+++ b/pypy/rlib/rsre/rsre_re.py
@@ -172,8 +172,9 @@
self._ctx = ctx
def span(self, groupnum=0):
- if not isinstance(groupnum, (int, long)):
- groupnum = self.re.groupindex[groupnum]
+# if not isinstance(groupnum, (int, long)):
+# groupnum = self.re.groupindex[groupnum]
+
return self._ctx.span(groupnum)
def start(self, groupnum=0):
@@ -182,19 +183,25 @@
def end(self, groupnum=0):
return self.span(groupnum)[1]
- def group(self, *groups):
- groups = groups or (0,)
- result = []
- for group in groups:
- frm, to = self.span(group)
- if 0 <= frm <= to:
- result.append(self._ctx._string[frm:to])
- else:
- result.append(None)
- if len(result) > 1:
- return tuple(result)
+ def group(self, group=0):
+ frm, to = self.span(group)
+ if 0 <= frm <= to:
+ return self._ctx._string[frm:to]
else:
- return result[0]
+ return None
+
+# def group(self, *groups):
+# groups = groups or (0,)
+# result = []
+# for group in groups:
+# frm, to = self.span(group)
+# if 0 <= frm <= to:
+# result.append(self._ctx._string[frm:to])
+# else:
+# result.append(None)
+# if len(result) > 1:
+# return tuple(result)
+
def groups(self, default=None):
fmarks = self._ctx.flatten_marks()
diff --git a/pypy/rlib/rsre/test/test_re.py b/pypy/rlib/rsre/test/test_re.py
--- a/pypy/rlib/rsre/test/test_re.py
+++ b/pypy/rlib/rsre/test/test_re.py
@@ -204,7 +204,7 @@
assert re.match('(a)', 'a').groups() == ('a',)
assert re.match(r'(a)', 'a').group(0) == 'a'
assert re.match(r'(a)', 'a').group(1) == 'a'
- assert re.match(r'(a)', 'a').group(1, 1) == ('a', 'a')
+ #assert re.match(r'(a)', 'a').group(1, 1) == ('a', 'a')
pat = re.compile('((a)|(b))(c)?')
assert pat.match('a').groups() == ('a', 'a', None, None)
@@ -218,13 +218,13 @@
assert m.group(0) == 'a'
assert m.group(0) == 'a'
assert m.group(1) == 'a'
- assert m.group(1, 1) == ('a', 'a')
+ #assert m.group(1, 1) == ('a', 'a')
pat = re.compile('(?:(?P<a1>a)|(?P<b2>b))(?P<c3>c)?')
- assert pat.match('a').group(1, 2, 3) == ('a', None, None)
- assert pat.match('b').group('a1', 'b2', 'c3') == (
- (None, 'b', None))
- assert pat.match('ac').group(1, 'b2', 3) == ('a', None, 'c')
+ #assert pat.match('a').group(1, 2, 3) == ('a', None, None)
+ #assert pat.match('b').group('a1', 'b2', 'c3') == (
+ # (None, 'b', None))
+ #assert pat.match('ac').group(1, 'b2', 3) == ('a', None, 'c')
def test_bug_923(self):
# Issue923: grouping inside optional lookahead problem
diff --git a/pypy/rlib/rsre/test/test_zinterp.py
b/pypy/rlib/rsre/test/test_zinterp.py
--- a/pypy/rlib/rsre/test/test_zinterp.py
+++ b/pypy/rlib/rsre/test/test_zinterp.py
@@ -1,7 +1,8 @@
# minimal test: just checks that (parts of) rsre can be translated
-from pypy.rpython.test.test_llinterp import gengraph
+from pypy.rpython.test.test_llinterp import gengraph, interpret
from pypy.rlib.rsre import rsre_core
+from pypy.rlib.rsre.rsre_re import compile
def main(n):
assert n >= 0
@@ -19,3 +20,18 @@
def test_gengraph():
t, typer, graph = gengraph(main, [int])
+
+m = compile("(a|b)aaaaa")
+
+def test_match():
+ def f(i):
+ if i:
+ s = "aaaaaa"
+ else:
+ s = "caaaaa"
+ g = m.match(s)
+ if g is None:
+ return 3
+ return int("aaaaaa" == g.group(0))
+ assert interpret(f, [3]) == 1
+ assert interpret(f, [0]) == 3
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit