From 917f32678b515cc0835389785c5d8d6092a73f1b Mon Sep 17 00:00:00 2001 From: David Grote Date: Thu, 31 Oct 2024 17:03:17 -0700 Subject: [PATCH] Fix case when only empty tuple is passed in (#387) 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> --- src/amrex/extensions/MultiFab.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/amrex/extensions/MultiFab.py b/src/amrex/extensions/MultiFab.py index 3f6b4144..11ce9de1 100644 --- a/src/amrex/extensions/MultiFab.py +++ b/src/amrex/extensions/MultiFab.py @@ -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")