[pypy-commit] pypy py3.5-ssl: fixed slicelength and parameter to decode_index4, renamed some methods, [::-1] for multi dim. memoryview works
plan_rich
pypy.commits at gmail.com
Fri Dec 2 11:52:17 EST 2016
Author: Richard Plangger <planrichi at gmail.com>
Branch: py3.5-ssl
Changeset: r88830:bd39209dafe3
Date: 2016-12-02 17:51 +0100
http://bitbucket.org/pypy/pypy/changeset/bd39209dafe3/
Log: fixed slicelength and parameter to decode_index4, renamed some
methods, [::-1] for multi dim. memoryview works
diff --git a/pypy/module/struct/formatiterator.py b/pypy/module/struct/formatiterator.py
--- a/pypy/module/struct/formatiterator.py
+++ b/pypy/module/struct/formatiterator.py
@@ -159,13 +159,12 @@
def skip(self, count):
# assumption: UnpackFormatIterator only iterates over
- # flat structures (continous memory) either, forward (index
- # is increasing) or reverse
+ # flat structures (continous memory) either: forward (index
+ # grows) or reverse
if self.strides:
assert len(self.strides) == 1
- end = self.pos + count * self.strides[0]
- else:
- end = self.pos + count
+ count = self.strides[0]
+ end = self.pos + count
if end > self.length:
raise StructError("unpack str size too short for format")
self.pos = end
diff --git a/pypy/objspace/std/memoryobject.py b/pypy/objspace/std/memoryobject.py
--- a/pypy/objspace/std/memoryobject.py
+++ b/pypy/objspace/std/memoryobject.py
@@ -199,7 +199,6 @@
items = [None] * dimshape
for i in range(dimshape):
- import pdb; pdb.set_trace()
buf = SubBuffer(buf, start, stride)
item = self._tolist_rec(space, buf, start, idim+1, fmt)
items[i] = item
@@ -267,7 +266,8 @@
if space.isinstance_w(w_index, space.w_tuple):
return self._getitem_tuple_indexed(space, w_index)
- start, stop, step, size = space.decode_index4(w_index, self.getlength())
+ shape = self.getshape()
+ start, stop, step, slicelength = space.decode_index4(w_index, shape[0])
# ^^^ for a non-slice index, this returns (index, 0, 0, 1)
if step == 0: # index only
itemsize = self.getitemsize()
@@ -289,28 +289,27 @@
return fmtiter.result_w[0]
elif step == 1:
mv = W_MemoryView.copy(self)
- mv.slice(start, step, size)
+ mv.init_slice(start, stop, step, slicelength, 0)
mv._init_flags()
return mv
else:
mv = W_MemoryView.copy(self)
- mv.slice(start, step, size)
- mv.length = mv.bytecount_from_shape()
+ mv.init_slice(start, stop, step, slicelength, 0)
+ mv.init_len()
mv._init_flags()
return mv
- def slice(self, start, step, size):
+ def init_slice(self, start, stop, step, slicelength, dim):
# modifies the buffer, shape and stride to allow step to be > 1
# TODO subbuffer
- strides = self.getstrides()[:]
- shape = self.getshape()[:]
- itemsize = self.getitemsize()
- dim = 0
- self.buf = SubBuffer(self.buf, strides[dim] * start, itemsize)
- shape[dim] = size
+ self.strides = strides = self.getstrides()[:]
+ self.shape = shape = self.getshape()[:]
+ self.buf = SubBuffer(self.buf, strides[dim] * start, slicelength)
+ shape[dim] = slicelength
strides[dim] = strides[dim] * step
- self.strides = strides
- self.shape = shape
+
+ def init_len(self):
+ self.length = self.bytecount_from_shape()
def bytecount_from_shape(self):
dim = self.getndim()
@@ -629,8 +628,6 @@
return None
def _cast_to_ND(self, space, shape, ndim):
- buf = self.buf
-
self.ndim = ndim
length = self.itemsize
if ndim == 0:
diff --git a/pypy/objspace/std/test/test_memoryobject.py b/pypy/objspace/std/test/test_memoryobject.py
--- a/pypy/objspace/std/test/test_memoryobject.py
+++ b/pypy/objspace/std/test/test_memoryobject.py
@@ -437,6 +437,6 @@
view = memoryview(bytes)
bview = view.cast('b')
rview = bview.cast(fmt, shape=(2,3))
+ raises(NotImplementedError, list, reversed(rview))
assert rview.tolist() == [[1,2,3],[9,7,5]]
- assert rview[::-1].tolist() == [[3,2,1], [5,7,9]]
- raises(NotImplementedError, list, reversed(rview))
+ assert rview[::-1].tolist() == [[9,7,5], [1,2,3]]
More information about the pypy-commit
mailing list