diff options
Diffstat (limited to 'numpy/core/memmap.py')
-rw-r--r-- | numpy/core/memmap.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py index 05bfd68b7..5c8542479 100644 --- a/numpy/core/memmap.py +++ b/numpy/core/memmap.py @@ -226,14 +226,16 @@ class memmap(ndarray): if sys.version_info[:2] >= (2,6): # The offset keyword in mmap.mmap needs Python >= 2.6 - bytes = bytes - offset - mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=offset) - self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm, - offset=0, order=order) + blocks = offset // mmap.ALLOCATIONGRANULARITY + aligned_offset = blocks * mmap.ALLOCATIONGRANULARITY + bytes = bytes - aligned_offset + offset = offset - aligned_offset + mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=aligned_offset) else: mm = mmap.mmap(fid.fileno(), bytes, access=acc) - self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm, - offset=offset, order=order) + + self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm, + offset=offset, order=order) self._mmap = mm return self |