Commits

Timo Paulssen committed bceb4ab

fix obvious off-by-ones, assert lens, size of dtype is important for length of buffer.

Comments (0)

Files changed (2)

pypy/module/_numpy/interp_buffer.py

         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)
 
     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])

pypy/module/_numpy/test/test_buffer.py

 
         raises(IndexError, "buf[5]")
 
+        assert len(buf) == 5
+
     def test_mutable(self):
         from _numpy import array
         from _numpy import dtype
         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