Author: Timo Paulssen <timona...@perpetuum-immobile.de> Branch: numpy-data-buffer Changeset: r47783:b2f6f9ba6200 Date: 2011-10-03 08:05 +0200 http://bitbucket.org/pypy/pypy/changeset/b2f6f9ba6200/
Log: test str(NumpyBuffer), fix incorrect size constraints in views. diff --git a/pypy/module/_numpy/interp_buffer.py b/pypy/module/_numpy/interp_buffer.py --- a/pypy/module/_numpy/interp_buffer.py +++ b/pypy/module/_numpy/interp_buffer.py @@ -12,19 +12,19 @@ return self.array.get_concrete().find_size() * self.array.find_dtype().num_bytes def getitem(self, index): - index = self.calc_index(index) if index > self.getlength(): raise IndexError("Index out of bounds (0<=index<%d)" % self.getlength()) storage = self.array.get_concrete().get_root_storage() char_data = rffi.cast(CHAR_TP, storage) + index = self.calc_index(index) return char_data[index] def setitem(self, index, value): - index = self.calc_index(index) if index > self.getlength(): raise IndexError("Index out of bounds (0<=index<%d)" % self.getlength()) storage = self.array.get_concrete().get_root_storage() char_ptr = rffi.cast(CHAR_TP, storage) + index = self.calc_index(index) char_ptr[index] = value def setslice(self, index, newstring): diff --git a/pypy/module/_numpy/test/test_buffer.py b/pypy/module/_numpy/test/test_buffer.py --- a/pypy/module/_numpy/test/test_buffer.py +++ b/pypy/module/_numpy/test/test_buffer.py @@ -63,7 +63,7 @@ assert arbuf[1] == '\5' assert viewbuf[0] == '\5' - assert len(view) == len(ar) - 2 == 3 + assert len(viewbuf) == len(arbuf) - 2 == 3 br = array(range(5,10), dtype=float) buf = br.data @@ -161,3 +161,39 @@ assert ar[4] == 1 # tests for float dtype already done above + + def test_convert_to_string(self): + from _numpy import array + from _numpy import dtype + ar = array(range(5,10), dtype=dtype("int8")) + buf = ar.data + as_str = str(buf) + + for idx in range(len(buf)): + assert buf[idx] == as_str[idx] + + br = array(range(5,10), dtype=float) + buf = br.data + bs_str = str(buf) + + for idx in range(len(buf)): + assert buf[idx] == bs_str[idx] + + def test_convert_view_to_string(self): + from _numpy import array + from _numpy import dtype + ar = array(range(5,10), dtype=dtype("int8")) + view = ar[1:-1] + buf = view.data + as_str = str(buf) + + for idx in range(len(buf)): + assert buf[idx] == as_str[idx] + + br = array(range(5,10), dtype=float) + view = br[1:-1] + buf = view.data + bs_str = str(buf) + + for idx in range(len(buf)): + assert buf[idx] == bs_str[idx] _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit