Commit f1d59ad5 authored by Alex Gaynor's avatar Alex Gaynor
Browse files

merged upstream.

......@@ -1118,6 +1118,9 @@ class Transformer(object):
return meth(op, args, *descrs)
def _get_list_nonneg_canraise_flags(self, op):
# XXX as far as I can see, this function will always return True
# because functions that are neither nonneg nor fast don't have an
# oopspec any more
# xxx break of abstraction:
func = get_funcobj(op.args[0].value)._callable
# base hints on the name of the ll function, which is a bit xxx-ish
......
......@@ -244,6 +244,12 @@ class BaseArray(Wrappable):
def descr_len(self, space):
return self.get_concrete().descr_len(space)
def descr_repr(self, space):
return self.get_concrete()._repr(space)
def descr_str(self, space):
return self.get_concrete()._str(space)
def descr_getitem(self, space, w_idx):
# TODO: indexing by tuples
start, stop, step, slice_length = space.decode_index4(w_idx, self.find_size())
......@@ -433,6 +439,26 @@ class SingleDimSlice(ViewArray):
def calc_index(self, item):
return (self.start + item * self.step)
def _getnums(self, comma):
if self.find_size() > 1000:
nums = [str(self.getitem(index)) for index \
in range(3)]
nums.append("..." + "," * comma)
nums.extend([str(self.getitem(index)) for index \
in range(self.find_size() - 3, self.find_size())])
else:
nums = [str(self.getitem(index)) for index \
in range(self.find_size())]
return nums
def _repr(self, space):
# Simple implementation so that we can see the array. Needs work.
return space.wrap("array([" + ", ".join(self._getnums(False)) + "])")
def _str(self,space):
# Simple implementation so that we can see the array. Needs work.
return space.wrap("[" + " ".join(self._getnums(True)) + "]")
class SingleDimArray(BaseArray):
signature = Signature()
......@@ -470,6 +496,26 @@ class SingleDimArray(BaseArray):
def getitem(self, item):
return self.storage[item]
def _getnums(self, comma):
if self.find_size() > 1000:
nums = [str(self.getitem(index)) for index \
in range(3)]
nums.append("..." + "," * comma)
nums.extend([str(self.getitem(index)) for index \
in range(self.find_size() - 3, self.find_size())])
else:
nums = [str(self.getitem(index)) for index \
in range(self.find_size())]
return nums
def _repr(self, space):
# Simple implementation so that we can see the array. Needs work.
return space.wrap("array([" + ", ".join(self._getnums(False)) + "])")
def _str(self,space):
# Simple implementation so that we can see the array. Needs work.
return space.wrap("[" + " ".join(self._getnums(True)) + "]")
@unwrap_spec(item=int, value=float)
def descr_setitem(self, space, item, value):
item = self.getindex(space, item)
......@@ -527,6 +573,8 @@ BaseArray.typedef = TypeDef(
__rdiv__ = interp2app(BaseArray.descr_rdiv),
__rpow__ = interp2app(BaseArray.descr_rpow),
__rmod__ = interp2app(BaseArray.descr_rmod),
__repr__ = interp2app(BaseArray.descr_repr),
__str__ = interp2app(BaseArray.descr_str),
mean = interp2app(BaseArray.descr_mean),
sum = interp2app(BaseArray.descr_sum),
......
......@@ -43,6 +43,38 @@ class AppTestNumArray(BaseNumpyAppTest):
a = array(range(5))
assert a[3] == 3
def test_repr(self):
from numpy import array, zeros
a = array(range(5))
assert repr(a) == "array([0.0, 1.0, 2.0, 3.0, 4.0])"
a = zeros(1001)
assert repr(a) == "array([0.0, 0.0, 0.0, ..., 0.0, 0.0, 0.0])"
def test_repr_slice(self):
from numpy import array, zeros
a = array(range(5))
b = a[1::2]
assert repr(b) == "array([1.0, 3.0])"
a = zeros(2002)
b = a[::2]
assert repr(b) == "array([0.0, 0.0, 0.0, ..., 0.0, 0.0, 0.0])"
def test_str(self):
from numpy import array, zeros
a = array(range(5))
assert str(a) == "[0.0 1.0 2.0 3.0 4.0]"
a = zeros(1001)
assert str(a) == "[0.0 0.0 0.0 ..., 0.0 0.0 0.0]"
def test_str_slice(self):
from numpy import array, zeros
a = array(range(5))
b = a[1::2]
assert str(b) == "[1.0 3.0]"
a = zeros(2002)
b = a[::2]
assert str(b) == "[0.0 0.0 0.0 ..., 0.0 0.0 0.0]"
def test_getitem(self):
from numpy import array
a = array(range(5))
......
......@@ -336,10 +336,10 @@ def import_log(logname, ParserCls=SimpleParser):
log = parse_log_file(logname)
addrs = {}
for entry in extract_category(log, 'jit-backend-addr'):
m = re.search('bootstrap ([\da-f]+)', entry)
m = re.search('bootstrap ([-\da-f]+)', entry)
if not m:
# a bridge
m = re.search('has address ([\da-f]+)', entry)
m = re.search('has address ([-\da-f]+)', entry)
addr = int(m.group(1), 16)
entry = entry.lower()
m = re.search('guard \d+', entry)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment