Author: Timo Paulssen <[email protected]>
Branch: numpy-data-buffer
Changeset: r47778:bceb4ab33edd
Date: 2011-10-03 07:21 +0200
http://bitbucket.org/pypy/pypy/changeset/bceb4ab33edd/
Log: fix obvious off-by-ones, assert lens, size of dtype is important for
length of buffer.
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
@@ -9,7 +9,7 @@
self.array = array
def getlength(self):
- return self.array.get_concrete().find_size()
+ return self.array.get_concrete().find_size() *
self.array.find_dtype().num_bytes
def getitem(self, index):
index = self.calc_index(index)
@@ -29,7 +29,7 @@
def setslice(self, index, newstring):
offset_index = self.calc_index(index)
- if offset_index + len(newstring) > self.getlength() - 1:
+ if offset_index + len(newstring) > self.getlength():
raise IndexError("End of slice to set out of bounds (0<=index<%d)"
% self.getlength())
for idx in range(0, len(newstring)):
self.setitem(index + idx, newstring[idx])
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
@@ -12,6 +12,8 @@
raises(IndexError, "buf[5]")
+ assert len(buf) == 5
+
def test_mutable(self):
from _numpy import array
from _numpy import dtype
@@ -39,6 +41,8 @@
assert arbuf[1] == '\5'
assert viewbuf[0] == '\5'
+ assert len(view) == len(ar) - 2 == 3
+
def test_buffer_set(self):
from _numpy import array
from _numpy import dtype
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit