Commit fcbb26e6 authored by Kirill Smelkov's avatar Kirill Smelkov

bigarray: Translate OverflowError when computing slice indices to MemoryError

OverflowError when computing slice indices practically means we'll
cannot allocate so much address space at next step:

    In [1]: s = slice(None)

    In [2]: s.indices(1<<62)
    Out[2]: (0, 4611686018427387904, 1)

    In [3]: s.indices(1<<63)
    ---------------------------------------------------------------------------
    OverflowError                             Traceback (most recent call last)
    <ipython-input-4-5aa549641bc6> in <module>()
    ----> 1 s.indices(1<<63)

    OverflowError: cannot fit 'long' into an index-sized integer

So translate this OverflowError into MemoryError (preserving message
details), because we'll need such "no so much address space" cases to
show up as MemoryError in a sooner patch.
parent 2cf9073f
...@@ -291,7 +291,13 @@ class BigArray(object): ...@@ -291,7 +291,13 @@ class BigArray(object):
shape0 = self._shape[0] shape0 = self._shape[0]
# major idx start/stop/stride # major idx start/stop/stride
try:
idx0_start, idx0_stop, idx0_stride = idx0.indices(shape0) idx0_start, idx0_stop, idx0_stride = idx0.indices(shape0)
except OverflowError as e:
# overflow error here means slice indices do not fit into std long,
# which also practically means we cannot allocate such amount of
# address space.
raise MemoryError(e)
#print('idx0:\t', idx0, '-> [%s:%s:%s]' % (idx0_start, idx0_stop, idx0_stride)) #print('idx0:\t', idx0, '-> [%s:%s:%s]' % (idx0_start, idx0_stop, idx0_stride))
#print('strid0:\t', stride0) #, self._stridev #print('strid0:\t', stride0) #, self._stridev
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment