Skip to content

Commit

Permalink
[DLMED] fix 1.5.1 cron test (#3121)
Browse files Browse the repository at this point in the history
Signed-off-by: Nic Ma <nma@nvidia.com>

Co-authored-by: Wenqi Li <wenqil@nvidia.com>
  • Loading branch information
Nic-Ma and wyli authored Oct 13, 2021
1 parent ce76ec7 commit 9b9516c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions monai/transforms/utils_pytorch_numpy_unification.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from monai.config.type_definitions import NdarrayOrTensor
from monai.utils.misc import is_module_ver_at_least
from monai.utils.type_conversion import convert_to_dst_type

__all__ = [
"moveaxis",
Expand Down Expand Up @@ -294,8 +295,14 @@ def isfinite(x):


def searchsorted(a: NdarrayOrTensor, v: NdarrayOrTensor, right=False, sorter=None):
side = "right" if right else "left"
if isinstance(a, np.ndarray):
side = "right" if right else "left"
return np.searchsorted(a, v, side, sorter) # type: ignore
else:
return torch.searchsorted(a, v, right=right) # type: ignore
if hasattr(torch, "searchsorted"):
return torch.searchsorted(a, v, right=right) # type: ignore
else:
# if using old PyTorch, will convert to numpy array then compute
ret = np.searchsorted(a.cpu().numpy(), v.cpu().numpy(), side, sorter) # type: ignore
ret, *_ = convert_to_dst_type(ret, a)
return ret

0 comments on commit 9b9516c

Please sign in to comment.