Author: Alex Gaynor <alex.gay...@gmail.com> Branch: Changeset: r45702:a4096819e9eb Date: 2011-07-17 15:02 -0700 http://bitbucket.org/pypy/pypy/changeset/a4096819e9eb/
Log: merged upstream. diff --git a/pypy/jit/codewriter/jtransform.py b/pypy/jit/codewriter/jtransform.py --- a/pypy/jit/codewriter/jtransform.py +++ b/pypy/jit/codewriter/jtransform.py @@ -1118,6 +1118,9 @@ 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 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 @@ -244,6 +244,12 @@ 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 @@ 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 @@ 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 @@ __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), 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 @@ -43,6 +43,38 @@ 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)) 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 @@ -336,10 +336,10 @@ 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) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit