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

Allow scalar cunumeric ndarrays as array indices #479

Merged
merged 2 commits into from
Jul 29, 2022

Conversation

manopapad
Copy link
Contributor

@manopapad manopapad commented Jul 28, 2022

Another attempt at solving #472, using the operator.index(.) method instead of int(), as the python documentation suggests, and handling some additional cases (also support indexing numpy ndarrays and python lists).

def test_scalar_ndarray_as_index(arr):
offsets = num.arange(5) # [0, 1, 2, 3, 4]
offset = offsets[3] # 3
# assert arr[offset] == 1 # TODO: doesn't work when arr is a num.ndarray
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails with:

Assertion failed: (false), function double_dispatch, file /Users/mpapadakis/legate.core/install/include/core/utilities/dispatch.h, line 239.

I think this is because zip_indices doesn't handle 0d arrays. @ipdemes we may want to cast 0d arrays to 1d in zip_indices, as is done in other places.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fix for this seems to involve more than just casting of array to 1d in ZIP task. I would probably need to do something similar for the Copy task as well since I will have to call copy() on the output of ZIP later during get_item operation. I will work on the fix tomorrow.

@bryevdv
Copy link
Contributor

bryevdv commented Jul 29, 2022

After brushing up on PEP 357, agree that .index is the proper approach. LGTM

@manopapad manopapad merged commit 731901b into nv-legate:branch-22.07 Jul 29, 2022
sbak5 pushed a commit to sbak5/cunumeric that referenced this pull request Aug 17, 2022
* Allow scalar cunumeric ndarrays as array indices

* Remove some duplicate test lines
@manopapad manopapad deleted the ndarray-as-index branch July 19, 2023 17:30
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

Successfully merging this pull request may close these issues.

3 participants