Commit 4680c0cd authored by Kirill Smelkov's avatar Kirill Smelkov

bigarray: Be explicit about not-supporting advanced indexing

In NumPy speak advanced indexing is picking up arbitrarily requested
elemtnts, e.g.

    a = arange(10)
    a[[0,3,2]]  -> array([0, 3, 2])

The way this indexing schem works is - it creates a new array with
len = len(key), and picks up requested elements sequentially into new

So it is very not the same as creating _view_ to original array data by
using basic indexing [1]

BigArray does not support advanced indexing, because its main job is to
organize an ndarray _view_ backed up by BigFile data and give that view
to clients, and then it is up to clients how to use that view with full
numpy api available with it.

So be explicit, and reject advanced indexing in __getitem__ right at the

parent 84f0bd25
......@@ -197,6 +197,14 @@ class BigArray(object):
# NOTE basic indexing means idx = tuple(slice | int) + sugar(newaxis, ellipsis)
#print('\n__getitem__', idx)
# BigArray does not support advanced indexes:
# In numpy they create _copy_, picking up elements, e.g.
# a = arange(10)
# a[ 0,3,2 ] -> IndexError
# a[[0,3,2]] -> [0,3,2]
if isinstance(idx, list):
raise TypeError('BigArray does not support advanced indexing ; idx = %r' % (idx,))
# handle 1d slices uniformly with Nd
if not isinstance(idx, tuple):
idx = (idx,)
......@@ -105,6 +105,13 @@ def test_bigarray_indexing_1d():
AA = DoubleGet(A, A_)
# BigArray does not support advanced indexes
# (in numpy they create _copy_ picking up elements)
A_[0:5] = range(0,10,2)
assert array_equal(A_[[0,1,2,3,4]], [0,2,4,6,8])
raises (TypeError, 'A[[0,1,2,3,4]]')
# "empty" slices
assert A[10:5:1] .size == 0
assert A[5:10:-1] .size == 0
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment