Skip to content

Commit

Permalink
Fix slicing_dict() for boolean-mask
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Holl committed Aug 7, 2024
1 parent 387609b commit 871f8c6
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions phiml/math/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,10 @@ def valid_key(key):
else:
raise AssertionError(f"Cannot slice {obj}[{item}]. Use a dict or the special slicing syntax value.dim[slice] instead. See https://tum-pbs.github.io/PhiML/Introduction.html#Slicing")
else:
from ._tensors import Tensor
if isinstance(item, Tensor) and item.dtype.kind == bool: # boolean mask
mask_dim = item.shape.non_batch or item.shape
return {mask_dim.name: item}
if shape(obj).channel_rank == 1:
return {channel(obj).name: item}
elif non_batch(obj).rank == 1:
Expand Down

0 comments on commit 871f8c6

Please sign in to comment.