Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexing with arrays only seems to work with 1D arrays #584

Open
jamesavery opened this issue Jan 17, 2019 · 3 comments
Open

Indexing with arrays only seems to work with 1D arrays #584

jamesavery opened this issue Jan 17, 2019 · 3 comments
Assignees

Comments

@jamesavery
Copy link
Contributor

jamesavery commented Jan 17, 2019

Small example:

a  = np.arange(10);
ix = a[::-1];
print(a[ix])    # works fine
b  = a[:,None]*a[None,:];

print(b[:,ix])  # Explodes in array_create.py, line 147
print(b[ix,:])  # Explodes in array_create.py, line 147
print(b[ix])    # Handed off to NumPy
print(b[:][ix]) # Handed off to NumPy
print(b.flatten()[b]) # 2D-index on flat array works fine
@jamesavery jamesavery changed the title Indexing with arrays only seems to work with ndim=1 arrays Indexing with arrays only seems to work with 1D arrays Jan 17, 2019
@jamesavery
Copy link
Contributor Author

@madsbk I've written a user kernel that implements numpy.take for any axis (and any ndim for the index matrix too). How do I link it up with the actual indexing, so I can get A[:,ix,:], etc., to work in Bohrium?

@dionhaefner
Copy link
Collaborator

print(b.flatten()[b]) # 2D-index on flat array works fine

If that's the case, the solution could be in pure Python; just use the strides to convert the indices into absolute offsets, then index into the flat array. But I'm afraid any solution will have to be implemented inside Bohrium, as it's not possible to monkey-patch __getitem__ of bh.ndarray since it's a C extension type.

@jamesavery
Copy link
Contributor Author

Same solution as for #586. New GATHER instruction that allows indexing over any axis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants