[DLMED] fix 1.5.1 cron test
@@ -16,6 +16,7 @@ import torch
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",
@@ -294,8 +295,14 @@ def isfinite(x):
def searchsorted(a: NdarrayOrTensor, v: NdarrayOrTensor, right=False, sorter=None):
- if isinstance(a, np.ndarray):
side = "right" if right else "left"
+ if isinstance(a, np.ndarray):
return np.searchsorted(a, v, side, sorter) # type: ignore
else:
+ 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
