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

towards addressing issue 472 #477

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cunumeric/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,21 @@ def __ge__(self, rhs):

def _convert_key(self, key, first=True):
# Convert any arrays stored in a key to a cuNumeric array
if isinstance(key, slice):
if isinstance(key.start, ndarray):
Copy link
Contributor

@magnatelee magnatelee Jul 28, 2022

Choose a reason for hiding this comment

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

I'd suggest you do the integer conversion unconditionally. An isinstance call isn't particularly cheaper. Plus the code would look cleaner in that way.

start = int(key.start)
else:
start = key.start
if isinstance(key.stop, ndarray):
stop = int(key.stop)
else:
stop = key.stop
if isinstance(key.step, ndarray):
step = int(key.step)
else:
step = key.step
key = slice(start, stop, step)

if (
key is np.newaxis
or key is Ellipsis
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/test_advanced_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,17 @@ def test():
res_num = x_num[indx_num]
assert np.array_equal(res, res_num)

# slicing with the scalar from array
offsets_np = np.ones((1,), dtype=int)
offsets_num = num.array(offsets_np)
offset_np = offsets_np[0]
offset_num = offsets_num[0]
x_np = np.zeros((300,))
x_num = num.zeros((300,))
x_np[: int(offset_np)] = 0
x_num[:offset_num] = 0
assert np.array_equal(x_np, x_num)

# we do less than LEGATE_MAX_DIM becasue the dimension will be increased by
# 1 when passig 2d index array
for ndim in range(2, LEGATE_MAX_DIM):
Expand Down