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

Function searchsorted

monai/transforms/utils_pytorch_numpy_unification.py:345–361  ·  view source on GitHub ↗

`np.searchsorted` with equivalent implementation for torch. Args: a: numpy array or tensor, containing monotonically increasing sequence on the innermost dimension. v: containing the search values. right: if False, return the first suitable location that is found, i

(a: NdarrayTensor, v: NdarrayOrTensor, right=False, sorter=None, **kwargs)

Source from the content-addressed store, hash-verified

343
344
345def searchsorted(a: NdarrayTensor, v: NdarrayOrTensor, right=False, sorter=None, **kwargs) -> NdarrayTensor:
346 """
347 `np.searchsorted` with equivalent implementation for torch.
348
349 Args:
350 a: numpy array or tensor, containing monotonically increasing sequence on the innermost dimension.
351 v: containing the search values.
352 right: if False, return the first suitable location that is found, if True, return the last such index.
353 sorter: if `a` is numpy array, optional array of integer indices that sort array `a` into ascending order.
354 kwargs: if `a` is PyTorch Tensor, additional args for `torch.searchsorted`, more details:
355 https://pytorch.org/docs/stable/generated/torch.searchsorted.html.
356
357 """
358 side = "right" if right else "left"
359 if isinstance(a, np.ndarray):
360 return np.searchsorted(a, v, side, sorter) # type: ignore
361 return torch.searchsorted(a, v, right=right, **kwargs) # type: ignore
362
363
364def repeat(a: NdarrayOrTensor, repeats: int, axis: int | None = None, **kwargs) -> NdarrayOrTensor:

Callers 1

weighted_patch_samplesFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…