Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3119 Fix cron test for PyTorch 1.5.1 #3121

Merged
merged 7 commits into from
Oct 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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