Skip to content

Commit

Permalink
Fix case when only empty tuple is passed in (#387)
Browse files Browse the repository at this point in the history
One more fix for the global indexing of MultiFabs. I hadn't taken care
of the case when only the empty tuple is passed in (for example for 1D).
This PR fixes this case.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
dpgrote and pre-commit-ci[bot] authored Nov 1, 2024
1 parent 1aa1db3 commit 917f326
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/amrex/extensions/MultiFab.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,19 @@ def _process_index(self, index):
# If only one slice or integer passed in, it was not wrapped in a tuple
index = [index]
elif isinstance(index, tuple):
index = list(index)
for i in range(len(index)):
if index[i] == Ellipsis:
index = (
index[:i] + (dims + 2 - len(index)) * [slice(None)] + index[i + 1 :]
)
break
if len(index) == 0:
# The empty tuple specifies all valid and ghost cells
index = [index]
else:
index = list(index)
for i in range(len(index)):
if index[i] == Ellipsis:
index = (
index[:i]
+ (dims + 2 - len(index)) * [slice(None)]
+ index[i + 1 :]
)
break
else:
raise Exception("MultiFab.__getitem__: unexpected index type")

Expand Down

0 comments on commit 917f326

Please sign in to comment.