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

fix(mpiarray): crash testing for an Ellipsis when given an ndarray index #200

Merged
merged 1 commit into from
Jun 29, 2022
Merged
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
9 changes: 6 additions & 3 deletions caput/mpiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1927,7 +1927,10 @@ def sanitize_slice(
orig_sl = sl

# Add an Ellipsis at the very end if it isn't present elsewhere
if Ellipsis not in sl:
num_ellipsis = sum([s is Ellipsis for s in sl])
if num_ellipsis > 1:
raise IndexError(f"Found more than one Ellipsis in slice {sl}")
elif num_ellipsis == 0:
sl += (Ellipsis,)

# Convert all np.int types (which are valid arguments) to ints
Expand All @@ -1939,11 +1942,11 @@ def sanitize_slice(

for ii, s in enumerate(sl):

if s == np.newaxis:
if s is np.newaxis:
num_added += 1
elif isinstance(s, int):
num_removed += 1
elif s == Ellipsis:
elif s is Ellipsis:
ell_ind = ii

# Calculate the number of slices to add instead of the ellipsis
Expand Down
7 changes: 7 additions & 0 deletions caput/tests/test_mpiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,13 @@ def test_slice_ellipsis():
assert new_dist_array.global_shape == (4, size, 3, 1)
assert (new_dist_array[:] == rank).all()

bool_sel = np.ones(3, dtype=bool)
bool_sel[2:] = False
new_dist_array = dist_array[..., bool_sel]
assert new_dist_array.shape == (4, 1, 2)
assert new_dist_array.global_shape == (4, size, 2)
assert (new_dist_array == rank).all()


def test_slice_npint64():

Expand Down