[pypy-commit] pypy jit-usable_retrace_2: hg merge default
hakanardo
noreply at buildbot.pypy.org
Wed Jan 4 15:48:43 CET 2012
Author: Hakan Ardo <hakan at debian.org>
Branch: jit-usable_retrace_2
Changeset: r51019:ca3d9cd45ea5
Date: 2012-01-04 13:07 +0100
http://bitbucket.org/pypy/pypy/changeset/ca3d9cd45ea5/
Log: hg merge default
diff --git a/pypy/jit/metainterp/optimizeopt/test/test_multilabel.py b/pypy/jit/metainterp/optimizeopt/test/test_multilabel.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_multilabel.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_multilabel.py
@@ -442,6 +442,22 @@
"""
self.optimize_loop(ops, expected)
+ def test_optimizer_renaming_boxes_not_imported(self):
+ ops = """
+ [p1]
+ i1 = strlen(p1)
+ label(p1)
+ jump(p1)
+ """
+ expected = """
+ [p1]
+ i1 = strlen(p1)
+ label(p1, i1)
+ i11 = same_as(i1)
+ jump(p1, i11)
+ """
+ self.optimize_loop(ops, expected)
+
class TestLLtype(OptimizeoptTestMultiLabel, LLtypeMixin):
diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py
--- a/pypy/jit/metainterp/optimizeopt/unroll.py
+++ b/pypy/jit/metainterp/optimizeopt/unroll.py
@@ -287,6 +287,10 @@
if newresult is not op.result and not newvalue.is_constant():
op = ResOperation(rop.SAME_AS, [op.result], newresult)
self.optimizer._newoperations.append(op)
+ if self.optimizer.loop.logops:
+ debug_print(' Falling back to add extra: ' +
+ self.optimizer.loop.logops.repr_of_resop(op))
+
self.optimizer.flush()
self.optimizer.emitting_dissabled = False
@@ -451,7 +455,13 @@
return
for a in op.getarglist():
if not isinstance(a, Const) and a not in seen:
- self.ensure_short_op_emitted(self.short_boxes.producer(a), optimizer, seen)
+ self.ensure_short_op_emitted(self.short_boxes.producer(a), optimizer,
+ seen)
+
+ if self.optimizer.loop.logops:
+ debug_print(' Emitting short op: ' +
+ self.optimizer.loop.logops.repr_of_resop(op))
+
optimizer.send_extra_operation(op)
seen[op.result] = True
if op.is_ovf():
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
@@ -380,6 +380,9 @@
def descr_get_dtype(self, space):
return space.wrap(self.find_dtype())
+ def descr_get_ndim(self, space):
+ return space.wrap(len(self.shape))
+
@jit.unroll_safe
def descr_get_shape(self, space):
return space.newtuple([space.wrap(i) for i in self.shape])
@@ -409,7 +412,7 @@
def descr_repr(self, space):
res = StringBuilder()
res.append("array(")
- concrete = self.get_concrete()
+ concrete = self.get_concrete_or_scalar()
dtype = concrete.find_dtype()
if not concrete.size:
res.append('[]')
@@ -422,8 +425,9 @@
else:
concrete.to_str(space, 1, res, indent=' ')
if (dtype is not interp_dtype.get_dtype_cache(space).w_float64dtype and
- dtype is not interp_dtype.get_dtype_cache(space).w_int64dtype) or \
- not self.size:
+ not (dtype.kind == interp_dtype.SIGNEDLTR and
+ dtype.itemtype.get_element_size() == rffi.sizeof(lltype.Signed)) or
+ not self.size):
res.append(", dtype=" + dtype.name)
res.append(")")
return space.wrap(res.build())
@@ -840,80 +844,80 @@
each line will begin with indent.
'''
size = self.size
+ ccomma = ',' * comma
+ ncomma = ',' * (1 - comma)
+ dtype = self.find_dtype()
if size < 1:
builder.append('[]')
return
+ elif size == 1:
+ builder.append(dtype.itemtype.str_format(self.getitem(0)))
+ return
if size > 1000:
# Once this goes True it does not go back to False for recursive
# calls
use_ellipsis = True
- dtype = self.find_dtype()
ndims = len(self.shape)
i = 0
- start = True
builder.append('[')
if ndims > 1:
if use_ellipsis:
- for i in range(3):
- if start:
- start = False
- else:
- builder.append(',' * comma + '\n')
- if ndims == 3:
+ for i in range(min(3, self.shape[0])):
+ if i > 0:
+ builder.append(ccomma + '\n')
+ if ndims >= 3:
builder.append('\n' + indent)
else:
builder.append(indent)
- # create_slice requires len(chunks) > 1 in order to reduce
- # shape
- view = self.create_slice([(i, 0, 0, 1), (0, self.shape[1], 1, self.shape[1])]).get_concrete()
- view.to_str(space, comma, builder, indent=indent + ' ', use_ellipsis=use_ellipsis)
- builder.append('\n' + indent + '..., ')
- i = self.shape[0] - 3
+ view = self.create_slice([(i, 0, 0, 1)]).get_concrete()
+ view.to_str(space, comma, builder, indent=indent + ' ',
+ use_ellipsis=use_ellipsis)
+ if i < self.shape[0] - 1:
+ builder.append(ccomma +'\n' + indent + '...' + ncomma)
+ i = self.shape[0] - 3
+ else:
+ i += 1
while i < self.shape[0]:
- if start:
- start = False
- else:
- builder.append(',' * comma + '\n')
- if ndims == 3:
+ if i > 0:
+ builder.append(ccomma + '\n')
+ if ndims >= 3:
builder.append('\n' + indent)
else:
builder.append(indent)
# create_slice requires len(chunks) > 1 in order to reduce
# shape
- view = self.create_slice([(i, 0, 0, 1), (0, self.shape[1], 1, self.shape[1])]).get_concrete()
- view.to_str(space, comma, builder, indent=indent + ' ', use_ellipsis=use_ellipsis)
+ view = self.create_slice([(i, 0, 0, 1)]).get_concrete()
+ view.to_str(space, comma, builder, indent=indent + ' ',
+ use_ellipsis=use_ellipsis)
i += 1
elif ndims == 1:
- spacer = ',' * comma + ' '
+ spacer = ccomma + ' '
item = self.start
# An iterator would be a nicer way to walk along the 1d array, but
# how do I reset it if printing ellipsis? iterators have no
# "set_offset()"
i = 0
if use_ellipsis:
- for i in range(3):
- if start:
- start = False
- else:
+ for i in range(min(3, self.shape[0])):
+ if i > 0:
builder.append(spacer)
builder.append(dtype.itemtype.str_format(self.getitem(item)))
item += self.strides[0]
- # Add a comma only if comma is False - this prevents adding two
- # commas
- builder.append(spacer + '...' + ',' * (1 - comma))
- # Ugly, but can this be done with an iterator?
- item = self.start + self.backstrides[0] - 2 * self.strides[0]
- i = self.shape[0] - 3
+ if i < self.shape[0] - 1:
+ # Add a comma only if comma is False - this prevents adding
+ # two commas
+ builder.append(spacer + '...' + ncomma)
+ # Ugly, but can this be done with an iterator?
+ item = self.start + self.backstrides[0] - 2 * self.strides[0]
+ i = self.shape[0] - 3
+ else:
+ i += 1
while i < self.shape[0]:
- if start:
- start = False
- else:
+ if i > 0:
builder.append(spacer)
builder.append(dtype.itemtype.str_format(self.getitem(item)))
item += self.strides[0]
i += 1
- else:
- builder.append('[')
builder.append(']')
@jit.unroll_safe
@@ -1185,6 +1189,7 @@
shape = GetSetProperty(BaseArray.descr_get_shape,
BaseArray.descr_set_shape),
size = GetSetProperty(BaseArray.descr_get_size),
+ ndim = GetSetProperty(BaseArray.descr_get_ndim),
T = GetSetProperty(BaseArray.descr_get_transpose),
flat = GetSetProperty(BaseArray.descr_get_flatiter),
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
@@ -158,6 +158,7 @@
assert calc_new_strides([24], [2, 4, 3], [48, 6, 1]) is None
assert calc_new_strides([24], [2, 4, 3], [24, 6, 2]) == [2]
+
class AppTestNumArray(BaseNumpyAppTest):
def test_ndarray(self):
from numpypy import ndarray, array, dtype
@@ -179,6 +180,20 @@
ar = array(range(5))
assert type(ar) is type(ar + ar)
+ def test_ndim(self):
+ from numpypy import array
+ x = array(0.2)
+ assert x.ndim == 0
+ x = array([1, 2])
+ assert x.ndim == 1
+ x = array([[1, 2], [3, 4]])
+ assert x.ndim == 2
+ x = array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
+ assert x.ndim == 3
+ # numpy actually raises an AttributeError, but numpypy raises an
+ # TypeError
+ raises(TypeError, 'x.ndim = 3')
+
def test_init(self):
from numpypy import zeros
a = zeros(15)
@@ -725,19 +740,19 @@
a = identity(0)
assert len(a) == 0
assert a.dtype == dtype('float64')
- assert a.shape == (0,0)
+ assert a.shape == (0, 0)
b = identity(1, dtype=int32)
assert len(b) == 1
assert b[0][0] == 1
- assert b.shape == (1,1)
+ assert b.shape == (1, 1)
assert b.dtype == dtype('int32')
c = identity(2)
- assert c.shape == (2,2)
- assert (c == [[1,0],[0,1]]).all()
+ assert c.shape == (2, 2)
+ assert (c == [[1, 0], [0, 1]]).all()
d = identity(3, dtype='int32')
- assert d.shape == (3,3)
+ assert d.shape == (3, 3)
assert d.dtype == dtype('int32')
- assert (d == [[1,0,0],[0,1,0],[0,0,1]]).all()
+ assert (d == [[1, 0, 0], [0, 1, 0], [0, 0, 1]]).all()
def test_prod(self):
from numpypy import array
@@ -954,13 +969,13 @@
def test_tolist_view(self):
from numpypy import array
- a = array([[1,2],[3,4]])
+ a = array([[1, 2], [3, 4]])
assert (a + a).tolist() == [[2, 4], [6, 8]]
def test_tolist_slice(self):
from numpypy import array
a = array([[17.1, 27.2], [40.3, 50.3]])
- assert a[:,0].tolist() == [17.1, 40.3]
+ assert a[:, 0].tolist() == [17.1, 40.3]
assert a[0].tolist() == [17.1, 27.2]
@@ -1090,11 +1105,11 @@
from numpypy import zeros, ones
a = zeros((3, 3))
b = ones((3, 3))
- a[:,1:3] = b[:,1:3]
+ a[:, 1:3] = b[:, 1:3]
assert (a == [[0, 1, 1], [0, 1, 1], [0, 1, 1]]).all()
a = zeros((3, 3))
b = ones((3, 3))
- a[:,::2] = b[:,::2]
+ a[:, ::2] = b[:, ::2]
assert (a == [[1, 0, 1], [1, 0, 1], [1, 0, 1]]).all()
def test_broadcast_ufunc(self):
@@ -1233,6 +1248,7 @@
assert isinstance(i['data'][0], int)
raises(TypeError, getattr, array(3), '__array_interface__')
+
class AppTestSupport(BaseNumpyAppTest):
def setup_class(cls):
import struct
@@ -1275,17 +1291,17 @@
assert g[1] == 2
assert g[2] == 3
h = fromstring("1, , 2, 3", dtype=uint8, sep=",")
- assert (h == [1,0,2,3]).all()
+ assert (h == [1, 0, 2, 3]).all()
i = fromstring("1 2 3", dtype=uint8, sep=" ")
- assert (i == [1,2,3]).all()
+ assert (i == [1, 2, 3]).all()
j = fromstring("1\t\t\t\t2\t3", dtype=uint8, sep="\t")
- assert (j == [1,2,3]).all()
+ assert (j == [1, 2, 3]).all()
k = fromstring("1,x,2,3", dtype=uint8, sep=",")
- assert (k == [1,0]).all()
+ assert (k == [1, 0]).all()
l = fromstring("1,x,2,3", dtype='float32', sep=",")
- assert (l == [1.0,-1.0]).all()
+ assert (l == [1.0, -1.0]).all()
m = fromstring("1,,2,3", sep=",")
- assert (m == [1.0,-1.0,2.0,3.0]).all()
+ assert (m == [1.0, -1.0, 2.0, 3.0]).all()
n = fromstring("3.4 2.0 3.8 2.2", dtype=int32, sep=" ")
assert (n == [3]).all()
o = fromstring("1.0 2f.0f 3.8 2.2", dtype=float32, sep=" ")
@@ -1333,7 +1349,6 @@
j = fromstring(self.ulongval, dtype='L')
assert j[0] == 12
-
def test_fromstring_invalid(self):
from numpypy import fromstring, uint16, uint8, int32
#default dtype is 64-bit float, so 3 bytes should fail
@@ -1347,6 +1362,7 @@
class AppTestRepr(BaseNumpyAppTest):
def test_repr(self):
from numpypy import array, zeros
+ int_size = array(5).dtype.itemsize
a = array(range(5), float)
assert repr(a) == "array([0.0, 1.0, 2.0, 3.0, 4.0])"
a = array([], float)
@@ -1354,14 +1370,26 @@
a = zeros(1001)
assert repr(a) == "array([0.0, 0.0, 0.0, ..., 0.0, 0.0, 0.0])"
a = array(range(5), long)
- assert repr(a) == "array([0, 1, 2, 3, 4])"
+ if a.dtype.itemsize == int_size:
+ assert repr(a) == "array([0, 1, 2, 3, 4])"
+ else:
+ assert repr(a) == "array([0, 1, 2, 3, 4], dtype=int64)"
+ a = array(range(5), 'int32')
+ if a.dtype.itemsize == int_size:
+ assert repr(a) == "array([0, 1, 2, 3, 4])"
+ else:
+ assert repr(a) == "array([0, 1, 2, 3, 4], dtype=int32)"
a = array([], long)
assert repr(a) == "array([], dtype=int64)"
a = array([True, False, True, False], "?")
assert repr(a) == "array([True, False, True, False], dtype=bool)"
+ a = zeros([])
+ assert repr(a) == "array(0.0)"
+ a = array(0.2)
+ assert repr(a) == "array(0.2)"
def test_repr_multi(self):
- from numpypy import array, zeros
+ from numpypy import arange, zeros
a = zeros((3, 4))
assert repr(a) == '''array([[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0],
@@ -1374,6 +1402,16 @@
[[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0]]])'''
+ a = arange(1002).reshape((2, 501))
+ assert repr(a) == '''array([[0, 1, 2, ..., 498, 499, 500],
+ [501, 502, 503, ..., 999, 1000, 1001]])'''
+ assert repr(a.T) == '''array([[0, 501],
+ [1, 502],
+ [2, 503],
+ ...,
+ [498, 999],
+ [499, 1000],
+ [500, 1001]])'''
def test_repr_slice(self):
from numpypy import array, zeros
@@ -1417,7 +1455,7 @@
a = zeros((400, 400), dtype=int)
assert str(a) == "[[0 0 0 ..., 0 0 0]\n [0 0 0 ..., 0 0 0]\n" \
- " [0 0 0 ..., 0 0 0]\n ..., \n [0 0 0 ..., 0 0 0]\n" \
+ " [0 0 0 ..., 0 0 0]\n ...,\n [0 0 0 ..., 0 0 0]\n" \
" [0 0 0 ..., 0 0 0]\n [0 0 0 ..., 0 0 0]]"
a = zeros((2, 2, 2))
r = str(a)
diff --git a/pypy/module/pypyjit/test_pypy_c/test_00_model.py b/pypy/module/pypyjit/test_pypy_c/test_00_model.py
--- a/pypy/module/pypyjit/test_pypy_c/test_00_model.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_00_model.py
@@ -8,10 +8,12 @@
from pypy.tool import logparser
from pypy.jit.tool.jitoutput import parse_prof
from pypy.module.pypyjit.test_pypy_c.model import (Log, find_ids_range,
- find_ids, TraceWithIds,
+ find_ids,
OpMatcher, InvalidMatch)
class BaseTestPyPyC(object):
+ log_string = 'jit-log-opt,jit-log-noopt,jit-log-virtualstate,jit-summary'
+
def setup_class(cls):
if '__pypy__' not in sys.builtin_module_names:
py.test.skip("must run this test with pypy")
@@ -52,8 +54,7 @@
cmdline += ['--jit', ','.join(jitcmdline)]
cmdline.append(str(self.filepath))
#
- print cmdline, logfile
- env={'PYPYLOG': 'jit-log-opt,jit-log-noopt,jit-log-virtualstate,jit-summary:' + str(logfile)}
+ env={'PYPYLOG': self.log_string + ':' + str(logfile)}
pipe = subprocess.Popen(cmdline,
env=env,
stdout=subprocess.PIPE,
diff --git a/pypy/module/pypyjit/test_pypy_c/test__ffi.py b/pypy/module/pypyjit/test_pypy_c/test__ffi.py
--- a/pypy/module/pypyjit/test_pypy_c/test__ffi.py
+++ b/pypy/module/pypyjit/test_pypy_c/test__ffi.py
@@ -98,7 +98,8 @@
end = time.time()
return end - start
#
- log = self.run(main, [get_libc_name(), 200], threshold=150)
+ log = self.run(main, [get_libc_name(), 200], threshold=150,
+ import_site=True)
assert 1 <= log.result <= 1.5 # at most 0.5 seconds of overhead
loops = log.loops_by_id('sleep')
assert len(loops) == 1 # make sure that we actually JITted the loop
@@ -121,7 +122,7 @@
return fabs._ptr.getaddr(), x
libm_name = get_libm_name(sys.platform)
- log = self.run(main, [libm_name])
+ log = self.run(main, [libm_name], import_site=True)
fabs_addr, res = log.result
assert res == -4.0
loop, = log.loops_by_filename(self.filepath)
diff --git a/pypy/module/pypyjit/test_pypy_c/test_string.py b/pypy/module/pypyjit/test_pypy_c/test_string.py
--- a/pypy/module/pypyjit/test_pypy_c/test_string.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_string.py
@@ -15,7 +15,7 @@
i += letters[i % len(letters)] == uletters[i % len(letters)]
return i
- log = self.run(main, [300])
+ log = self.run(main, [300], import_site=True)
assert log.result == 300
loop, = log.loops_by_filename(self.filepath)
assert loop.match("""
@@ -55,7 +55,7 @@
i += int(long(string.digits[i % len(string.digits)], 16))
return i
- log = self.run(main, [1100])
+ log = self.run(main, [1100], import_site=True)
assert log.result == main(1100)
loop, = log.loops_by_filename(self.filepath)
assert loop.match("""
diff --git a/pypy/tool/jitlogparser/parser.py b/pypy/tool/jitlogparser/parser.py
--- a/pypy/tool/jitlogparser/parser.py
+++ b/pypy/tool/jitlogparser/parser.py
@@ -185,7 +185,10 @@
return self.code.map[self.bytecode_no]
def getlineno(self):
- return self.getopcode().lineno
+ code = self.getopcode()
+ if code is None:
+ return None
+ return code.lineno
lineno = property(getlineno)
def getline_starts_here(self):
diff --git a/pypy/tool/jitlogparser/storage.py b/pypy/tool/jitlogparser/storage.py
--- a/pypy/tool/jitlogparser/storage.py
+++ b/pypy/tool/jitlogparser/storage.py
@@ -6,7 +6,6 @@
import py
import os
from lib_pypy.disassembler import dis
-from pypy.tool.jitlogparser.parser import Function
from pypy.tool.jitlogparser.module_finder import gather_all_code_objs
class LoopStorage(object):
More information about the pypy-commit
mailing list