MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / where

Function where

monai/transforms/utils_pytorch_numpy_unification.py:139–156  ·  view source on GitHub ↗

Note that `torch.where` may convert y.dtype to x.dtype.

(condition: NdarrayOrTensor, x=None, y=None)

Source from the content-addressed store, hash-verified

137
138
139def where(condition: NdarrayOrTensor, x=None, y=None) -> NdarrayOrTensor:
140 """
141 Note that `torch.where` may convert y.dtype to x.dtype.
142 """
143 result: NdarrayOrTensor
144 if isinstance(condition, np.ndarray):
145 if x is not None:
146 result = np.where(condition, x, y)
147 else:
148 result = np.where(condition) # type: ignore
149 else:
150 if x is not None:
151 x = torch.as_tensor(x, device=condition.device)
152 y = torch.as_tensor(y, device=condition.device, dtype=x.dtype)
153 result = torch.where(condition, x, y)
154 else:
155 result = torch.where(condition) # type: ignore
156 return result
157
158
159def argwhere(a: NdarrayTensor) -> NdarrayTensor:

Callers 6

__call__Method · 0.90
get_extreme_pointsFunction · 0.90
_get_pointFunction · 0.90
__call__Method · 0.90
__call__Method · 0.85

Calls 1

as_tensorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…