Skip to content

Commit 60a112a

Browse files
committed
Small refactor of the use of nonzero in _resolve_indexing_state
1 parent 76c5c85 commit 60a112a

2 files changed

Lines changed: 2 additions & 7 deletions

File tree

heat/core/dndarray.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,7 @@ def _resolve_indexing_state(
358358
and first_dtype in (ht_bool, ht_uint8, torch.bool, torch.uint8, np.bool_, np.uint8)
359359
):
360360
if isinstance(first, DNDarray):
361-
nz = first.nonzero()
362-
if isinstance(nz, tuple):
363-
nz = nz[0]
364-
if getattr(nz, "ndim", 1) > 1 and nz.shape[-1] == 1:
365-
nz = nz.squeeze(-1)
366-
idx0 = nz
361+
idx0 = first.nonzero(as_tuple=False).flatten()
367362
elif isinstance(first, torch.Tensor):
368363
idx0 = torch.nonzero(first, as_tuple=False).flatten()
369364
else: # np.ndarray

heat/core/indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def nonzero(x: DNDarray, as_tuple: bool = True) -> tuple[DNDarray, ...] | DNDarr
146146
)
147147

148148

149-
DNDarray.nonzero = lambda self: nonzero(self, as_tuple=True)
149+
DNDarray.nonzero = nonzero
150150
DNDarray.nonzero.__doc__ = nonzero.__doc__
151151

152152

0 commit comments

Comments
 (0)